使用ffmpeg从图像文件制作视频

时间:2014-08-03 22:50:35

标签: image ubuntu ffmpeg video-processing

我有64个图像序列,我想用这些图像制作视频。

您可以下载图片here

我在ubuntu中使用ffmpeg。 这是我的命令

ffmpeg -r 60 -f image2 -s 1360x768 -i "/home/roylisto/Documents/Tugas Akhir/JAva version/UAVSystem/UAVSystem/tmp/result%d.png" -vcodec libx264 -crf 20 "/home/roylisto/Documents/Tugas Akhir/JAva version/UAVSystem/UAVSystem/render/test.mp4"

它有效,但视频只生成了39张图像。我的问题是为什么ffmpeg不会将该文件夹中的所有图像渲染成视频,我的错误是什么以及如何解决?

输出命令:

    ffmpeg version 2.2.git-73d820e Copyright (c) 2000-2014 the FFmpeg developers
  built on Jun 16 2014 10:08:12 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-x11grab --enable-libpulse --enable-libx264 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr
  libavutil      52. 89.100 / 52. 89.100
  libavcodec     55. 66.101 / 55. 66.101
  libavformat    55. 43.100 / 55. 43.100
  libavdevice    55. 13.101 / 55. 13.101
  libavfilter     4.  8.100 /  4.  8.100
  libavresample   1.  3.  0 /  1.  3.  0
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, image2, from '/home/roylisto/Documents/Tugas Akhir/JAva version/UAVSystem/UAVSystem/tmp/result%d.png':
  Duration: 00:00:00.62, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, rgb24, 320x240, 60 fps, 60 tbr, 60 tbn, 60 tbc
No pixel format specified, yuv444p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x2bccce0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.1 Cache64
[libx264 @ 0x2bccce0] profile High 4:4:4 Predictive, level 2.1, 4:4:4 8-bit
[libx264 @ 0x2bccce0] 264 - core 142 r2431 ac76440 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - 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=4 threads=3 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=20.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/home/roylisto/Documents/Tugas Akhir/JAva version/UAVSystem/UAVSystem/render/test.mp4':
  Metadata:
    encoder         : Lavf55.43.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv444p, 320x240, q=-1--1, 60 fps, 15360 tbn, 60 tbc
    Metadata:
      encoder         : Lavc55.66.101 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))
Press [q] to stop, [?] for help
Input stream #0:0 frame changed from size:320x240 fmt:rgb24 to size:480x360 fmt:rgb24
frame=   35 fps=0.0 q=-1.0 Lsize=      18kB time=00:00:00.55 bitrate= 264.7kbits/s dup=0 drop=2    
video:17kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 7.355630%
[libx264 @ 0x2bccce0] frame I:1     Avg QP:14.45  size:  1829
[libx264 @ 0x2bccce0] frame P:12    Avg QP:20.02  size:   908
[libx264 @ 0x2bccce0] frame B:22    Avg QP:24.15  size:   161
[libx264 @ 0x2bccce0] consecutive B-frames: 14.3%  5.7%  0.0% 80.0%
[libx264 @ 0x2bccce0] mb I  I16..4:  3.3% 84.3% 12.3%
[libx264 @ 0x2bccce0] mb P  I16..4:  0.6%  2.9%  1.9%  P16..4:  7.6%  6.0%  2.8%  0.0%  0.0%    skip:78.3%
[libx264 @ 0x2bccce0] mb B  I16..4:  0.0%  0.1%  0.0%  B16..8: 10.1%  3.2%  0.5%  direct: 0.3%  skip:85.8%  L0:36.3% L1:56.4% BI: 7.3%
[libx264 @ 0x2bccce0] 8x8 transform intra:72.3% inter:49.0%
[libx264 @ 0x2bccce0] coded y,u,v intra: 34.4% 16.0% 10.7% inter: 3.6% 0.5% 0.3%
[libx264 @ 0x2bccce0] i16 v,h,dc,p: 76% 21%  3%  0%
[libx264 @ 0x2bccce0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 22% 50%  2%  2%  1%  5%  2%  3%
[libx264 @ 0x2bccce0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu:  7% 30% 32%  2%  8%  3% 11%  3%  5%
[libx264 @ 0x2bccce0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x2bccce0] ref P L0: 64.9% 22.6%  9.7%  2.8%
[libx264 @ 0x2bccce0] ref B L0: 86.1% 12.2%  1.7%
[libx264 @ 0x2bccce0] ref B L1: 94.3%  5.7%
[libx264 @ 0x2bccce0] kb/s:223.06

1 个答案:

答案 0 :(得分:2)

在这看到差异?

$ gm identify tmp/result38.png
tmp/result38.png PNG 480x360+0+0 DirectClass 8-bit 77.3K 0.000u 0:01

$ gm identify tmp/result39.png
tmp/result39.png PNG 640x480+0+0 DirectClass 8-bit 78.3K 0.000u 0:01

ffmpeg要求您的图片具有完全相同的尺寸。

要解决问题,请安装imagemagick(或者imagemagick,我更喜欢这个问题)

并写:

# graphicsmagick
gm mogrify -size 480x360 tmp/*.png

# imagemagick
mogrify -size 480x360 tmp/*.png

无论如何,你的ffmpeg命令可能会更强大。 (事实上​​,你过早地调用了重新缩放。)这是我的ffmpeg推荐给你:

ffmpeg -threads 0 -loglevel error -y -ar 48000 -ac 2 -f s16le -i /dev/zero \
-r 25/1 -f image2 -i "tmp/result%2d.png" -start_number 1 \ 
-c:a libfdk_aac -c:v libx264 -vf "fps=fps=25,format=pix_fmts=yuv420p" \
-s 1360x768 -crf 20 -shortest -vframes 64 "tmp/test.mp4"

以下是细分:

您的h264文件中应该有一个音频轨道,因为否则某些设备(例如手臂)上的某些同步方法可能无法正常工作,并且您的播放速率将会被删除。

我不确定这是不是一个老习惯,但我总是把-r 25/1用于-f图像。也许这只是一个人必须做的事情,但不再需要......

你可能不应该以0的文件编号开头,我总是喜欢使用填充数字。 (%2d = 01,02,03,04,05,06,07,08,09,10 ...)Linux通常是正确的,但其他操作系统可能会破坏文件夹列表中的序列。如果你"可以"#34;重命名result0.png文件,你可以尝试添加" -start_number 0"旗帜

在-vf组中明确指定播放速度是个好主意。

如果你不将像素编码切换到yuv420p,那么大多数非linux系统都不会 播放文件。

" -shortest"当任何流已经到达终点时,flag将结束转码...

" -vframes 64" flag将正好编码64帧然后退出 - 除非它不能编码那么多帧然后它将永远挂起......(这实际上是我对你的问题的线索。)

最后,你过早地调用了redimensioning,因此视频没有缩放。 (-s 1360x768)

相关问题