#11668: Audio being much longer than video will make -shortest clamp to 1 second
-------------------------------------+-------------------------------------
             Reporter:  RavenWorks   |                    Owner:  (none)
                 Type:  defect       |                   Status:  new
             Priority:  normal       |                Component:
                                     |  undetermined
              Version:  7.1          |               Resolution:
             Keywords:               |               Blocked By:
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
-------------------------------------+-------------------------------------

Old description:

> Summary of the bug:  Feeding (for example) a 0.15 sec video file and a 50
> sec audio file into ffmpeg with -shortest will produce a 1 sec file (a
> length that doesn't correspond to EITHER input).   Notably though, a 0.15
> sec video and **5** sec audio will give the correct output (0.15 sec
> file).
>
> I first encountered this with anullsrc for the audio source, but I
> reproduced it with regular wav files just to be certain that it wasn't
> something about anullsrc in particular.
>
> Don't mind the fact that I'm recompressing the video for nothing in this
> example; in the original context I need to be recompressing the video for
> unrelated reasons (and, notably, the bug *doesn't* occur when using -c:v
> copy.)
>
> It might be hard to even see the video files in VLC due to their
> shortness; MPV and Firefox can both loop them fine.
>
> How to reproduce:
> {{{
> % ffmpeg -y -i .\50sec.wav -i .\no_audio.mp4 -shortest silent_audio.mp4
> ffmpeg version 7.1.1-full_build-www.gyan.dev Copyright (c) 2000-2025 the
> FFmpeg developers
>   built with gcc 14.2.0 (Rev1, Built by MSYS2 project)
>   configuration: --enable-gpl --enable-version3 --enable-static
> --disable-w32threads --disable-autodetect --enable-fontconfig --enable-
> iconv --enable-gnutls --enable-lcms2 --enable-libxml2 --enable-gmp
> --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-
> librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth
> --enable-libbluray --enable-libcaca --enable-libdvdnav --enable-
> libdvdread --enable-sdl2 --enable-libaribb24 --enable-libaribcaption
> --enable-libdav1d --enable-libdavs2 --enable-libopenjpeg --enable-
> libquirc --enable-libuavs3d --enable-libxevd --enable-libzvbi --enable-
> libqrencode --enable-librav1e --enable-libsvtav1 --enable-libvvenc
> --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2
> --enable-libxeve --enable-libxvid --enable-libaom --enable-libjxl
> --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r
> --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-
> liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg
> --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-
> d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-
> nvdec --enable-nvenc --enable-vaapi --enable-libshaderc --enable-vulkan
> --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme
> --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb
> --enable-libmp3lame --enable-libshine --enable-libtheora --enable-
> libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc
> --enable-libgsm --enable-liblc3 --enable-libopencore-amrnb --enable-
> libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-
> libbs2b --enable-libflite --enable-libmysofa --enable-librubberband
> --enable-libsoxr --enable-chromaprint
>   libavutil      59. 39.100 / 59. 39.100
>   libavcodec     61. 19.101 / 61. 19.101
>   libavformat    61.  7.100 / 61.  7.100
>   libavdevice    61.  3.100 / 61.  3.100
>   libavfilter    10.  4.100 / 10.  4.100
>   libswscale      8.  3.100 /  8.  3.100
>   libswresample   5.  3.100 /  5.  3.100
>   libpostproc    58.  3.100 / 58.  3.100
> [aist#0:0/pcm_s16le @ 000001cccab59200] Guessed Channel Layout: mono
> Input #0, wav, from '.\50sec.wav':
>   Duration: 00:00:50.00, bitrate: 705 kb/s
>   Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono,
> s16, 705 kb/s
> Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '.\no_audio.mp4':
>   Metadata:
>     major_brand     : isom
>     minor_version   : 512
>     compatible_brands: isomiso2avc1mp41
>     encoder         : Lavf61.7.100
>   Duration: 00:00:00.15, start: 0.000000, bitrate: 157 kb/s
>   Stream #1:0[0x1](und): Video: h264 (Constrained Baseline) (avc1 /
> 0x31637661), yuv420p(progressive), 256x64, 110 kb/s, 60 fps, 60 tbr,
> 15360 tbn (default)
>       Metadata:
>         handler_name    : VideoHandler
>         vendor_id       : [0][0][0][0]
>         encoder         : Lavc61.19.101 libx264
> Stream mapping:
>   Stream #1:0 -> #0:0 (h264 (native) -> h264 (libx264))
>   Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (native))
> Press [q] to stop, [?] for help
> [libx264 @ 000001cccaac7e00] using cpu capabilities: MMX2 SSE2Fast SSSE3
> SSE4.2 AVX FMA3 BMI2 AVX2
> [libx264 @ 000001cccaac7e00] profile High, level 1.2, 4:2:0, 8-bit
> [libx264 @ 000001cccaac7e00] 264 - core 164 r3204 373697b - H.264/MPEG-4
> AVC codec - Copyleft 2003-2025 - http://www.videolan.org/x264.html -
> options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7
> psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1
> 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=2
> lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0
> bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1
> b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25
> scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0
> qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
> Output #0, mp4, to 'silent_audio.mp4':
>   Metadata:
>     encoder         : Lavf61.7.100
>   Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p(tv,
> progressive), 256x64, q=2-31, 60 fps, 15360 tbn (default)
>       Metadata:
>         handler_name    : VideoHandler
>         vendor_id       : [0][0][0][0]
>         encoder         : Lavc61.19.101 libx264
>       Side data:
>         cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
>   Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp,
> 69 kb/s
>       Metadata:
>         encoder         : Lavc61.19.101 aac
> [out#0/mp4 @ 000001cccaabf1c0] video:2KiB audio:9KiB subtitle:0KiB other
> streams:0KiB global headers:0KiB muxing overhead: 15.732564%
> frame=    9 fps=0.0 q=-1.0 Lsize=      13KiB time=00:00:00.11 bitrate=
> 880.7kbits/s speed=5.52x
> [libx264 @ 000001cccaac7e00] frame I:4     Avg QP:31.54  size:   243
> [libx264 @ 000001cccaac7e00] frame P:5     Avg QP:22.03  size:    71
> [libx264 @ 000001cccaac7e00] mb I  I16..4: 11.7% 74.6% 13.7%
> [libx264 @ 000001cccaac7e00] mb P  I16..4:  0.0%  2.8%  3.4%  P16..4:
> 4.7%  0.0%  0.0%  0.0%  0.0%    skip:89.1%
> [libx264 @ 000001cccaac7e00] 8x8 transform intra:72.5% inter:100.0%
> [libx264 @ 000001cccaac7e00] coded y,uvDC,uvAC intra: 8.5% 0.0% 0.0%
> inter: 0.2% 0.0% 0.0%
> [libx264 @ 000001cccaac7e00] i16 v,h,dc,p: 10%  0% 90%  0%
> [libx264 @ 000001cccaac7e00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 45%  1% 53%
> 1%  0%  0%  0%  0%  0%
> [libx264 @ 000001cccaac7e00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 21% 38%
> 8%  3%  3%  3%  4%  4%
> [libx264 @ 000001cccaac7e00] i8c dc,h,v,p: 100%  0%  0%  0%
> [libx264 @ 000001cccaac7e00] Weighted P-Frames: Y:0.0% UV:0.0%
> [libx264 @ 000001cccaac7e00] ref P L0: 46.7%  0.0% 26.7% 26.7%
> [libx264 @ 000001cccaac7e00] kb/s:70.93
> [aac @ 000001cccb099ac0] Qavg: 32.825
> }}}
>

> And just to be clear:
> {{{
> % ffmpeg -y -i .\5sec.wav -i .\no_audio.mp4 -shortest silent_audio.mp4
> }}}
> produces an output that is NOT bugged (provided to demonstrate that the
> problem seems to be related to audio length).

New description:

 Summary of the bug:  Feeding (for example) a 0.15 sec video file and a 25
 sec audio file into ffmpeg with -shortest will produce a 1 sec file (a
 length that doesn't correspond to EITHER input).   Notably though, a 0.15
 sec video and **5** sec audio will give the correct output (0.15 sec
 file).

 I first encountered this with anullsrc for the audio source, but I
 reproduced it with regular wav files just to be certain that it wasn't
 something about anullsrc in particular.

 Don't mind the fact that I'm recompressing the video for nothing in this
 example; in the original context I need to be recompressing the video for
 unrelated reasons (and, notably, the bug *doesn't* occur when using -c:v
 copy.)

 It might be hard to even see the video files in VLC due to their
 shortness; MPV and Firefox can both loop them fine.

 How to reproduce:
 {{{
 ffmpeg -y -i .\25sec.wav -i .\no_audio.mp4 -shortest silent_audio.mp4
 ffmpeg version 7.1.1-full_build-www.gyan.dev Copyright (c) 2000-2025 the
 FFmpeg developers
   built with gcc 14.2.0 (Rev1, Built by MSYS2 project)
   configuration: --enable-gpl --enable-version3 --enable-static --disable-
 w32threads --disable-autodetect --enable-fontconfig --enable-iconv
 --enable-gnutls --enable-lcms2 --enable-libxml2 --enable-gmp --enable-
 bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist
 --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth
 --enable-libbluray --enable-libcaca --enable-libdvdnav --enable-libdvdread
 --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-
 libdav1d --enable-libdavs2 --enable-libopenjpeg --enable-libquirc
 --enable-libuavs3d --enable-libxevd --enable-libzvbi --enable-libqrencode
 --enable-librav1e --enable-libsvtav1 --enable-libvvenc --enable-libwebp
 --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxeve
 --enable-libxvid --enable-libaom --enable-libjxl --enable-libvpx --enable-
 mediafoundation --enable-libass --enable-frei0r --enable-libfreetype
 --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-
 libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-
 llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va
 --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-
 vaapi --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-
 opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-
 libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-
 libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc
 --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-liblc3
 --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-
 libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-
 libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
   libavutil      59. 39.100 / 59. 39.100
   libavcodec     61. 19.101 / 61. 19.101
   libavformat    61.  7.100 / 61.  7.100
   libavdevice    61.  3.100 / 61.  3.100
   libavfilter    10.  4.100 / 10.  4.100
   libswscale      8.  3.100 /  8.  3.100
   libswresample   5.  3.100 /  5.  3.100
   libpostproc    58.  3.100 / 58.  3.100
 [aist#0:0/pcm_s16le @ 0000017f66bd9200] Guessed Channel Layout: mono
 Input #0, wav, from '.\25sec.wav':
   Duration: 00:00:25.00, bitrate: 705 kb/s
   Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono,
 s16, 705 kb/s
 Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '.\no_audio.mp4':
   Metadata:
     major_brand     : isom
     minor_version   : 512
     compatible_brands: isomiso2avc1mp41
     encoder         : Lavf61.7.100
   Duration: 00:00:00.15, start: 0.000000, bitrate: 157 kb/s
   Stream #1:0[0x1](und): Video: h264 (Constrained Baseline) (avc1 /
 0x31637661), yuv420p(progressive), 256x64, 110 kb/s, 60 fps, 60 tbr, 15360
 tbn (default)
       Metadata:
         handler_name    : VideoHandler
         vendor_id       : [0][0][0][0]
         encoder         : Lavc61.19.101 libx264
 Stream mapping:
   Stream #1:0 -> #0:0 (h264 (native) -> h264 (libx264))
   Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (native))
 Press [q] to stop, [?] for help
 [libx264 @ 0000017f66b47e00] using cpu capabilities: MMX2 SSE2Fast SSSE3
 SSE4.2 AVX FMA3 BMI2 AVX2
 [libx264 @ 0000017f66b47e00] profile High, level 1.2, 4:2:0, 8-bit
 [libx264 @ 0000017f66b47e00] 264 - core 164 r3204 373697b - H.264/MPEG-4
 AVC codec - Copyleft 2003-2025 - http://www.videolan.org/x264.html -
 options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7
 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1
 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=2
 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0
 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1
 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25
 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0
 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
 Output #0, mp4, to 'silent_audio.mp4':
   Metadata:
     encoder         : Lavf61.7.100
   Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p(tv,
 progressive), 256x64, q=2-31, 60 fps, 15360 tbn (default)
       Metadata:
         handler_name    : VideoHandler
         vendor_id       : [0][0][0][0]
         encoder         : Lavc61.19.101 libx264
       Side data:
         cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
   Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp,
 69 kb/s
       Metadata:
         encoder         : Lavc61.19.101 aac
 [out#0/mp4 @ 0000017f66b3f1c0] video:2KiB audio:9KiB subtitle:0KiB other
 streams:0KiB global headers:0KiB muxing overhead: 15.708502%
 frame=    9 fps=0.0 q=-1.0 Lsize=      13KiB time=00:00:00.11 bitrate=
 881.9kbits/s speed=5.15x
 [libx264 @ 0000017f66b47e00] frame I:4     Avg QP:31.54  size:   243
 [libx264 @ 0000017f66b47e00] frame P:5     Avg QP:22.03  size:    71
 [libx264 @ 0000017f66b47e00] mb I  I16..4: 11.7% 74.6% 13.7%
 [libx264 @ 0000017f66b47e00] mb P  I16..4:  0.0%  2.8%  3.4%  P16..4:
 4.7%  0.0%  0.0%  0.0%  0.0%    skip:89.1%
 [libx264 @ 0000017f66b47e00] 8x8 transform intra:72.5% inter:100.0%
 [libx264 @ 0000017f66b47e00] coded y,uvDC,uvAC intra: 8.5% 0.0% 0.0%
 inter: 0.2% 0.0% 0.0%
 [libx264 @ 0000017f66b47e00] i16 v,h,dc,p: 10%  0% 90%  0%
 [libx264 @ 0000017f66b47e00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 45%  1% 53%
 1%  0%  0%  0%  0%  0%
 [libx264 @ 0000017f66b47e00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 21% 38%
 8%  3%  3%  3%  4%  4%
 [libx264 @ 0000017f66b47e00] i8c dc,h,v,p: 100%  0%  0%  0%
 [libx264 @ 0000017f66b47e00] Weighted P-Frames: Y:0.0% UV:0.0%
 [libx264 @ 0000017f66b47e00] ref P L0: 46.7%  0.0% 26.7% 26.7%
 [libx264 @ 0000017f66b47e00] kb/s:70.93
 [aac @ 0000017f67199e80] Qavg: 35.527
 }}}


 And just to be clear:
 {{{
 % ffmpeg -y -i .\5sec.wav -i .\no_audio.mp4 -shortest silent_audio.mp4
 }}}
 produces an output that is NOT bugged (provided to demonstrate that the
 problem seems to be related to audio length).

--
Comment (by RavenWorks):

 the 50sec.wav file I had originally mentioned in the description was too
 big to attach;  I made a 25sec.wav file that fits (and still reproduces
 the bug), and edited the description accordingly.
-- 
Ticket URL: <https://trac.ffmpeg.org/ticket/11668#comment:1>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
_______________________________________________
FFmpeg-trac mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-trac

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".

Reply via email to