FFmpeg drops frames when encoding a png image sequence into an x264 mp4 video

24
2013-08
  • PtrFdr

    I'm trying to encode an image-sequence (frame0001.png, frame0002.png, ... , frame0160.png) into an x264 video using the following command:

    ffmpeg -i frame%04d.png -sameq -r 24 out.mp4
    

    After encoding, it says drop=5 and indeed there are noticeable “jumps” in the video.

    It appears someone else had a similar problem, but for me the accepted answer isn't very useful since I'd like to have no frames dropped.

    Is a switch missing from the command? Or am I doing something else wrong?


    Edit: Added console output:

    ffmpeg version N-42347-g299387e Copyright (c) 2000-2012 the FFmpeg developers
      built on Jul  8 2012 15:46:39 with gcc 4.7.1
      configuration: --disable-static --enable-shared --enable-gpl --enable-version3
     --disable-w32threads --enable-runtime-cpudetect --enable-avisynth --enable-bzli
    b --enable-frei0r --enable-libass --enable-libcelt --enable-libopencore-amrnb --
    enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lam
    e --enable-libnut --enable-libopenjpeg --enable-librtmp --enable-libschroedinger
     --enable-libspeex --enable-libtheora --enable-libutvideo --enable-libvo-aacenc
    --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --en
    able-libxavs --enable-libxvid --enable-zlib
      libavutil      51. 64.100 / 51. 64.100
      libavcodec     54. 33.100 / 54. 33.100
      libavformat    54. 15.102 / 54. 15.102
      libavdevice    54.  1.100 / 54.  1.100
      libavfilter     3.  1.100 /  3.  1.100
      libswscale      2.  1.100 /  2.  1.100
      libswresample   0. 15.100 /  0. 15.100
      libpostproc    52.  0.100 / 52.  0.100
    Input #0, image2, from 'frame%04d.png':
      Duration: 00:00:06.40, start: 0.000000, bitrate: N/A
        Stream #0:0: Video: png, rgb24, 1920x1080, 25 fps, 25 tbr, 25 tbn, 25 tbc
    [graph 0 input from stream 0:0 @ 01cd1f60] w:1920 h:1080 pixfmt:rgb24 tb:1/25 fr
    :25/1 sar:0/1 sws_param:flags=2
    [output stream 0:0 @ 01cd2220] No opaque field provided
    [auto-inserted scaler 0 @ 01cd3540] w:1920 h:1080 fmt:rgb24 sar:0/1 -> w:1920 h:
    1080 fmt:yuv420p sar:0/1 flags:0x4
    [libx264 @ 01cd0dc0] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
    [libx264 @ 01cd0dc0] profile High, level 4.0
    [libx264 @ 01cd0dc0] 264 - core 125 r2200 999b753 - H.264/MPEG-4 AVC codec - Cop
    yleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deb
    lock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 m
    e_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chro
    ma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 i
    nterlaced=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=24 scenec
    ut=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 'out.mp4':
      Metadata:
        encoder         : Lavf54.15.102
        Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1920x1080, q=-1-
    -1, 24 tbn, 24 tbc
    Stream mapping:
      Stream #0:0 -> #0:0 (png -> libx264)
    Press [q] to stop, [?] for help
    frame=    8 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=   0.0kbits/s
    frame=   15 fps= 15 q=0.0 size=       0kB time=00:00:00.00 bitrate=   0.0kbits/s
    frame=   22 fps= 14 q=0.0 size=       0kB time=00:00:00.00 bitrate=   0.0kbits/s
    frame=   29 fps= 14 q=0.0 size=       0kB time=00:00:00.00 bitrate=   0.0kbits/s
    frame=   36 fps= 14 q=0.0 size=       0kB time=00:00:00.00 bitrate=   0.0kbits/s
    frame=   43 fps= 14 q=0.0 size=       0kB time=00:00:00.00 bitrate=   0.0kbits/s
    frame=   47 fps= 11 q=0.0 size=       0kB time=00:00:00.00 bitrate=   0.0kbits/s
    frame=   53 fps= 11 q=28.0 size=     111kB time=00:00:00.04 bitrate=21735.2kbits
    frame=   59 fps= 11 q=28.0 size=     268kB time=00:00:00.29 bitrate=7527.8kbits/
    frame=   63 fps= 10 q=28.0 size=     375kB time=00:00:00.45 bitrate=6708.1kbits/
    frame=   69 fps= 10 q=28.0 size=     538kB time=00:00:00.70 bitrate=6219.6kbits/
    frame=   74 fps= 10 q=28.0 size=     675kB time=00:00:00.91 bitrate=6032.7kbits/
    frame=   79 fps= 10 q=28.0 size=     802kB time=00:00:01.12 bitrate=5840.7kbits/
    frame=   84 fps= 10 q=28.0 size=     922kB time=00:00:01.33 bitrate=5662.9kbits/
    frame=   89 fps=9.9 q=28.0 size=    1060kB time=00:00:01.54 bitrate=5633.3kbits/
    frame=   94 fps=9.9 q=28.0 size=    1186kB time=00:00:01.75 bitrate=5551.2kbits/
    frame=   98 fps=9.7 q=28.0 size=    1309kB time=00:00:01.91 bitrate=5594.3kbits/
    frame=  103 fps=9.7 q=28.0 size=    1436kB time=00:00:02.12 bitrate=5536.4kbits/
    frame=  107 fps=9.6 q=28.0 size=    1533kB time=00:00:02.29 bitrate=5481.7kbits/
    frame=  112 fps=9.5 q=28.0 size=    1654kB time=00:00:02.50 bitrate=5421.3kbits/
    frame=  117 fps=9.4 q=28.0 size=    1781kB time=00:00:02.70 bitrate=5386.9kbits/
    frame=  123 fps=9.4 q=28.0 size=    1925kB time=00:00:02.95 bitrate=5331.5kbits/
    frame=  128 fps=9.4 q=28.0 size=    2030kB time=00:00:03.16 bitrate=5250.8kbits/
    frame=  133 fps=9.4 q=28.0 size=    2210kB time=00:00:03.37 bitrate=5363.8kbits/
    frame=  138 fps=9.3 q=28.0 size=    2356kB time=00:00:03.58 bitrate=5386.0kbits/
    frame=  142 fps=9.3 q=28.0 size=    2465kB time=00:00:03.75 bitrate=5384.3kbits/
    frame=  147 fps=9.3 q=28.0 size=    2602kB time=00:00:03.95 bitrate=5385.0kbits/
    frame=  151 fps=9.2 q=28.0 size=    2706kB time=00:00:04.12 bitrate=5374.3kbits/
    frame=  155 fps=9.2 q=28.0 size=    2812kB time=00:00:04.29 bitrate=5367.7kbits/
    frame=  155 fps=7.0 q=28.0 Lsize=    4129kB time=00:00:06.37 bitrate=5306.4kbits
    /s dup=0 drop=5
    video:4128kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.035320%
    [libx264 @ 01cd0dc0] frame I:2     Avg QP:21.97  size: 79850
    [libx264 @ 01cd0dc0] frame P:153   Avg QP:23.43  size: 26579
    [libx264 @ 01cd0dc0] mb I  I16..4:  9.6% 70.5% 19.9%
    [libx264 @ 01cd0dc0] mb P  I16..4:  7.0% 15.3%  0.7%  P16..4: 45.2%  9.1%  2.2%
     0.0%  0.0%    skip:20.5%
    [libx264 @ 01cd0dc0] 8x8 transform intra:66.7% inter:85.7%
    [libx264 @ 01cd0dc0] coded y,uvDC,uvAC intra: 38.6% 58.0% 6.0% inter: 16.2% 27.2
    % 0.2%
    [libx264 @ 01cd0dc0] i16 v,h,dc,p: 35% 29% 17% 19%
    [libx264 @ 01cd0dc0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 21% 31%  3%  4%  5%  4%
     4%  3%
    [libx264 @ 01cd0dc0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 19% 13%  5%  8%  9%  7%
     6%  4%
    [libx264 @ 01cd0dc0] i8c dc,h,v,p: 49% 23% 23%  5%
    [libx264 @ 01cd0dc0] Weighted P-Frames: Y:0.0% UV:0.0%
    [libx264 @ 01cd0dc0] ref P L0: 84.5% 10.9%  3.5%  1.1%
    [libx264 @ 01cd0dc0] kb/s:5235.14
    
  • Answers
  • PtrFdr

    Problem solved.

    By looking at the console output, it seems that the default framerate of the input sequence is 25 fps:

    Input #0, image2, from 'frame%04d.png':
      Duration: 00:00:06.40, start: 0.000000, bitrate: N/A
        Stream #0:0: Video: png, rgb24, 1920x1080, 25 fps, 25 tbr, 25 tbn, 25 tbc
    

    From the documentation:

    To force the frame rate of the input file (valid for raw formats only) to 1 fps and the frame rate of the output file to 24 fps:

    ffmpeg -r 1 -i input.m2v -r 24 output.avi
    

    So, all I needed to do just to add another -r 24:

    ffmpeg-r 24-i frame%04d.png -sameq -r 24 out.mp4

  • Sean Cheshire

    This site has information on making a movie using sequential images

    Also, as a comment on this question, sameq is not an option that should be used


  • Related Question

    Why does the quality of this video suck when converted with ffmpeg as opposed to mencoder?
  • scompt.com

    screesnshot

    Here's the command line that I'm using for both and the output. Any ideas? The bitrate of the two videos is comparable: both around 1500Kbps.

    ffmpeg command:

    ffmpeg -y -i aud.mp4 -acodec copy -i input.mp4 -ac 2 -vcodec libx264 -s 1280x720 
    -b 1850k -keyint_min 25 -g 250 -deinterlace -coder 1 -trellis 1 -directpred 1
    -b_strategy 1 -bf 3 -refs 3 -subq 5 -me_method hex -me_range 16 
    -partitions +parti8x8+parti4x4+partp8x8+partb8x8 -flags +loop 
    -flags2 +bpyramid+wpred+mixed_refs+dct8x8+fastpskip+mbtree -bufsize 2000k
    -sc_threshold 40 -cmp +chroma -qdiff 4 -qmin 5 -qmax 51 -qcomp 0.6 -i_qfactor 0.71
    -t 0:0:20 -wpredp 2 -r 25 -bt 1500000 output.mp4
    

    ffmpeg output:

    FFmpeg version SVN-r21602, Copyright (c) 2000-2010 Fabrice Bellard, et al.
      built on Feb 24 2010 18:28:53 with gcc 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
      configuration: --prefix=/var/jails/build/ --enable-static --disable-altivec --disable-debug --disable-network --enable-libvorbis --enable-libtheora --enable-libxvid --enable-libx264 --enable-libfaad --enable-libfaac --enable-gpl --disable-ffplay --disable-ffserver --enable-nonfree --enable-avfilter --enable-avfilter-lavf --enable-libmp3lame --enable-pthreads --enable-postproc --disable-shared --enable-static --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-avfilter --enable-avfilter-lavf
      libavutil     50. 8. 0 / 50. 8. 0
      libavcodec    52.51. 0 / 52.51. 0
      libavformat   52.50. 0 / 52.50. 0
      libavdevice   52. 2. 0 / 52. 2. 0
      libavfilter    1.17. 0 /  1.17. 0
      libswscale     0. 9. 0 /  0. 9. 0
      libpostproc   51. 2. 0 / 51. 2. 0
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'bad.aud.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: M4A mp42isomndia
        encoder         : Nero AAC codec / 1.3.3.0
      Duration: 00:07:24.30, start: 0.000000, bitrate: 90 kb/s
        Stream #0.0(und): Audio: aac, 44100 Hz, stereo, s16, 89 kb/s
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x8b6fe10]max_analyze_duration reached
    
    Seems stream 1 codec frame rate differs from container frame rate: 50.00 (50/1) -> 25.00 (25/1)
    Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'bad.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: mp42isomavc1
        encoder         : Sorenson Squeeze 5.0
      Duration: 00:07:24.32, start: 0.000000, bitrate: 910 kb/s
        Stream #1.0(und): Audio: aac, 48000 Hz, stereo, s16, 320 kb/s
        Stream #1.1(und): Video: h264, yuv420p, 1280x720 [PAR 1:1 DAR 16:9], 524 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
        Stream #1.2(und): Data: mp4s / 0x7334706D
        Stream #1.3(und): Data: mp4s / 0x7334706D
        Stream #1.4(eng): Data: rtp  / 0x20707472, 23 kb/s
        Stream #1.5(eng): Data: rtp  / 0x20707472, 34 kb/s
    [libx264 @ 0x8bae2c0]using SAR=1/1
    [libx264 @ 0x8bae2c0]using cpu capabilities: MMX2 SSE2 SSE3 Cache64
    [libx264 @ 0x8bae2c0]profile High, level 3.1
    Output #0, mp4, to 'out.mp4':
        Stream #0.0(und): Video: libx264, yuv420p, 1280x720 [PAR 1:1 DAR 16:9], q=5-51, 1850 kb/s, 25 tbn, 25 tbc
        Stream #0.1(und): Audio: aac, 44100 Hz, stereo, 89 kb/s
    Stream mapping:
      Stream #1.1 -> #0.0
      Stream #0.0 -> #0.1
    Press [q] to stop encoding
    frame=  499 fps= 10 q=-1.0 Lsize=    3514kB time=19.92 bitrate=1445.3kbits/s        
    video:3279kB audio:220kB global headers:0kB muxing overhead 0.432718%
    [libx264 @ 0x8bae2c0]frame I:3     Avg QP: 7.77  size: 66763
    [libx264 @ 0x8bae2c0]frame P:208   Avg QP: 6.89  size: 12756
    [libx264 @ 0x8bae2c0]frame B:288   Avg QP:11.95  size:  1748
    [libx264 @ 0x8bae2c0]consecutive B-frames: 22.0%  1.2%  1.8% 75.0%
    [libx264 @ 0x8bae2c0]mb I  I16..4: 66.1% 10.0% 23.9%
    [libx264 @ 0x8bae2c0]mb P  I16..4:  3.1%  1.4%  1.6%  P16..4: 14.5%  2.0%  1.5%  0.0%  0.0%    skip:75.9%
    [libx264 @ 0x8bae2c0]mb B  I16..4:  1.0%  0.6%  0.2%  B16..8:  2.6%  0.2%  0.2%  direct: 5.7%  skip:89.4%  L0:45.2% L1:46.4% BI: 8.4%
    [libx264 @ 0x8bae2c0]8x8 transform intra:23.9% inter:38.3%
    [libx264 @ 0x8bae2c0]coded y,uvDC,uvAC intra: 38.0% 34.2% 18.6% inter: 4.9% 6.7% 2.1%
    [libx264 @ 0x8bae2c0]i16 v,h,dc,p: 59% 34%  4%  3%
    [libx264 @ 0x8bae2c0]i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 35% 28%  2%  2%  2%  2%  2%  3%
    [libx264 @ 0x8bae2c0]i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 35% 15%  4%  4%  5%  4%  4%  4%
    [libx264 @ 0x8bae2c0]Weighted P-Frames: Y:9.1%
    [libx264 @ 0x8bae2c0]ref P L0: 71.5% 18.0%  3.2%  3.5%  3.7%
    [libx264 @ 0x8bae2c0]ref B L0: 90.3%  7.4%  2.3%
    [libx264 @ 0x8bae2c0]ref B L1: 91.5%  8.5%
    [libx264 @ 0x8bae2c0]kb/s:1345.52
    

    MEncoder command:

    mencoder bad.mp4 -oac pcm -ovc x264 -ofps 25.0 -vf scale=1280:720,harddup
    -o out2.mp4 -srate 48000 -endpos 20
    -x264encopts threads=1:bitrate=1850:vbv_bufsize=2000:bframes=3:frameref=3:subq=5:me=hex:b_pyramid=normal:partitions=all 
    

    MEncoder output:

    MEncoder SVN-r30554-4.1.2 (C) 2000-2010 MPlayer Team
    
    WARNING: OUTPUT FILE FORMAT IS _AVI_. See -of help.
    success: format: 0  data: 0x0 - 0x3036dc5
    libavformat file format detected.
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x8ed2b70]max_analyze_duration reached
    [lavf] Audio stream found, -aid 0
    [lavf] Video stream found, -vid 1
    VIDEO:  [H264]  1280x720  24bpp  25.000 fps  524.0 kbps (64.0 kbyte/s)
    [V] filefmt:44  fourcc:0x34363248  size:1280x720  fps:25.000  ftime:=0.0400
    ==========================================================================
    Opening audio decoder: [faad] AAC (MPEG2/4 Advanced Audio Coding)
    AUDIO: 48000 Hz, 2 ch, s16le, 320.0 kbit/20.83% (ratio: 40000->192000)
    Selected audio codec: [faad] afm: faad (FAAD AAC (MPEG-2/MPEG-4 Audio))
    ==========================================================================
    Opening video filter: [expand osd=1]
    Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
    Opening video filter: [harddup]
    Opening video filter: [scale w=1280 h=720]
    ==========================================================================
    Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
    Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
    ==========================================================================
    Movie-Aspect is 1.78:1 - prescaling to correct movie aspect..000 [0:0]
    [swscaler @ 0x8938400]using unscaled yuv420p -> yuv420p special converter
    x264 [info]: using SAR=1/1
    x264 [info]: using cpu capabilities: MMX2 SSE2 SSE3 Cache64
    x264 [info]: profile High, level 3.1
    New_Face failed. Maybe the font path is wrong.
    Please supply the text font file (~/.mplayer/subfont.ttf).
    subtitle font: load_sub_face failed.
    New_Face failed. Maybe the font path is wrong.
    Please supply the text font file (~/.mplayer/subfont.ttf).
    subtitle font: load_sub_face failed.
    Writing header...1f ( 2%)  0.00fps Trem:   0min   0mb  A-V:0.044 [0:0]]
    ODML: vprp aspect is 16:9.
    Setting audio delay to 0.080s.
    Writing header...
    ODML: vprp aspect is 16:9.
    Setting audio delay to 0.080s.
    Pos:  20.0s    542f ( 8%) 10.06fps Trem:  10min  79mb  A-V:0.053 [1144:1536]
    Flushing video frames.
    Writing index...
    Writing header...
    ODML: vprp aspect is 16:9.
    Setting audio delay to 0.080s.
    
    Video stream: 1063.410 kbit/s  (132926 B/s)  size: 2876525 bytes  21.640 secs  542 frames
    
    Audio stream: 1536.000 kbit/s  (192000 B/s)  size: 3840000 bytes  20.000 secs
    x264 [info]: frame I:3     Avg QP:10.62  size:106222
    x264 [info]: frame P:216   Avg QP:10.67  size:  9236
    x264 [info]: frame B:322   Avg QP:13.29  size:  1748
    x264 [info]: consecutive B-frames: 19.7%  0.7%  2.2% 77.3%
    x264 [info]: mb I  I16..4: 58.7%  8.0% 33.3%
    x264 [info]: mb P  I16..4:  2.8%  1.4%  1.3%  P16..4: 12.8%  1.6%  1.0%  0.2%  0.2%    skip:78.7%
    x264 [info]: mb B  I16..4:  0.7%  0.6%  0.2%  B16..8:  2.4%  0.3%  0.2%  direct: 6.7%  skip:88.9%  L0:44.3% L1:47.1% BI: 8.5%
    x264 [info]: 8x8 transform intra:26.2% inter:52.8%
    x264 [info]: coded y,uvDC,uvAC intra: 38.7% 35.5% 16.8% inter: 3.9% 6.7% 1.0%
    x264 [info]: i16 v,h,dc,p: 56% 37%  4%  4%
    x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 33% 29%  2%  2%  2%  2%  2%  3%
    x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 33% 16%  4%  4%  5%  4%  4%  4%
    x264 [info]: Weighted P-Frames: Y:8.8%
    x264 [info]: ref P L0: 69.0% 20.1%  3.6%  3.3%  4.0%
    x264 [info]: ref B L0: 91.5%  6.9%  1.6%
    x264 [info]: ref B L1: 95.0%  5.0%
    x264 [info]: kb/s:1063.41
    

  • Related Answers
  • scompt.com

    I'm an idiot. The video is non-interlaced and I was passing the -deinterlace flag to ffmpeg. This was the source of the artifacts.