Opened 8 months ago

Closed 8 months ago

Last modified 8 months ago

#7081 closed defect (fixed)

ffmpeg drops frames when transcoding a looped video stream

Reported by: Gyan Owned by:
Priority: normal Component: ffmpeg
Version: git-master Keywords: loop
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

If a video stream is looped and decoded, a few frames at the tail of each iteration except the last one are dropped.


How to reproduce

Generate sources

ffmpeg -f lavfi -i testsrc2 -t 1 v264.mp4

ffmpeg -f lavfi -i testsrc2 -c:v png -t 1 vpng.mp4

Loop H264 x1

ffmpeg -stream_loop 1 -i v264.mp4 264loop1.mp4 -v 40

ffmpeg version N-90168-gc0919c4985 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.0 (Rev1, Built by MSYS2 project)
  configuration:  --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-fontconfig --enable-libass --enable-libbluray --enable-libfreetype --enable-libmfx --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libwavpack --enable-libwebp --enable-libxml2 --enable-libzimg --enable-libshine --enable-gpl --enable-openssl --enable-avisynth --enable-chromaprint --enable-decklink --enable-frei0r --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libfdk-aac --enable-libflite --enable-libfribidi --enable-libgme --enable-libgsm --enable-libilbc --enable-libkvazaar --enable-libmodplug --enable-libopenh264 --enable-libopenmpt --enable-librtmp --enable-librubberband --enable-libssh --enable-libtesseract --enable-libxavs --enable-libxvid --enable-libzmq --enable-libzvbi --enable-opencl --enable-opengl --enable-libcodec2 --extra-cflags=-fopenmp --extra-libs=-lgomp --extra-cflags=-DLIBTWOLAME_STATIC --extra-libs=-lstdc++ --extra-cflags=-DLIBSSH_STATIC --extra-ldflags='-Wl,--allow-multiple-definition' --extra-cflags=-DCACA_STATIC --extra-cflags=-DMODPLUG_STATIC --extra-cflags=-DCHROMAPRINT_NODLL --extra-libs=-lstdc++ --extra-cflags=-DZMQ_STATIC --extra-libs=-lpsapi --extra-cflags=-DLIBXML_STATIC --disable-w32threads --extra-cflags=-DKVZ_STATIC_LIB --enable-version3 --enable-nonfree --disable-debug
  libavutil      56.  7.101 / 56.  7.101
  libavcodec     58. 13.100 / 58. 13.100
  libavformat    58. 10.100 / 58. 10.100
  libavdevice    58.  2.100 / 58.  2.100
  libavfilter     7. 12.100 /  7. 12.100
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
[h264 @ 0000000002984fc0] Reinit context to 320x240, pix_fmt: yuv420p
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'v264.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.9.100
  Duration: 00:00:01.00, start: 0.000000, bitrate: 295 kb/s
    Stream #0:0(und): Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], 286 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[h264 @ 0000000002979480] Reinit context to 320x240, pix_fmt: yuv420p
[graph 0 input from stream 0:0 @ 00000000029f2040] w:320 h:240 pixfmt:yuv420p tb:1/12800 fr:25/1 sar:1/1 sws_param:flags=2
[libx264 @ 000000000050c480] using SAR=1/1
[libx264 @ 000000000050c480] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000000000050c480] profile High, level 1.3
[libx264 @ 000000000050c480] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - 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=6 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 '264loop1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.10.100
    Stream #0:0(und): Video: h264 (libx264), 1 reference frame (avc1 / 0x31637661), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.13.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
[h264 @ 0000000002979480] Reinit context to 320x240, pix_fmt: yuv420p
*** 5 dup!
No more output streams to write to, finishing.
frame=   50 fps=0.0 q=-1.0 Lsize=      61kB time=00:00:01.88 bitrate= 264.3kbits/s dup=5 drop=0 speed=25.5x
video:59kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.380442%
Input file #0 (v264.mp4):
  Input stream #0:0 (video): 50 packets read (71598 bytes); 45 frames decoded;
  Total: 50 packets (71598 bytes) demuxed
Output file #0 (264loop1.mp4):
  Output stream #0:0 (video): 50 frames encoded; 50 packets muxed (60661 bytes);
  Total: 50 packets (60661 bytes) muxed
[libx264 @ 000000000050c480] frame I:1     Avg QP:21.65  size:  4473
[libx264 @ 000000000050c480] frame P:13    Avg QP:26.03  size:  1959
[libx264 @ 000000000050c480] frame B:36    Avg QP:31.64  size:   834
[libx264 @ 000000000050c480] consecutive B-frames:  2.0%  4.0%  6.0% 88.0%
[libx264 @ 000000000050c480] mb I  I16..4: 29.7% 45.7% 24.7%
[libx264 @ 000000000050c480] mb P  I16..4:  2.7%  5.4%  2.3%  P16..4: 17.8%  9.4%  6.0%  0.0%  0.0%    skip:56.4%
[libx264 @ 000000000050c480] mb B  I16..4:  0.1%  0.1%  0.1%  B16..8: 19.4%  5.5%  1.4%  direct: 1.9%  skip:71.5%  L0:53.0% L1:41.3% BI: 5.7%
[libx264 @ 000000000050c480] 8x8 transform intra:48.6% inter:31.5%
[libx264 @ 000000000050c480] coded y,uvDC,uvAC intra: 16.3% 35.9% 32.0% inter: 4.6% 13.2% 9.7%
[libx264 @ 000000000050c480] i16 v,h,dc,p: 71% 24%  6%  0%
[libx264 @ 000000000050c480] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 15% 61%  1%  0%  0%  0%  0%  0%
[libx264 @ 000000000050c480] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 40% 25% 24%  2%  2%  1%  4%  2%  1%
[libx264 @ 000000000050c480] i8c dc,h,v,p: 52% 18% 29%  1%
[libx264 @ 000000000050c480] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 000000000050c480] ref P L0: 58.0%  5.0% 23.4% 13.6%
[libx264 @ 000000000050c480] ref B L0: 80.2% 15.8%  4.0%
[libx264 @ 000000000050c480] ref B L1: 92.7%  7.3%
[libx264 @ 000000000050c480] kb/s:239.89

Loop H264 x5

ffmpeg -stream_loop 5 -i v264.mp4 264loop5.mp4 -v 40

ffmpeg version N-90168-gc0919c4985 Copyright (c) 2000-2018 the FFmpeg developers
...
[h264 @ 0000000002aa4fc0] Reinit context to 320x240, pix_fmt: yuv420p
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'v264.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.9.100
  Duration: 00:00:01.00, start: 0.000000, bitrate: 295 kb/s
    Stream #0:0(und): Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], 286 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[h264 @ 0000000002a99480] Reinit context to 320x240, pix_fmt: yuv420p
[graph 0 input from stream 0:0 @ 0000000003727c40] w:320 h:240 pixfmt:yuv420p tb:1/12800 fr:25/1 sar:1/1 sws_param:flags=2
[libx264 @ 00000000004bc480] using SAR=1/1
[libx264 @ 00000000004bc480] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 00000000004bc480] profile High, level 1.3
[libx264 @ 00000000004bc480] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - 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=6 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 '264loop5.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.10.100
    Stream #0:0(und): Video: h264 (libx264), 1 reference frame (avc1 / 0x31637661), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.13.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
[h264 @ 0000000002a99480] Reinit context to 320x240, pix_fmt: yuv420p
*** 5 dup!
[h264 @ 0000000002a99480] Reinit context to 320x240, pix_fmt: yuv420p
*** 5 dup!
[h264 @ 0000000002a99480] Reinit context to 320x240, pix_fmt: yuv420p
*** 5 dup!
[h264 @ 0000000002a99480] Reinit context to 320x240, pix_fmt: yuv420p
*** 5 dup!
[h264 @ 0000000002a99480] Reinit context to 320x240, pix_fmt: yuv420p
*** 5 dup!
No more output streams to write to, finishing.
frame=  150 fps=0.0 q=-1.0 Lsize=     165kB time=00:00:05.88 bitrate= 230.3kbits/s dup=25 drop=0 speed=31.9x
video:163kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.567206%
Input file #0 (v264.mp4):
  Input stream #0:0 (video): 150 packets read (214794 bytes); 125 frames decoded;
  Total: 150 packets (214794 bytes) demuxed
Output file #0 (264loop5.mp4):
  Output stream #0:0 (video): 150 frames encoded; 150 packets muxed (166666 bytes);
  Total: 150 packets (166666 bytes) muxed
[libx264 @ 00000000004bc480] frame I:1     Avg QP:21.65  size:  4473
[libx264 @ 00000000004bc480] frame P:41    Avg QP:25.44  size:  1983
[libx264 @ 00000000004bc480] frame B:108   Avg QP:31.61  size:   743
[libx264 @ 00000000004bc480]...

Loop PNG x1

ffmpeg -stream_loop 1 -i vpng.mp4 pngloop1.mp4 -v 40

ffmpeg version N-90168-gc0919c4985 Copyright (c) 2000-2018 the FFmpeg developers
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vpng.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.10.100
  Duration: 00:00:01.00, start: 0.000000, bitrate: 5659 kb/s
    Stream #0:0(und): Video: png, 1 reference frame (mp4v / 0x7634706D), rgb24(pc, progressive), 320x240 [SAR 1:1 DAR 4:
3], 5652 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[graph 0 input from stream 0:0 @ 0000000002b1cd40] w:320 h:240 pixfmt:rgb24 tb:1/12800 fr:25/1 sar:1/1 sws_param:flags=2

[auto_scaler_0 @ 0000000002b1e940] w:iw h:ih flags:'bicubic' interl:0
[format @ 0000000002b1e300] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_null_0' and the filter 'for
mat'
[auto_scaler_0 @ 0000000002b1e940] w:320 h:240 fmt:rgb24 sar:1/1 -> w:320 h:240 fmt:yuv444p sar:1/1 flags:0x4
[libx264 @ 0000000002aaa0c0] using SAR=1/1
[libx264 @ 0000000002aaa0c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0000000002aaa0c0] profile High 4:4:4 Predictive, level 1.3, 4:4:4 8-bit
[libx264 @ 0000000002aaa0c0] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.vid
eolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed
_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=6 lookahe
ad_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_a
dapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahea
d=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 'pngloop1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.10.100
    Stream #0:0(und): Video: h264 (libx264), 1 reference frame (avc1 / 0x31637661), yuv444p, 320x240 [SAR 1:1 DAR 4:3],
q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.13.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
*** 3 dup!
No more output streams to write to, finishing.
frame=   50 fps=0.0 q=-1.0 Lsize=      55kB time=00:00:01.88 bitrate= 240.9kbits/s dup=3 drop=0 speed=14.6x
video:54kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.616026%
Input file #0 (vpng.mp4):
  Input stream #0:0 (video): 50 packets read (1413054 bytes); 47 frames decoded;
  Total: 50 packets (1413054 bytes) demuxed
Output file #0 (pngloop1.mp4):
  Output stream #0:0 (video): 50 frames encoded; 50 packets muxed (55160 bytes);
  Total: 50 packets (55160 bytes) muxed
[libx264 @ 0000000002aaa0c0] frame I:1     Avg QP:15.92  size:  3799
[libx264 @ 0000000002aaa0c0] frame P:13    Avg QP:21.75  size:  1732
[libx264 @ 0000000002aaa0c0] frame B:36    Avg QP:32.65  size:   782
[libx264 @ 0000000002aaa0c0]...

Loop PNG x5

ffmpeg -stream_loop 5 -i vpng.mp4 pngloop5.mp4 -v 40

ffmpeg version N-90168-gc0919c4985 Copyright (c) 2000-2018 the FFmpeg developers
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vpng.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.10.100
  Duration: 00:00:01.00, start: 0.000000, bitrate: 5659 kb/s
    Stream #0:0(und): Video: png, 1 reference frame (mp4v / 0x7634706D), rgb24(pc, progressive), 320x240 [SAR 1:1 DAR 4:3], 5652 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[graph 0 input from stream 0:0 @ 000000000441cb80] w:320 h:240 pixfmt:rgb24 tb:1/12800 fr:25/1 sar:1/1 sws_param:flags=2
[auto_scaler_0 @ 000000000441f680] w:iw h:ih flags:'bicubic' interl:0
[format @ 000000000441f240] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_null_0' and the filter 'format'
[auto_scaler_0 @ 000000000441f680] w:320 h:240 fmt:rgb24 sar:1/1 -> w:320 h:240 fmt:yuv444p sar:1/1 flags:0x4
[libx264 @ 00000000029da0c0] using SAR=1/1
[libx264 @ 00000000029da0c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 00000000029da0c0] profile High 4:4:4 Predictive, level 1.3, 4:4:4 8-bit
[libx264 @ 00000000029da0c0] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=6 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 'pngloop5.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.10.100
    Stream #0:0(und): Video: h264 (libx264), 1 reference frame (avc1 / 0x31637661), yuv444p, 320x240 [SAR 1:1 DAR 4:3], q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.13.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
*** 3 dup!
    Last message repeated 4 times
No more output streams to write to, finishing.
frame=  150 fps=0.0 q=-1.0 Lsize=     155kB time=00:00:05.88 bitrate= 216.2kbits/s dup=15 drop=0 speed=26.6x
video:153kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.670367%
Input file #0 (vpng.mp4):
  Input stream #0:0 (video): 150 packets read (4239162 bytes); 135 frames decoded;
  Total: 150 packets (4239162 bytes) demuxed
Output file #0 (pngloop5.mp4):
  Output stream #0:0 (video): 150 frames encoded; 150 packets muxed (156313 bytes);
  Total: 150 packets (156313 bytes) muxed
[libx264 @ 00000000029da0c0] frame I:1     Avg QP:15.92  size:  3799
[libx264 @ 00000000029da0c0] frame P:41    Avg QP:21.27  size:  1747
[libx264 @ 00000000029da0c0] frame B:108   Avg QP:32.31  size:   742
[libx264 @ 00000000029da0c0]...

This behaviour is due to the decoders being flushed in fn seek_to_start in ffmpeg.c

        // flush decoders
        if (ist->decoding_needed) {
            process_input_packet(ist, NULL, 1);
            avcodec_flush_buffers(avctx);
}

If this step is skipped, no frames are dropped.


Loop H264 x5 - patched

ffmpeg-wip -stream_loop 5 -i v264.mp4 264loop5.mp4 -v 40

ffmpeg version N-90284-g950170bd3b-2018-03-10 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.0 (Rev1, Built by MSYS2 project)
  configuration: --disable-everything --disable-doc --enable-protocols --enable-indev=lavfi --enable-demuxer='avi,concat,image2,matroska,mov,mp3,mpegps,mpegts,nut,rawvideo,wav' --enable-decoder='aac,h264,mjpeg,mp2,mp3,mpeg2video,mpeg4,pcm_dvd,pcm_s16be,pcm_s16le,png,rawvideo' --enable-filter='setpts,settb,scale,showinfo,ashowinfo,asetpts,aresample' --enable-encoder='aac,flac,libmp3lame,mjpeg,mpeg2video,mpeg4,mp2,pcm_s16be,pcm_s16le,png,rawvideo,wrapped_avframe' --enable-muxer='adts,avi,image2,matroska,mp3,mp4,mpeg1system,mpeg1vcd,mpeg2dvd,mpeg2svcd,mpeg2vob,mpegts,null,nut,rawvideo,wav' --enable-outdev=sdl2 --enable-libmp3lame --disable-w32threads --enable-pthreads --enable-static --disable-shared --extra-ldflags=-static --pkg-config-flags=--static --enable-gpl --enable-version3 --extra-version=2018-03-10 --progs-suffix=-wip
  libavutil      56.  9.100 / 56.  9.100
  libavcodec     58. 14.100 / 58. 14.100
  libavformat    58. 10.100 / 58. 10.100
  libavdevice    58.  2.100 / 58.  2.100
  libavfilter     7. 12.100 /  7. 12.100
  libswscale      5.  0.102 /  5.  0.102
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
[h264 @ 00000000004a90c0] Reinit context to 320x240, pix_fmt: yuv420p
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'v264.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.9.100
  Duration: 00:00:01.00, start: 0.000000, bitrate: 295 kb/s
    Stream #0:0(und): Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], 286 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
[h264 @ 000000000055f840] Reinit context to 320x240, pix_fmt: yuv420p
[graph 0 input from stream 0:0 @ 0000000003c3c980] w:320 h:240 pixfmt:yuv420p tb:1/12800 fr:25/1 sar:1/1 sws_param:flags=2

Output #0, mp4, to '264loop5.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.10.100
    Stream #0:0(und): Video: mpeg4, 1 reference frame (mp4v / 0x7634706D), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.14.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
No more output streams to write to, finishing.
frame=  150 fps=0.0 q=16.0 Lsize=     244kB time=00:00:05.96 bitrate= 335.7kbits/s speed=96.6x
video:243kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.613559%
Input file #0 (v264.mp4):
  Input stream #0:0 (video): 150 packets read (214794 bytes); 150 frames decoded;
  Total: 150 packets (214794 bytes) demuxed
Output file #0 (264loop5.mp4):
  Output stream #0:0 (video): 150 frames encoded; 150 packets muxed (248550 bytes);
  Total: 150 packets (248550 bytes) muxed

Loop PNG x5 - patched

ffmpeg-wip -stream_loop 5 -i vpng.mp4 pngloop5.mp4 -v 40

ffmpeg version N-90284-g950170bd3b-2018-03-10 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.0 (Rev1, Built by MSYS2 project)
  configuration: --disable-everything --disable-doc --enable-protocols --enable-indev=lavfi --enable-demuxer='avi,concat,image2,matroska,mov,mp3,mpegps,mpegts,nut,rawvideo,wav' --enable-decoder='aac,h264,mjpeg,mp2,mp3,mpeg2video,mpeg4,pcm_dvd,pcm_s16be,pcm_s16le,png,rawvideo' --enable-filter='setpts,settb,scale,showinfo,ashowinfo,asetpts,aresample' --enable-encoder='aac,flac,libmp3lame,mjpeg,mpeg2video,mpeg4,mp2,pcm_s16be,pcm_s16le,png,rawvideo,wrapped_avframe' --enable-muxer='adts,avi,image2,matroska,mp3,mp4,mpeg1system,mpeg1vcd,mpeg2dvd,mpeg2svcd,mpeg2vob,mpegts,null,nut,rawvideo,wav' --enable-outdev=sdl2 --enable-libmp3lame --disable-w32threads --enable-pthreads --enable-static --disable-shared --extra-ldflags=-static --pkg-config-flags=--static --enable-gpl --enable-version3 --extra-version=2018-03-10 --progs-suffix=-wip
  libavutil      56.  9.100 / 56.  9.100
  libavcodec     58. 14.100 / 58. 14.100
  libavformat    58. 10.100 / 58. 10.100
  libavdevice    58.  2.100 / 58.  2.100
  libavfilter     7. 12.100 /  7. 12.100
  libswscale      5.  0.102 /  5.  0.102
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vpng.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.10.100
  Duration: 00:00:01.00, start: 0.000000, bitrate: 5659 kb/s
    Stream #0:0(und): Video: png, 1 reference frame (mp4v / 0x7634706D), rgb24(pc, progressive), 320x240 [SAR 1:1 DAR 4:3], 5652 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
[graph 0 input from stream 0:0 @ 00000000004bd3c0] w:320 h:240 pixfmt:rgb24 tb:1/12800 fr:25/1 sar:1/1 sws_param:flags=2
[auto_scaler_0 @ 00000000004bdd80] w:iw h:ih flags:'bicubic' interl:0
[format @ 00000000004bd980] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_null_0' and the filter 'format'
[auto_scaler_0 @ 00000000004bdd80] w:320 h:240 fmt:rgb24 sar:1/1 -> w:320 h:240 fmt:yuv420p sar:1/1 flags:0x4
Output #0, mp4, to 'pngloop5.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.10.100
    Stream #0:0(und): Video: mpeg4, 1 reference frame (mp4v / 0x7634706D), yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.14.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
No more output streams to write to, finishing.
frame=  150 fps=0.0 q=15.4 Lsize=     244kB time=00:00:05.96 bitrate= 335.0kbits/s speed=47.6x
video:242kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.614758%
Input file #0 (vpng.mp4):
  Input stream #0:0 (video): 150 packets read (4239162 bytes); 150 frames decoded;
  Total: 150 packets (4239162 bytes) demuxed
Output file #0 (pngloop5.mp4):
  Output stream #0:0 (video): 150 frames encoded; 150 packets muxed (248065 bytes);
  Total: 150 packets (248065 bytes) muxed

I don't see similar behaviour for audio streams.

Is the flushing step incorrectly implemented?

I'm implementing stream_loop for when multiple input files are supplied, and I came across this behaviour. Think this should get fixed first.

Change History (6)

comment:1 Changed 8 months ago by cehoyos

  • Component changed from undetermined to ffmpeg
  • Keywords loop added

What's wrong with the concat demuxer?

comment:2 Changed 8 months ago by Gyan

I don't know. I haven't looked :)

This is about a bug with stream_loop. I have got it working with multiple input files but I wanted to get this resolved first. Speaking of the concat demuxer, I glanced at it and see decoders aren't flushed there when switching to new files. Why was the step added for stream_loop?

comment:3 Changed 8 months ago by Gyan

Issue identified. Patch is at https://patchwork.ffmpeg.org/patch/7999/

comment:4 Changed 8 months ago by Gyan

  • Resolution set to fixed
  • Status changed from new to closed

comment:5 Changed 8 months ago by llogan

I think you meant to close #7091 instead.

comment:6 Changed 8 months ago by Gyan

Sorry, meant to close this one but patch link is wrong. Fixed in 8ad83044b47a2544907562f5e8fd11dd1a62ef82

Note: See TracTickets for help on using tickets.