ffmpeg基本功能使用

任务描述:由给定图像序列合成 24fps 视频

方案一

直接对图像进行操作,适用于图像名比较规范且默认即为所需顺序

ffmpeg -f image2 -i ./images_crop_%d.png -pix_fmt yuv420p -vcodec libx264 -r 24 -y output.mp4

方案二

将图像顺序写入一个文件列表,让ffmpeg从列表读入并合成视频,适用于自定义图像顺序

ffmpeg -f concat -safe 0 -i input.txt -pix_fmt yuv420p -vcodec libx264 -r 24 -y -an output.mp4

其中列表格式如下

file '/Users/cv/playground/data/cam_1_frame_00.png'
duration 0.5
file '/Users/cv/playground/data/cam_2_frame_01.png'
duration 0.5
……
input.txt

file 设置当前帧图像路径,使用绝对路径防止出错。

duration 设置当前帧与下一帧的时间间隔,单位是秒(s)。

可能出现的错误

如果图像的宽或高不是偶数,在转换过程中会出现下面的问题

[libx264 @ 0x7fec87003c00] height not divisible by 2 (2000x1125)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
Error Occur

解决方案

在转换过程中对宽和高重新调整

ffmpeg -f concat -safe 0 -i input.txt -pix_fmt yuv420p -vcodec libx264 -r 24 -y -an -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" output.mp4

任务描述:将视频拆分成图像序列

直接输入需要分解的视频名,并指定输出图像的格式即可

ffmpeg -i video.mpg image%d.jpg
ffmpeg -i scene2frame1.mov frame%d.png

其它常用功能

1. 获取视频格式信息

ffmpeg -i video.avi

2. 截取一张尺寸为352x240、格式为 jpg 的图片

ffmpeg -i test.asf -y -f image2 -t 0.001 -s 352x240 a.jpg

3. 把视频的前30帧转换成一个Animated Gif

ffmpeg -i test.asf -vframes 30 -y -f gif a.gif

4. 在视频的第 8.01 秒处截取 352*240 的缩略图

ffmpeg -i test2.asf -y -f image2 -ss 08.010 -t 0.001 -s 352x240 b.jpg

5. 合并视频和音频

ffmpeg -r 0.5 -i tmpImg/image%04d.jpg -i time.mp3 -vcodec mpeg4 video5.avi 

猜你喜欢

转载自www.cnblogs.com/phillee/p/12244970.html
今日推荐