From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <ffmpeg-devel-bounces@ffmpeg.org> Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 039D04E952 for <ffmpegdev@gitmailbox.com>; Thu, 8 May 2025 22:14:31 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 15E7868C347; Fri, 9 May 2025 01:14:26 +0300 (EEST) Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 356CE68C30B for <ffmpeg-devel@ffmpeg.org>; Fri, 9 May 2025 01:14:19 +0300 (EEST) Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-ad1b94382b8so119309566b.0 for <ffmpeg-devel@ffmpeg.org>; Thu, 08 May 2025 15:14:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unified-streaming.com; s=google; t=1746742458; x=1747347258; darn=ffmpeg.org; h=message-id:in-reply-to:to:references:date:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=elf1IQgvqWXqLG6qnadnT13gKbST0RAQPrCLBDjWKxo=; b=JBhY4eOn+zPmEKYZVDxlAvloWC6b8L29Bnm69TBCJ0pDPiIHrPcL2lotdyLp5Kn7Ny C/34f6Q3DObKPwV6tQLVpPkf0LhnTuAyV2XEDWj49XmsrcDmS5Ojv9K95UDk59QIb+O8 rn0siEcz5tjR/2JeYPoGH6r4SjTNHF1BJ0Q6xiVu/LY0cFX8l0TvGGlPNeyGdRwAp3YL FOrA9oUJQdO3UxUvFtwHLvhZZtb3jFW7MYX2OlBVpG1DEsiRdpH8+PBxeYRznneIB+KD h0P8Zd28ZWrIoEOh/RBaEZAKK1TDqU8owRKtTLzgZE4eQKjKdEhYs95gvbIobw4JyDpy ZDKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746742458; x=1747347258; h=message-id:in-reply-to:to:references:date:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=elf1IQgvqWXqLG6qnadnT13gKbST0RAQPrCLBDjWKxo=; b=KsPo/WSyxMKCA+Na4b9WSwaQ8nAjGTBUZOyAXOnGcRgbtxX0r7Vs9bo2iV4P3nSjxn Oiui27brBZnPlovnS66N+at2FLj9bhF5BIekIv3CJqveBHdGGua0JOirYTaroo1gbSu8 mKQqzCqzDCUjxUU7curVW13CoWF5adFg4xHYELeJFCg7kQDc2CBsv4pRYw8w1V5JVypo x/hPRgsaoocoqSdpMMfAUHjVO7mT2sQ3bG0WExheem3v1ISYdoh9u6D7F21Hx51Jxp/C qcWIY1SYdfg1ov9J8Nbz65Qm76qEHtgL3YDujGWkv6c7ig9dbBILMNhUBfPTaNN3x2Kb Ywbw== X-Gm-Message-State: AOJu0YxLv1LD6ScFRnLyxz566hVPTtvKRfiTufhGiJSf+OyuNe1JYGAV mBCmPPs94lJRv0E9j0FFS7uAI5ZOcgZsGZCvSAOWcr7WHpnOXzO/c6j9keaET0wPaSsFWcoksK/ oX2q+TI7ra6UQh9RL9qyjV+xYkZXqiHgPVr3skqZIb+oKbQypdiUt/a266nqyraUtHdCZZeTz4R i0itGhKwHdfsJaHwT9eHwyEU1MkgcaMZ6Uc4C9JwoSAnO39rPCHrg= X-Gm-Gg: ASbGncurPqks0MnU1Vm9EumRqU5vuT37UjiDH12PVcxPCXFf5Z5JOVtzKq2aEF6WEEM +U37/iPyXKkqosUgmC4SWyHPSrlfqQ43fxU7U/dnC81SJ9CEs5Q4puwHiI8WFCLisbEmoawnEzm cWEWKJTsWK6nS+Vn6HGPoCM7yCczrd5f055oVf8l+lzmsKEoohYCOvXJ6maYNKQ/lhImHIcQD/a NvfPb/+itAkrJrnBbyPR9Mfd8SuYV6B6cYQaolk1yYVe+9oJxyH7Ai7l4GFLQRxqM0nkfyypdYz wRJt3FEUZPpUvJeNaUQN7ryM0vIZuuNUMNd5rwpZyDhNpHhbGelc58QQJK7RbvEUQP3GCkBRTcn uG1C3oU5h X-Google-Smtp-Source: AGHT+IEJ0wzYouU/RcvNdqHMoB+i2cdbTh62yckLtq6DB09GaCw+HtISRUpMDh3EastfuwfNcQo3ew== X-Received: by 2002:a17:907:944e:b0:ace:3a3d:7e35 with SMTP id a640c23a62f3a-ad21928edfcmr115130466b.53.1746742458372; Thu, 08 May 2025 15:14:18 -0700 (PDT) Received: from smtpclient.apple (tensor.andric.com. [87.251.56.140]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad2192c9191sm51010466b.19.2025.05.08.15.14.17 for <ffmpeg-devel@ffmpeg.org> (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 May 2025 15:14:17 -0700 (PDT) From: Dimitry Andric <dimitry@unified-streaming.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6.1.10\)) Date: Fri, 9 May 2025 00:14:17 +0200 References: <20250403200239.226898-1-dimitry@unified-streaming.com> <9ADA5613-0335-455A-B75C-8ADD42D860E6@unified-streaming.com> <039BFB64-4F2B-4644-BA12-AE7ECE262393@unified-streaming.com> <4ECBE413-6C97-473E-A61F-75DCD6281196@unified-streaming.com> To: ffmpeg-devel@ffmpeg.org In-Reply-To: <4ECBE413-6C97-473E-A61F-75DCD6281196@unified-streaming.com> Message-Id: <3198FB5F-EF3B-41B1-BB33-E3AC82A4161A@unified-streaming.com> X-Mailer: Apple Mail (2.3731.700.6.1.10) Subject: Re: [FFmpeg-devel] [PATCH] avformat/mov: Fix decoding fragmented MP4 with multiple sample entries and empty stsc X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org> List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe> List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel> List-Post: <mailto:ffmpeg-devel@ffmpeg.org> List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help> List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe> Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org> Archived-At: <https://master.gitmailbox.com/ffmpegdev/3198FB5F-EF3B-41B1-BB33-E3AC82A4161A@unified-streaming.com/> List-Archive: <https://master.gitmailbox.com/ffmpegdev/> List-Post: <mailto:ffmpegdev@gitmailbox.com> On 28 Apr 2025, at 13:00, Dimitry Andric <dimitry@unified-streaming.com> wrote: > > On 19 Apr 2025, at 16:27, Dimitry Andric <dimitry@unified-streaming.com> wrote: >> >> On 10 Apr 2025, at 11:03, Dimitry Andric <dimitry@unified-streaming.com> wrote: >>> >>> On 3 Apr 2025, at 22:02, Dimitry Andric <dimitry@unified-streaming.com> wrote: >>>> >>>> When decoding fragmented MP4 files that have an empty stsc box, and >>>> instead contain sample description indexes in their tfhd boxes, the mov >>>> demuxer does not notify the decoder whenever the current sample >>>> description index changes. If the SPS or PPS changed sufficiently, this >>>> can lead to unexpected decoding errors. >>>> >>>> To fix this, in mov_finalize_packet(), when stsc_data is not available, >>>> use get_frag_stream_info_from_pkt() to get at the current fragment >>>> stream info, and retrieve the current sample description index from >>>> there. Then use that index in a similar manner as the stsc case. >>>> >>>> Signed-off-by: Dimitry Andric <dimitry@unified-streaming.com> >>>> --- >>>> libavformat/mov.c | 50 ++++++++++++++++++++++++++++------------------- >>>> 1 file changed, 30 insertions(+), 20 deletions(-) >>>> >>>> diff --git a/libavformat/mov.c b/libavformat/mov.c >>>> index 452690090c..ead89192f4 100644 >>>> --- a/libavformat/mov.c >>>> +++ b/libavformat/mov.c >>>> @@ -10756,25 +10756,29 @@ static int mov_switch_root(AVFormatContext *s, int64_t target, int index) >>>> return 1; >>>> } >>>> >>>> -static int mov_change_extradata(AVStream *st, AVPacket *pkt) >>>> +static int mov_change_extradata(AVStream *st, AVPacket *pkt, int stsd_id) >>>> { >>>> MOVStreamContext *sc = st->priv_data; >>>> uint8_t *side, *extradata; >>>> int extradata_size; >>>> >>>> - /* Save the current index. */ >>>> - sc->last_stsd_index = sc->stsc_data[sc->stsc_index].id - 1; >>>> + if (stsd_id > 0 && >>>> + stsd_id - 1 < sc->stsd_count && >>>> + stsd_id - 1 != sc->last_stsd_index) { >>>> + /* Save the current index. */ >>>> + sc->last_stsd_index = stsd_id - 1; >>>> >>>> - /* Notify the decoder that extradata changed. */ >>>> - extradata_size = sc->extradata_size[sc->last_stsd_index]; >>>> - extradata = sc->extradata[sc->last_stsd_index]; >>>> - if (st->discard != AVDISCARD_ALL && extradata_size > 0 && extradata) { >>>> - side = av_packet_new_side_data(pkt, >>>> - AV_PKT_DATA_NEW_EXTRADATA, >>>> - extradata_size); >>>> - if (!side) >>>> - return AVERROR(ENOMEM); >>>> - memcpy(side, extradata, extradata_size); >>>> + /* Notify the decoder that extradata changed. */ >>>> + extradata_size = sc->extradata_size[sc->last_stsd_index]; >>>> + extradata = sc->extradata[sc->last_stsd_index]; >>>> + if (st->discard != AVDISCARD_ALL && extradata_size > 0 && extradata) { >>>> + side = av_packet_new_side_data(pkt, >>>> + AV_PKT_DATA_NEW_EXTRADATA, >>>> + extradata_size); >>>> + if (!side) >>>> + return AVERROR(ENOMEM); >>>> + memcpy(side, extradata, extradata_size); >>>> + } >>>> } >>>> >>>> return 0; >>>> @@ -10893,13 +10897,10 @@ static int mov_finalize_packet(AVFormatContext *s, AVStream *st, AVIndexEntry *s >>>> >>>> /* Multiple stsd handling. */ >>>> if (sc->stsc_data) { >>>> - if (sc->stsc_data[sc->stsc_index].id > 0 && >>>> - sc->stsc_data[sc->stsc_index].id - 1 < sc->stsd_count && >>>> - sc->stsc_data[sc->stsc_index].id - 1 != sc->last_stsd_index) { >>>> - int ret = mov_change_extradata(st, pkt); >>>> - if (ret < 0) >>>> - return ret; >>>> - } >>>> + int stsd_id = sc->stsc_data[sc->stsc_index].id; >>>> + int ret = mov_change_extradata(st, pkt, stsd_id); >>>> + if (ret < 0) >>>> + return ret; >>>> >>>> /* Update the stsc index for the next sample */ >>>> sc->stsc_sample++; >>>> @@ -10908,6 +10909,15 @@ static int mov_finalize_packet(AVFormatContext *s, AVStream *st, AVIndexEntry *s >>>> sc->stsc_index++; >>>> sc->stsc_sample = 0; >>>> } >>>> + } else { >>>> + MOVContext *mov = s->priv_data; >>>> + MOVFragmentStreamInfo *frag_stream_info = get_frag_stream_info_from_pkt(&mov->frag_index, pkt, sc->id); >>>> + if (frag_stream_info) { >>>> + int stsd_id = frag_stream_info->stsd_id; >>>> + int ret = mov_change_extradata(st, pkt, stsd_id); >>>> + if (ret < 0) >>>> + return ret; >>>> + } >>>> } >>>> >>>> return 0; >>>> -- >>>> 2.43.0 >>>> >>> >>> Any comments on this patch? >> >> Ping :) > > Is there any particular group of persons that "own" the mov muxer? Another ping. -Dimitry _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".