FFMPEG 在颜色变化时编码 JPEG 序列时丢帧

FFMPEG 在颜色变化时编码 JPEG 序列时丢帧

我正在尝试使用 imagemagick 和 FFMPEG 制作幻灯片。我使用 imagemagick 将单张照片扩展为 30fps 的视频(imagemagick 还处理诸如在过程中在帧上添加一些文本标题之类的事情)。当我让 ffmpeg 将其消化成视频时,它会很好地剪辑视频的彩色部分,但当它到达黑白部分时,它会报告frame= 2030 fps=102 q=32766.0 Lsize= 5203kB time=00:01:07.60 bitrate= 630.5kbits/s dup=0 drop=703并丢弃视频的每一帧,直到它遇到有颜色的东西。你可以想象这会导致整个照片从幻灯片中删除。

这是我最新的转储...

ffmpeg -y -r 30 -i "teststream/%06d.jpg" -c:v libx264 -r 30 newffmpeg.mp4

ffmpeg version git-2012-12-10-c3bb333 Copyright (c) 2000-2012 the FFmpeg developers
built on Dec 10 2012 22:02:04 with gcc 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)
configuration: --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libx264 --enable-nonfree --enable-version3
  libavutil      52. 12.100 / 52. 12.100
  libavcodec     54. 79.101 / 54. 79.101
  libavformat    54. 49.100 / 54. 49.100
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 26.101 /  3. 26.101
  libswscale      2.  1.103 /  2.  1.103
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, image2, from 'teststream/%06d.jpg':
Duration: 00:12:02.80, start: 0.000000, bitrate: N/A
  Stream #0:0: Video: mjpeg, yuvj444p, 720x480 [SAR 72:72 DAR 3:2], 25 fps, 25 tbr, 25 tbn, 25 tbc
[libx264 @ 0x3450140] using SAR=1/1
[libx264 @ 0x3450140] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2
[libx264 @ 0x3450140] profile High, level 3.0
[libx264 @ 0x3450140] 264 - core 129 r2 1cffe9f - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - 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=12 lookahead_threads=2 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 'newffmpeg.mp4':
  Metadata:
    encoder         : Lavf54.49.100
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuvj420p, 720x480 [SAR 1:1 DAR 3:2], q=-1--1, 15360 tbn, 30 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg -> libx264)
Press [q] to stop, [?] for help
Input stream #0:0 frame changed from size:720x480 fmt:yuvj444p to size:720x480 fmt:yuvj422p
Input stream #0:0 frame changed from size:720x480 fmt:yuvj422p to size:720x480 fmt:yuvj444pp=584    
frame= 2030 fps=102 q=32766.0 Lsize=    5203kB time=00:01:07.60 bitrate= 630.5kbits/s dup=0 drop=703    
video:5179kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.472425%
[libx264 @ 0x3450140] frame I:9     Avg QP:20.10  size: 33933
[libx264 @ 0x3450140] frame P:636   Avg QP:24.12  size:  6737
[libx264 @ 0x3450140] frame B:1385  Avg QP:27.04  size:   514
[libx264 @ 0x3450140] consecutive B-frames:  2.5% 15.2% 13.2% 69.2%
[libx264 @ 0x3450140] mb I  I16..4:  8.3% 80.3% 11.5%
[libx264 @ 0x3450140] mb P  I16..4:  1.5%  2.5%  0.2%  P16..4: 41.7% 18.0% 10.3%  0.0%  0.0%    skip:25.9%
[libx264 @ 0x3450140] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8: 26.6%  0.6%  0.1%  direct: 0.2%  skip:72.3%  L0:35.0% L1:60.3% BI: 4.7%
[libx264 @ 0x3450140] 8x8 transform intra:64.1% inter:75.1%
[libx264 @ 0x3450140] coded y,uvDC,uvAC intra: 51.6% 78.0% 43.7% inter: 10.6% 14.9% 2.1%
[libx264 @ 0x3450140] i16 v,h,dc,p: 29% 19%  6% 46%
[libx264 @ 0x3450140] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 15% 17%  5%  9% 10%  7%  8%  6%
[libx264 @ 0x3450140] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 31% 18% 11%  5%  9% 10%  6%  6%  4%
[libx264 @ 0x3450140] i8c dc,h,v,p: 46% 18% 24% 12%
[libx264 @ 0x3450140] Weighted P-Frames: Y:20.1% UV:18.7%
[libx264 @ 0x3450140] ref P L0: 59.2% 23.2% 13.1%  4.3%  0.2%
[libx264 @ 0x3450140] ref B L0: 88.7%  8.3%  3.0%
[libx264 @ 0x3450140] ref B L1: 95.0%  5.0%
[libx264 @ 0x3450140] kb/s:626.88
Received signal 2: terminating.

最后一点:如果我-r 30从输入和输出中删除,它就可以正常工作。我不知道为什么-r 30会导致它崩溃。

答案1

仅当您使用原始输入文件(例如 h.264 比特流)时,强制输入(之前)和输出(输出文件名之前)的帧速率-i才可靠地工作,您需要明确告诉 FFmpeg 您期望的帧速率。

在读取图像的情况下,您可以看到模块image2仍然以每秒 25 帧的速度读取,即使您-r 30之前指定了-i

Stream #0:0: Video: mjpeg, […] 25 fps, 25 tbr, 25 tbn, 25 tbc

您应该使用的实际选项image2-framerate

ffmpeg -framerate 30 -i "teststream/%06d.jpg" -c:v libx264 -r 30 newffmpeg.mp4

这应该可以正确设置输入率,但由于您提到当忽略两个选项时它可以工作,所以我只会坚持这样做。

相关内容