Some MOV files contain an empty track whose STSC table has a placeholder entry even though STCO has no chunks. mov_read_trak() already tolerates this when sc->stts_count is zero.
sc->stts_count is the number of STTS entries, not the number of samples. A zero-count STTS entry therefore makes an empty track fail the STSC/STCO sanity check. Use the STSZ sample count and the total sample count from STTS instead. Keep rejecting the track when either table describes samples. Add a FATE test for a MOV with a valid video track and an empty AAC track containing placeholder STSC and zero-count STTS entries. Signed-off-by: Swami Kevala <[email protected]> --- The issue was reproduced with five silent DJI drone videos. Their video tracks are intact, but each empty AAC track has an STSC entry whose first chunk is 1 while STCO has no chunks. At least one zero-count STTS entry makes the existing empty-track exception miss the case. Synthetic FATE sample (install as mov/empty-audio-stsc.mov): https://streams.videolan.org/ffmpeg/incoming/empty-audio-stsc.mov Sample size: 12,949 bytes SHA-256: 80f5dff362feb48b5f95272c36dfcee2fad540026821c678d015d99e2b329cb4 Tested on master 9fc8c785e2747c87121ec28f8f10ceab0562384b: - make -j6 fate - fate-mov-empty-audio-stsc - Valgrind 3.22 Memcheck: zero errors and zero bytes in use at exit - tools/patcheck (only Makefile false positives and the optional changelog reminder) - affected 3840x2160 DJI input: 522 video packets, zero audio packets - MPS-style stream copy with optional audio mapping - two-second 640x360 libx264 transcode - non-empty contradictory STSC/STCO control remains rejected I used GPT-5.6-sol to analyze the files, make the code change, and draft this email. I tested the change on my DJI drone videos. libavformat/mov.c | 8 +++++--- tests/fate/mov.mak | 8 ++++++++ tests/ref/fate/mov-empty-audio-stsc | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 tests/ref/fate/mov-empty-audio-stsc diff --git a/libavformat/mov.c b/libavformat/mov.c index f53ce693f8..b16d173a4a 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -5575,9 +5575,11 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) c->trak_index = -1; - // Here stsc refers to a chunk not described in stco. This is technically invalid, - // but we can overlook it (clearing stsc) whenever stts_count == 0 (indicating no samples). - if (!sc->chunk_count && !sc->stts_count && sc->stsc_count) { + /* An empty track may contain a placeholder stsc entry even though stco + * contains no chunks. Ignore stsc only when neither stsz nor stts + * describes any samples. */ + if (!sc->chunk_count && !sc->sample_count && !st->nb_frames && + sc->stsc_count) { sc->stsc_count = 0; av_freep(&sc->stsc_data); } diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak index 1a81962626..55d81563c7 100644 --- a/tests/fate/mov.mak +++ b/tests/fate/mov.mak @@ -47,6 +47,8 @@ FATE_MOV_FFPROBE-$(call DEMDEC, MOV, HEVC) += fate-mov-dovi-hvce-mp4-read FATE_MOV_FFPROBE-$(call DEMDEC, MOV, H264) += fate-mov-vfr-bframes-duration +FATE_MOV_FFPROBE-$(call DEMDEC, MOV, MPEG4) += fate-mov-empty-audio-stsc + FATE_MOV_FASTSTART = fate-mov-faststart-4gb-overflow \ FATE_SAMPLES_FFMPEG += $(FATE_MOV-yes) $(FATE_MOV_REMUX-yes) @@ -169,6 +171,12 @@ fate-mov-mp4-with-mov-in24-ver: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entr fate-mov-mp4-extended-atom: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_packets -print_format compact -select_streams v $(TARGET_SAMPLES)/mov/extended_atom_size_probe +# An empty track may contain an STSC entry while having no chunks or samples. +fate-mov-empty-audio-stsc: CMD = run ffprobe$(PROGSSUF)$(EXESUF) \ + -show_entries stream=index,codec_name,codec_type,nb_frames,nb_read_packets \ + -count_packets -of compact -v 0 \ + $(TARGET_SAMPLES)/mov/empty-audio-stsc.mov + fate-mov-mime-codecstring: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries stream=mime_codec_string -v 0 $(TARGET_SAMPLES)/mov/mov_stream_shorter_than_movie.mov fate-mov-t35-cdsc-track: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries stream_group=index,id,nb_streams,type:stream_group_stream=index,id,codec_name,codec_type,codec_tag_string,extradata_size $(TARGET_SAMPLES)/mov/mov-t35-cdsc-track.mp4 diff --git a/tests/ref/fate/mov-empty-audio-stsc b/tests/ref/fate/mov-empty-audio-stsc new file mode 100644 index 0000000000..1d9f5247b7 --- /dev/null +++ b/tests/ref/fate/mov-empty-audio-stsc @@ -0,0 +1,2 @@ +stream|index=0|codec_name=mpeg4|codec_type=video|nb_frames=5|nb_read_packets=5 +stream|index=1|codec_name=aac|codec_type=audio|nb_frames=N/A|nb_read_packets=N/A -- 2.43.0 -- The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The Organisation accepts no liability for any damage caused by any virus transmitted by this email. www.ishafoundation.org <http://www.ishafoundation.org> -- <https://isha.sadhguru.org/in/en/miracle-of-mind?referrer=singular_click_id%3D7dcef6d9-9f8c-48aa-8131-27c73eed82fa&utm_campaign=mom_promo_2025&utm_content=mom_email_signaturefooter&utm_medium=email&utm_source=email_footer&utm_term=eng> _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
