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



边栏推荐
- MySql實戰45講【SQL查詢和更新執行流程】
- @Accessors注解作用指定前缀遵守驼峰命名
- Find the storage address of the elements in the two-dimensional array
- Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
- 模糊查詢時報錯Parameter index out of range (1 > number of parameters, which is 0)
- 复选框的使用:全选,全不选,选一部分
- Left connection, inner connection
- Lvgl usage experience
- Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)
- Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
猜你喜欢

Elsevier latex submitted the article pdftex def Error: File `thumbnails/cas-email. jpeg‘ not found: using draf

Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf

On the adjacency matrix and adjacency table of graph storage

VS 2019配置tensorRT

Docker install MySQL

Docker install redis

Agile certification (professional scrum Master) simulation exercise-2

MongoDB简介

Idea set method call ignore case

Vs 2019 configuration du moteur de génération de tensorrt
随机推荐
Docker install redis
VS克隆时显示403错误
Pytorch轻量级可视化工具wandb(local)
QT based tensorrt accelerated yolov5
Solve high and send system Currenttimemillis Caton
The difference between componentscan and componentscans
el-tree搜索方法使用
Limit of one question per day
Left connection, inner connection
敏捷认证(Professional Scrum Master)模拟练习题-2
Vs 2019 configuration tensorrt
Agile certification (professional scrum Master) simulation exercise-2
Bigvision code
New programmers use the isXXX form to define Boolean types in the morning, and are discouraged in the afternoon?
Vs 2019 configuration du moteur de génération de tensorrt
渤、黄海的潮汐特征
Limit of one question per day
Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0
Distributed transaction
二维数组中的元素求其存储地址
