From patchwork Mon Dec 2 16:18:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 16534 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 1427144A8DE for ; Mon, 2 Dec 2019 18:19:00 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E05CF68AF1A; Mon, 2 Dec 2019 18:18:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 85F0568ACB2 for ; Mon, 2 Dec 2019 18:18:58 +0200 (EET) Received: by mail-qt1-f194.google.com with SMTP id d5so292994qto.0 for ; Mon, 02 Dec 2019 08:18:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=dHC8qMUq455zTUojNbTuXCVgdys3NquNUeHBpagRiQM=; b=DSoa+zSWaXQO91DgUyg0lhHyZhoNwtD3iDFujysx3CaGxRf42oj01WAGepZ6WSKNUz oYg+KJpWQyciTWsr5V47UatXh0DqA891GPq5OdNXp47uYKo/8Jl6tmzei6ZBnILoKHLD uGDh3rHzcQMcU/vCvRIVXJeEAyc6D2RFZv8Uo6WjSkZvuW5AGRK4qku4ZxIvZ7xtJUkp Yy1w6X4r/nMIGxa+jAy2T34ME+k3DFZgMc7urB4aEb0Km2+GEXcg34jSET/IdOX9eJdM A6dER2DY/JGnKQ6CnYlXUk1yC2+apJ9MiJlzeRv62NNLpfGdNQRRPaoWoB92aWraLLXz RyJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=dHC8qMUq455zTUojNbTuXCVgdys3NquNUeHBpagRiQM=; b=rHxptF2aAU7t6JMlPk8Eq2DWbOyq4fZ5ZaF+z6bq/aLCP1WvrUgorwtByTzytnyo4M ESbiXtc082dLgP/hbgFgQ2ZoiodiDVnB1W+CcT5pdnC0sKuJe1vKoXafmgn3UVD2HhQ0 djCYn7AZYLUhC/w+FpYBdgNZXaQDLZPw0q6bb7ArturfCeOM/1zQECwrqhAUNWUcUPpc 2wJ0/Ndwaj+0K5QxlKH89jUS2LNEh/M0Ac9IOUNI6V/d3eyd2sQiCCYhwCpAdOkaKdd1 nZSWstz3blNpchAFv7T6oJYXKWuTT/52puwrcWPfxUAZoJVONv0UABkHWu1I1T4sS6A+ neLQ== X-Gm-Message-State: APjAAAWzdCtlSm71iaIP7pZrToEMFMZgNeQ6xvw51vNV+zemCfIzH1Ro bbZNq1HpmyQHyfnVbNwioXCVvotJ X-Google-Smtp-Source: APXvYqw/rKhzdNX0758auLsBw7jUDJ8M6l1NKV4HxqzUzASuvNo4gSYCeXD0lbxaQcgqhAW7s5Tg5Q== X-Received: by 2002:ac8:4a93:: with SMTP id l19mr34343qtq.121.1575303536929; Mon, 02 Dec 2019 08:18:56 -0800 (PST) Received: from localhost.localdomain ([181.23.79.171]) by smtp.gmail.com with ESMTPSA id u67sm14592561qkf.115.2019.12.02.08.18.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 08:18:56 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Dec 2019 13:18:36 -0300 Message-Id: <20191202161838.1746-1-jamrial@gmail.com> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avformat/movenc: write the major brand also as the first compatible brand X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: James Almer --- This is meant to be squashed with patch 2/3, otherwise it will write duplicate compatible brands, and a lot of tests will have to be updated twice. I'm sending it like this to make reviewing/reading easier. libavformat/movenc.c | 61 +++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index dd144ae20a..afce95042e 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -4740,27 +4740,11 @@ static int mov_write_mdat_tag(AVIOContext *pb, MOVMuxContext *mov) return 0; } -/* TODO: This needs to be more general */ -static int mov_write_ftyp_tag(AVIOContext *pb, AVFormatContext *s) +static void mov_write_ftyp_tag_internal(AVIOContext *pb, AVFormatContext *s, + int has_h264, int has_video, int write_minor) { MOVMuxContext *mov = s->priv_data; - int64_t pos = avio_tell(pb); - int has_h264 = 0, has_video = 0; int minor = 0x200; - int i; - - for (i = 0; i < s->nb_streams; i++) { - AVStream *st = s->streams[i]; - if (is_cover_image(st)) - continue; - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) - has_video = 1; - if (st->codecpar->codec_id == AV_CODEC_ID_H264) - has_h264 = 1; - } - - avio_wb32(pb, 0); /* size */ - ffio_wfourcc(pb, "ftyp"); if (mov->major_brand && strlen(mov->major_brand) >= 4) ffio_wfourcc(pb, mov->major_brand); @@ -4787,11 +4771,36 @@ static int mov_write_ftyp_tag(AVIOContext *pb, AVFormatContext *s) else ffio_wfourcc(pb, "qt "); - avio_wb32(pb, minor); + if (write_minor) + avio_wb32(pb, minor); +} - if (mov->mode == MODE_MOV) - ffio_wfourcc(pb, "qt "); - else if (mov->mode == MODE_ISM) { +static int mov_write_ftyp_tag(AVIOContext *pb, AVFormatContext *s) +{ + MOVMuxContext *mov = s->priv_data; + int64_t pos = avio_tell(pb); + int has_h264 = 0, has_video = 0; + int i; + + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + if (is_cover_image(st)) + continue; + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) + has_video = 1; + if (st->codecpar->codec_id == AV_CODEC_ID_H264) + has_h264 = 1; + } + + avio_wb32(pb, 0); /* size */ + ffio_wfourcc(pb, "ftyp"); + + // Write major brand + mov_write_ftyp_tag_internal(pb, s, has_h264, has_video, 1); + // Write the major brand as the first compatible brand as well + mov_write_ftyp_tag_internal(pb, s, has_h264, has_video, 0); + + if (mov->mode == MODE_ISM) { ffio_wfourcc(pb, "piff"); } else if (!(mov->flags & FF_MOV_FLAG_DEFAULT_BASE_MOOF)) { ffio_wfourcc(pb, "isom"); @@ -4805,13 +4814,7 @@ static int mov_write_ftyp_tag(AVIOContext *pb, AVFormatContext *s) if (mov->flags & FF_MOV_FLAG_FRAGMENT && mov->mode != MODE_ISM) ffio_wfourcc(pb, "iso6"); - if (mov->mode == MODE_3GP) - ffio_wfourcc(pb, has_h264 ? "3gp6":"3gp4"); - else if (mov->mode & MODE_3G2) - ffio_wfourcc(pb, has_h264 ? "3g2b":"3g2a"); - else if (mov->mode == MODE_PSP) - ffio_wfourcc(pb, "MSNV"); - else if (mov->mode == MODE_MP4) + if (mov->mode == MODE_MP4) ffio_wfourcc(pb, "mp41"); if (mov->flags & FF_MOV_FLAG_DASH && mov->flags & FF_MOV_FLAG_GLOBAL_SIDX)