当前位置:网站首页>ffmpeg之 一张/多张图片合成视频
ffmpeg之 一张/多张图片合成视频
2022-07-03 03:23:00 【水w】
目录
ffmpeg 把一张图片合成视频,并且设置视频时长
(1)执行代码,
完整代码:
import subprocess
import os
# 把一张图片合成视频,设置视频时长
cmdLine = "ffmpeg -r 25 -loop 1 -i images/img1.png -pix_fmt yuv420p -vcodec libx264 -b:v 600k -r:v 25 -preset medium -crf 30 -s 720x576 -vframes 250 -r 25 -t 10 a.mp4"
subprocess.call(cmdLine, shell=True)
(2)运行结果:
ffmpeg与opencv结合之 多张图片合成视频
注意:需要注意的是参数的选取和图像大小
img_root:是jpg图片存放的路径
out_root:是avi视频的保存路径
string = img_root + 'img' + str(im_name) + '.jpg':是图片的存储路径。此处我的图片是在images文件夹下,
fps:是帧速率,会直接造成视频的帧数和时长不同
参数
(1)可以按照自己的需要来修改代码中的一些变量和参数,
(2)执行代码,
我的完整代码:
import cv2
from cv2 import VideoWriter, VideoWriter_fourcc, imread, resize
import os
from subprocess import call
img_root = 'images/'
out_root = 'pig.avi'
fps = 1
fourcc = VideoWriter_fourcc(*"MJPG") #支持jpg
videoWriter = cv2.VideoWriter(out_root, fourcc, fps, (640, 480))
im_names = os.listdir(img_root)
print(len(im_names))
for im_name in range(1, 4):
string = img_root + 'img' + str(im_name) + '.jpg'
print(string)
frame = cv2.imread(string)
frame = cv2.resize(frame, (640, 480))
videoWriter.write(frame)
videoWriter.release()
# 将输出的视频变为mp4格式或者压缩
dir = out_root.strip(".avi")
command = "ffmpeg -i %s.avi %s.mp4" % (dir, dir)
call(command.split())
(3)执行过程中,我们可以看到一共处理了3张图片,
等待代码运行完成,
(4) 执行结果:会生成两个视频文件,avi视频文件和mp4视频文件,
边栏推荐
- labelme标记的文件转换为yolov5格式
- umi 路由拦截(简单粗暴)
- Limit of one question per day
- MySQL practice 45 [global lock and table lock]
- Pytorch配置
- 【PyG】理解MessagePassing过程,GCN demo详解
- Find the storage address of the elements in the two-dimensional array
- Lvgl usage experience
- Stepping on pits and solutions when using inputfilter to limit EditText
- Idea format code idea set shortcut key format code
猜你喜欢
Small guide for rapid formation of manipulator (VIII): kinematic modeling (standard DH method)
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
PAT乙级“1104 天长地久”DFS优化思路
MySql实战45讲【索引】
MongoDB复制集【主从复制】
Lvgl usage experience
The calculation of stripe, kernel and padding in CNN
45 lectures on MySQL [index]
[Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)
MySql实战45讲【全局锁和表锁】
随机推荐
VS克隆时显示403错误
Pytorch轻量级可视化工具wandb(local)
Opengauss database development and debugging tool guide
@Accessors annotation function specifies that the prefix follows the hump naming
Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0
The calculation of stripe, kernel and padding in CNN
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 05 data input and output
[algebraic structure] group (definition of group | basic properties of group | proof method of group | commutative group)
The base value is too large (the error is marked as "08") [duplicate] - value too great for base (error token is'08') [duplicate]
BigVision代码
Small guide for rapid formation of manipulator (VIII): kinematic modeling (standard DH method)
MongoDB简介
复选框的使用:全选,全不选,选一部分
Elsevier latex submitted the article pdftex def Error: File `thumbnails/cas-email. jpeg‘ not found: using draf
Vs 2019 configuration du moteur de génération de tensorrt
idea 加载不了应用市场解决办法(亲测)
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
从输入URL到页面展示这中间发生了什么?
MySql实战45讲【全局锁和表锁】
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf