使用ffmpeg将图像转换为视频

时间:2014-02-05 19:06:13

标签: ffmpeg

我在另一个论坛上问过这个问题,但从来没有运气。我在网上发现了以下命令,该命令应该使用FFmpeg从图像创建视频(每个持续5秒)。

ffmpeg -f image2 -r 1/5 -i img%03d.png -vcodec libx264 out.mp4

我已经跑了,我有两个名为img001.png和img002.png的图片,但是当我播放out.mp4时,只播放了img001.png的5秒剪辑。真正奇怪的是,在我的Windows Media Player中,它认为它是10秒长(2张图像@ 10秒),但当测量仪在视频中途(5秒)时,它就会结束。

有关可能发生的事情的任何建议吗?

我还尝试了一些我在网上找到的其他命令,但从来没有运气。他们最终会显示两个图像,但第一个图像只会闪烁一秒钟,或者其他一些图像会发生同样的事情会发生在视频结尾的第二个图像上。

我将ImageMagick安装到我的Windows Vista PC上的XAMPP中。如果需要,我可以从命令提供命令行输出。

编辑:添加了命令行输出

C:\xampp\htdocs>ffmpeg -f image2 -r 1/5 -i img%03d.png -vcodec libx264 out.mp4
ffmpeg version N-50911-g9efcfbe Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 13 2013 21:26:48 with gcc 4.7.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libg
sm --enable-libilbc --enable-libmp3lame --enable-libopencore-amrnb --enable-libo
pencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-li
bschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-lib
twolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enabl
e-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 19.100 / 52. 19.100
  libavcodec     55.  0.100 / 55.  0.100
  libavformat    55.  0.100 / 55.  0.100
  libavdevice    54.  4.100 / 54.  4.100
  libavfilter     3. 45.103 /  3. 45.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, image2, from 'img%03d.png':
  Duration: 00:00:10.00, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, rgb24, 800x600 [SAR 1:1 DAR 4:3], 0.20 tbr, 0.20 tb
n, 0.20 tbc
[libx264 @ 0032cae0] using SAR=1/1
[libx264 @ 0032cae0] using cpu capabilities: MMX2 SSE2Slow SlowCTZ
[libx264 @ 0032cae0] profile High 4:4:4 Predictive, level 3.1, 4:4:4 8-bit
[libx264 @ 0032cae0] 264 - core 130 r2274 c832fe9 - H.264/MPEG-4 AVC codec - Cop
yright 2003-2013 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 de
block=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 chr
oma_qp_offset=4 threads=3 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=1 scenecu
t=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         : Lavf55.0.100
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv444p, 800x600 [SAR 1:1
 DAR 4:3], q=-1--1, 16384 tbn, 0.20 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (png -> libx264)
Press [q] to stop, [?] for help
frame=    2 fps=0.0 q=2621023.0 Lsize=      37kB time=00:00:10.00 bitrate=  30.0
kbits/s
video:36kB audio:0kB subtitle:0 global headers:0kB muxing overhead 2.142993%
[libx264 @ 0032cae0] frame I:1     Avg QP:11.18  size: 17627
[libx264 @ 0032cae0] frame P:1     Avg QP:11.45  size: 18415
[libx264 @ 0032cae0] mb I  I16..4: 18.3% 69.5% 12.3%
[libx264 @ 0032cae0] mb P  I16..4: 11.6% 60.1%  9.7%  P16..4:  8.9%  6.6%  2.2%
 0.0%  0.0%    skip: 0.8%
[libx264 @ 0032cae0] 8x8 transform intra:71.4% inter:67.1%
[libx264 @ 0032cae0] coded y,u,v intra: 57.0% 24.1% 22.3% inter: 42.6% 25.7% 16.
4%
[libx264 @ 0032cae0] i16 v,h,dc,p: 28% 50% 15%  8%
[libx264 @ 0032cae0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 39% 28%  2%  2%  2%  3%
 3%  4%
[libx264 @ 0032cae0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 53% 23%  1%  2%  2%  3%
 0%  2%
[libx264 @ 0032cae0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0032cae0] kb/s:28.83

C:\xampp\htdocs>

1 个答案:

答案 0 :(得分:1)

我认为你唯一的问题是你没有告诉ffmpeg使用什么输出格式。

尝试ffmpeg -f image2 -r 1/5 -i img%03d.png -vcodec libx264 -pix_fmt yuv420p out.mp4

还要记住图像的大小必须相同。如果不是,则需要将它们预处理到相同的大小。

祝你好运

相关问题