【问题标题】:make video from image file using ffmpeg [closed]使用ffmpeg从图像文件制作视频[关闭]
【发布时间】:2014-09-26 09:44:28
【问题描述】:

我有 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

【问题讨论】:

  • 请向我们展示完整的、未删减的命令行输出。
  • @slhck 好的,我把它放在上面

标签: image ubuntu ffmpeg video-processing


【解决方案1】:

看到这里的区别了吗?

$ 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(或 graphicsmagick,出于多种原因我更喜欢它)

然后写:

# 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 文件中应该有一个音轨,否则在各种设备(例如 arm)上的某些同步方法可能无法正常工作,并且您的播放速度会变差。

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

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

最好在 -vf 组中明确命名播放速度。

如果不将像素编码切换为yuv420p,那么大部分非linux系统不会 播放文件。

“-shortest”标志将在任何流到达其结尾时结束转码...

“-vframes 64”标志将精确编码 64 帧然后退出 - 除非它不能编码那么多帧然后它会永远挂起......(这实际上是我对你的问题的线索。)

最后,您调用重新调整尺寸的时间过早,因此视频未缩放。 (-s 1360x768)

【讨论】:

  • 哇,非常感谢您的回答和解释,我会尝试:D
猜你喜欢
  • 2018-08-13
  • 1970-01-01
  • 1970-01-01
  • 2019-01-01
  • 2016-04-26
  • 2014-07-05
  • 1970-01-01
  • 2013-08-19
  • 1970-01-01
相关资源
最近更新 更多