当前位置:网站首页>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视频文件,
边栏推荐
- Basic information of Promethus (I)
- com. fasterxml. jackson. databind. Exc.invalidformatexception problem
- I2C subsystem (I): I2C spec
- 45 lectures on MySQL [index]
- Idea format code idea set shortcut key format code
- MySql实战45讲【全局锁和表锁】
- Don't use the new Dede collection without the updated Dede plug-in
- labelimg生成的xml文件转换为voc格式
- Pytorch配置
- New programmers use the isXXX form to define Boolean types in the morning, and are discouraged in the afternoon?
猜你喜欢
45 lectures on MySQL [index]
900W+ 数据,从 17s 到 300ms,如何操作
Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
渤、黄海的潮汐特征
Pytoch lightweight visualization tool wandb (local)
Hi3536C V100R001C02SPC040 交叉编译器安装
【PyG】理解MessagePassing过程,GCN demo详解
TCP handshake three times and wave four times. Why does TCP need handshake three times and wave four times? TCP connection establishes a failure processing mechanism
Vs 2019 configuration du moteur de génération de tensorrt
Docker install redis
随机推荐
PAT乙级“1104 天长地久”DFS优化思路
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
The file marked by labelme is converted to yolov5 format
MySQL practice 45 lecture [transaction isolation]
文件重命名
45 lectures on MySQL [index]
MySQL practice 45 [SQL query and update execution process]
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions
Use three JS make a simple 3D scene
为什么线程崩溃不会导致 JVM 崩溃
从输入URL到页面展示这中间发生了什么?
Limit of one question per day
Avec trois. JS fait une scène 3D simple
Find the storage address of the elements in the two-dimensional array
后管中编辑与预览获取表单的值写法
Idea set method call ignore case
【AI实战】应用xgboost.XGBRegressor搭建空气质量预测模型(一)
Convert binary stream to byte array
Why does thread crash not cause JVM crash
Unity3d RPG implementation (medium)