From patchwork Thu Aug 1 15:10:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 50861 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:12d6:0:b0:489:2eb3:e4c4 with SMTP id 205csp1232305vqs; Thu, 1 Aug 2024 08:26:58 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUIzpbj1JdJgjXqnEVFsxTblMwVwXVsPLYK/RXR7vFE7qhbMCP5Hf/cfgvmu4bhJ1GyAxMW5s6bVx/iVSNSWCLF31vpoHF/a2hEmA== X-Google-Smtp-Source: AGHT+IGTfHCtptOg6lIXE2PX+7WvlfHiT9RHO47vxX5FrL36P+oCy590zgc+/xQa2Sg6ccsnPOp+ X-Received: by 2002:a17:907:d28:b0:a7a:c083:8579 with SMTP id a640c23a62f3a-a7dc509fd42mr45996066b.62.1722526017866; Thu, 01 Aug 2024 08:26:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722526017; cv=none; d=google.com; s=arc-20160816; b=OF3rPpDW7BfC7Uhf/2sYLXPWmhRzWUw0kCzuqhbSUmzBd5wm4SWRsWiy0M6uaoTDBw r7ysMLRiZmEHKS/GmpR50HAv3ElmQU9NhUfK2PTVDdULifgC2cueC+Q55bqNCDSiZ+14 WMa/gQCjyawhT/CMVn6pDEBCnHuCQ+yhJMtqpq3dFIHVXfiuL9bHH3vjb9V3JZxmkW4d LSP7g9/nX4kqs9F316fPiq+vpCfCbB5IDiwe0n8OHhMyIhdMZvVPj1atOdIXeHgWWjl+ zrfgehooppj31PD73cSc8IdMPRpEVKOY55hynIL9SbP0iTszkT772Z9AOZirhTQG3w/b hMpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=7FvUWoUH5cqzADKZwlIBHwBjv5g0tzgNS+tDlqyAVFw=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=VRrKXmDxh85/NVmvaWrFgrAX/Ib8ftDydwIffWJTIio3Z7IKNCYPSXEjjragZc+FWJ xMSMeZsQiNdQlMbFputNeqIJ71Fah+Vwo3KPb+PSNaEgCgHlwTRpM0lt/ehkcNzJhHDx 0tgn3gLCQjHQhN+mCl2ElC0cOw9USIpHOCrcvO5qn7FezAoX63wGMh07ALoRkmfKmS0T V/PrH4Bru44U4AGJRDn5yMCGKYUv9LxEIUyJLP0JGcFAIVW+yhAIIkNAWNrkYMZx037I saQw6a2bUEJTpWSBeqr8Dkh6c43z9KQNTwLewgiL6EuwPwzVSr3VB8DDh31/zTCqmEPt 7CeQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=hlx5Ne5G; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a7aca7b426dsi1066525266b.198.2024.08.01.08.26.57; Thu, 01 Aug 2024 08:26:57 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=hlx5Ne5G; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1F44368D477; Thu, 1 Aug 2024 18:10:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3302068D477 for ; Thu, 1 Aug 2024 18:09:58 +0300 (EEST) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-70eec5f2401so4396618b3a.3 for ; Thu, 01 Aug 2024 08:09:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722524996; x=1723129796; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=9NPbz03QGsEEwmQUpRjbVD/yKXhvZhw/XPxa3ElfvPY=; b=hlx5Ne5GUZ64p7vo3V6lfxXRh/HmreRcrJv31cuCU6ffdcPc9htYWqpOXYXhn6wZ0p XUKhc0W6UwwSLVQ9yACFF3TXC5IdhG5yfN+9hPdtsAC2aI8u+vU/dBHTdriCiGUy3wps /5cOKrsnESUixkdI/heuZS8CfDLaKsG1syW+Xb79vgGozwfmuuNUjNbSalIPbCkBNrRY jF+o5iEVCt247LqHaRs3wryjpU+DUgDZN6kbLJTpQ3tNqMUsfZBp9ZQfm/RBO7bZKN4g 9HfD6n92cK2TpWsKi+wXWRemkjAe8R5LTN8IXjwVObhVMVxxJfccTRyj+HYpWYByYbUs c2Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524996; x=1723129796; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9NPbz03QGsEEwmQUpRjbVD/yKXhvZhw/XPxa3ElfvPY=; b=pHem7pkmHUmWa7hizmpvQ8zDFKM7Jrd/pHcLO8trrWwC6LK+HdJsbt7cuUjNhdD2IZ 5Ls0EQpUsfnvrZaXlSWDfMURzH1t1mJS6kzubkkev0YDWS1Vpl6QQGp929qc8JGx1g7p PsHpskApBM627uY7Jisj1JHWrWrIc2jQD4BIIOYNI/G1DBMEVgAkXJ4B7bhQR1+lszJP 1bvvR1toNdhOEA29Q3I9FQTZ1MxPnqAM66w8SZe/fVA0KbbUn2z4dlsaWiJswcmyhJSq 71oloWqz56bQVOdEzB4sTA3OG1MlildZ1+mBHs5K4/DTFHLn4DtiPASyssX1055Jc1Fy qGwA== X-Gm-Message-State: AOJu0YxveRtJ6rnNTMmRNZ4l+E9RgFvXtdak7hqtE1NZZsdPsuER42eu 3SHlPEK6p10RJRIUcv/+vpN8OV+RQfLY5XpQDFwMlVMFiiJGkJBaDtoKdQ== X-Received: by 2002:a05:6a20:2586:b0:1c4:c3a1:f479 with SMTP id adf61e73a8af0-1c699680670mr697717637.39.1722524995931; Thu, 01 Aug 2024 08:09:55 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7a9f817ae28sm10501854a12.25.2024.08.01.08.09.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:09:55 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Aug 2024 12:10:31 -0300 Message-ID: <20240801151032.4369-1-jamrial@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/mov: fix track handling when mixing IAMF and video tracks X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: j21Z8s6Oa1oa Fixes crashes when muxing the two together. Signed-off-by: James Almer --- libavformat/movenc.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index ae49582a1a..8e4a037e46 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -7510,7 +7510,9 @@ static int mov_create_dvd_sub_decoder_specific_info(MOVTrack *track, static int mov_init_iamf_track(AVFormatContext *s) { MOVMuxContext *mov = s->priv_data; - MOVTrack *track = &mov->tracks[0]; // IAMF if present is always the first track + MOVTrack *track; + IAMFContext *iamf; + int first_iamf_idx = INT_MAX, last_iamf_idx = 0; int nb_audio_elements = 0, nb_mix_presentations = 0; int ret; @@ -7532,24 +7534,24 @@ static int mov_init_iamf_track(AVFormatContext *s) return AVERROR(EINVAL); } - track->iamf = av_mallocz(sizeof(*track->iamf)); - if (!track->iamf) + iamf = av_mallocz(sizeof(*iamf)); + if (!iamf) return AVERROR(ENOMEM); + for (int i = 0; i < s->nb_stream_groups; i++) { const AVStreamGroup *stg = s->stream_groups[i]; switch(stg->type) { case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: for (int j = 0; j < stg->nb_streams; j++) { - track->first_iamf_idx = FFMIN(stg->streams[j]->index, track->first_iamf_idx); - track->last_iamf_idx = FFMAX(stg->streams[j]->index, track->last_iamf_idx); - stg->streams[j]->priv_data = track; + first_iamf_idx = FFMIN(stg->streams[j]->index, first_iamf_idx); + last_iamf_idx = FFMAX(stg->streams[j]->index, last_iamf_idx); } - ret = ff_iamf_add_audio_element(track->iamf, stg, s); + ret = ff_iamf_add_audio_element(iamf, stg, s); break; case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: - ret = ff_iamf_add_mix_presentation(track->iamf, stg, s); + ret = ff_iamf_add_mix_presentation(iamf, stg, s); break; default: av_assert0(0); @@ -7558,8 +7560,20 @@ static int mov_init_iamf_track(AVFormatContext *s) return ret; } + track = &mov->tracks[first_iamf_idx]; + track->iamf = iamf; + track->first_iamf_idx = first_iamf_idx; + track->last_iamf_idx = last_iamf_idx; track->tag = MKTAG('i','a','m','f'); + for (int i = 0; i < s->nb_stream_groups; i++) { + AVStreamGroup *stg = s->stream_groups[i]; + if (stg->type != AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT) + continue; + for (int j = 0; j < stg->nb_streams; j++) + stg->streams[j]->priv_data = track; + } + ret = avio_open_dyn_buf(&track->iamf_buf); if (ret < 0) return ret; @@ -7571,6 +7585,7 @@ static int mov_init_iamf_track(AVFormatContext *s) static int mov_init(AVFormatContext *s) { MOVMuxContext *mov = s->priv_data; + int has_iamf = 0; int i, ret; mov->fc = s; @@ -7725,6 +7740,7 @@ static int mov_init(AVFormatContext *s) } st->priv_data = st; } + has_iamf = 1; if (!mov->nb_tracks) // We support one track for the entire IAMF structure mov->nb_tracks++; @@ -7830,8 +7846,11 @@ static int mov_init(AVFormatContext *s) for (int j = 0, i = 0; j < s->nb_streams; j++) { AVStream *st = s->streams[j]; - if (st != st->priv_data) + if (st != st->priv_data) { + if (has_iamf) + i += has_iamf--; continue; + } st->priv_data = &mov->tracks[i++]; }