Zexian Li

ffmpeg库简例

2019-06-09 · 2 min read
Python

毕设需要对图片和视频进行格式转换与部分处理,将过程中用到的ffmpeg库部分整理如下:

以特定间隔保存视频中的图像

以下命令行为例进行参数的讲解(在终端执行):

ffmpeg -y -i "1.mp4" -r 1 -q:v 2 -ss 00:00:26 -t 00:00:02 -s 1920*1080 -f image2 %d.jpg image_path

  • -y 对输出文件进行覆盖
  • -i 输入
  • -r 帧率(1秒内截取的图片数)
  • -q:v 2 提升图像质量
  • -ss 开始时间
  • -t 持续时长
  • -s 保存图像的分辨率
  • -f --> use the designative format.
  • image_path 保存路径

Function2: change the foramt of videos / images.

video format change

ffmpeg -i input.flv output.mp4

input.flv --> the name and the format of the input. Note don't use the absolute path of the file, just use the file name.
output.mp4 --> the output video's name and format.

Function3: Compose images into a video.

1.Put all images in a folder and make a naming rule which can be regularized.

2.Compose the images.

With Audio.

ffmpeg -threads2 -y -r 10 -i /tmpdir/image%04d.jpg -i audio.mp3 -absf aac_adtstoasc output.mp4

-threads 2 --> run 2 processes at the same time.
-y --> overwrite the output file.
-r 10 --> set the fps. '10' means 10 images showed 1 second in the video.

Without Audio.

ffmpeg -loop 1 -f image2 -i /tmpdir/image%04d.jpg -vcodec libx264 -r 10 -t 10 test.mp4

Wait further :https://blog.csdn.net/wangshuainan/article/details/77914508

Bad decisions make good stories.