当前位置:网站首页>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视频文件,



边栏推荐
- File rename
- [combinatorics] number of solutions of indefinite equations (number of combinations of multiple sets R | number of non negative integer solutions of indefinite equations | number of integer solutions
- LVGL使用心得
- 二进制流转换成字节数组
- MongoDB安装 & 部署
- Are there any recommended term life insurance products? I want to buy a term life insurance.
- Last update time of all sqlserver tables
- 监听对象中值变化及访问
- 从输入URL到页面展示这中间发生了什么?
- VS 2019配置tensorRT
猜你喜欢
![[shutter] monitor the transparency gradient of the scrolling action control component (remove the blank of the top status bar | frame layout component | transparency component | monitor the scrolling](/img/c3/b9a614001f80345a5c1cb3c68ab27c.jpg)
[shutter] monitor the transparency gradient of the scrolling action control component (remove the blank of the top status bar | frame layout component | transparency component | monitor the scrolling

用Three.js做一个简单的3D场景

Application of derivative in daily question

Idea set method call ignore case

Limit of one question per day

MySql实战45讲【行锁】

VS code配置虚拟环境

softmax的近似之NCE详解

el-tree搜索方法使用

Gavin teacher's perception of transformer live class - rasa project's actual banking financial BOT Intelligent Business Dialogue robot architecture, process and phenomenon decryption through rasa inte
随机推荐
Vs 2019 configure tensorrt to generate engine
Small guide for rapid formation of manipulator (VIII): kinematic modeling (standard DH method)
MySql实战45讲【索引】
模型转换onnx2engine
【PyG】理解MessagePassing过程,GCN demo详解
The idea setting code is in UTF-8 idea Properties configuration file Chinese garbled
Yolov5 project based on QT
二维数组中的元素求其存储地址
@Accessors annotation function specifies that the prefix follows the hump naming
Basic information of Promethus (I)
Creation and destruction of function stack frame
静态网页 和 动态网页的区别 & WEB1.0和WEB2.0的区别 & GET 和 POST 的区别
Elsevier latex submitted the article pdftex def Error: File `thumbnails/cas-email. jpeg‘ not found: using draf
Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0
MySql实战45讲【行锁】
[shutter] monitor the transparency gradient of the scrolling action control component (remove the blank of the top status bar | frame layout component | transparency component | monitor the scrolling
【AI实战】应用xgboost.XGBRegressor搭建空气质量预测模型(一)
渤、黄海的潮汐特征
3D drawing example
[Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)
