如何成功使用ffmpeg将图像转换为视频 [英] How to successfully use ffmpeg to convert images into videos

查看:1158
本文介绍了如何成功使用ffmpeg将图像转换为视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在尝试为每个图像制作5秒钟的视频,然后使用concat对其进行组合,但是这样做存在很多问题.

Currently I'm trying to make 5 second videos for each image and then combining them using concat, but I'm having a lot of issues doing this.

这是我的代码:

ffmpeg -loop 1 -i 000.jpg -t 5 000.mp4 ffmpeg -loop 1 -i 001.jpg -t 5 001.mp4 ffmpeg -f concat -i input.txt-编解码器复制output.mp4

ffmpeg -loop 1 -i 000.jpg -t 5 000.mp4 ffmpeg -loop 1 -i 001.jpg -t 5 001.mp4 ffmpeg -f concat -i inputs.txt -codec copy output.mp4

inputs.txt列出以下内容 档案'000.mp4' 文件"001.mp4"

inputs.txt lists the following file '000.mp4' file '001.mp4'

现在,当我尝试所有这些操作时,我将运行输出mp4文件,并且文件的第一部分工作正常,但是一旦它开始显示视频的001部分,它就会切换为灰屏.甚至在独立文件001.mp4中都没有.

Now when I try all of this, I run the output mp4 file and the first part of it works fine, but then once it starts displaying the 001 part of the video, it switches to a gray screen. It doesn't even do that in the stand-alone file 001.mp4.

关于正在发生的事情或我可以做些什么的任何建议?

Any suggestions on what's going on or what I could do fix this?

我也尝试了很多其他事情.就像将所有文件切换到png一样,这也带来了同样的问题.我还尝试过使用不同的输出文件类型,例如wmv,avi等.尽管我仍然很新,所以我不知道可以尝试什么.

I've tried so many other things too. Like switching all the files over to png instead, which gave the same issue. I also tried using different output file types like wmv, avi, etc. I'm still very new though so I don't know what else to try.

这是运行命令后在命令提示符中显示的内容.

This is what shows up in my command prompt after running the command.

C:\xampp\htdocs\images>ffmpeg -f concat -i inputs.txt -codec copy output.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
[concat @ 003b9660] Estimating duration from bitrate, this may be inaccurate
Input #0, concat, from 'inputs.txt':
  Duration: 00:00:00.01, start: 0.000000, bitrate: 28 kb/s
    Stream #0:0: Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444
p, 800x600 [SAR 1:1 DAR 4:3], 28 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc
Output #0, mp4, to 'output.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=2-31, 28 kb/s, 25 fps, 12800 tbn, 12800 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=  250 fps=0.0 q=-1.0 Lsize=      31kB time=00:00:09.88 bitrate=  26.1kbits
/s
video:28kB audio:0kB subtitle:0 global headers:0kB muxing overhead 13.534948%

C:\xampp\htdocs\images>

推荐答案

您的控制台输出显示您正在编写4:4:4 H.264输出,很少有播放器支持. (较新版本的FFmpeg对此发出警告.)在输出文件前添加-pix_fmt yuv420p以转换为广泛支持的4:2:0像素格式.您还可以包括-profile:v baseline,使其可以在更多的播放器上使用. (这些选项适用于编码,因此请不要在指定-codec copy的命令上使用它们.)您还可以尝试使用ffplay播放输出文件,这是少数支持4:4:4的播放器之一mp4文件中为H.264.

Your console output shows that you are writing 4:4:4 H.264 output, which very few players support. (Newer versions of FFmpeg warn about that.) Add -pix_fmt yuv420p before the output file to convert to the widely supported 4:2:0 pixel format. You could additionally include -profile:v baseline to make it work on even more players. (These options apply to encoding, so don't use them on the command that specifies -codec copy.) You could also try playing your output file with ffplay, which is one of the few players that support 4:4:4 H.264 in mp4 files.

如果您希望每个图像具有相同的持续时间并且已连续编号,则只需要一个命令,例如:

If you want the same duration for each image and they are consecutively numbered, you only need a single command such as:

ffmpeg -framerate 0.2 -i %3d.jpg -vf fps=10 -pix_fmt yuv420p output.mp4

-framerate 0.2将输入帧速率设置为每秒0.2帧(每5秒1帧).每帧%3d被3位数字000001等代替. -vf fps=10将通过复制输入帧将帧速率更改为每秒10帧;并非绝对必要,但可以降低帧速率,从而使查找更为顺畅并确保第一张和最后一张图像的完整持续时间,并且不应将输出大小增加太多,因为可以对与前一帧相同的帧进行编码小尺寸.

The -framerate 0.2 sets the input frame rate to 0.2 frames per second (1 frame every 5 seconds). %3d is replaced by 3 digits 000, 001, etc. for each frame. -vf fps=10 will change the frame rate to 10 frames per second, in this case by duplicating input frames; it is not strictly necessary but can be helpful with low frame rates to make seeking smoother and ensure the full duration for the first and last images, and should not increase the output size by much since frames that are identical to the previous frame can be encoded in a small size.

如果要继续使用concat多路分配器,或者希望为每个图像使用不同的文件名或持续时间,则可以直接为图像指定inputs.txt中每个图像的持续时间.无需为每个图像创建单独的电影文件.例如:

If you want to continue using the concat demuxer, or want different file names or durations for each image, you can specify the image directly with a duration for each one in your inputs.txt. There is no need to create a separate movie file for each image. For example:

file 000.jpg
duration 5
file 001.jpg
duration 5
...

然后使用concat多路分配器将它们连接起来并同时执行编码:

Then use the concat demuxer to concatenate them and perform the encoding at the same time:

ffmpeg -f concat -i inputs.txt -vf fps=10 -pix_fmt yuv420p output.mp4

如果这些都不起作用,请将FFmpeg升级到最新版本.

If any of these things don't work, upgrade your FFmpeg to the latest version.

这篇关于如何成功使用ffmpeg将图像转换为视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆