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



边栏推荐
- Idea format code idea set shortcut key format code
- MongoDB复制集【主从复制】
- labelimg生成的xml文件转换为voc格式
- 为什么线程崩溃不会导致 JVM 崩溃
- Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)
- The file marked by labelme is converted to yolov5 format
- Model transformation onnx2engine
- com. fasterxml. jackson. databind. Exc.invalidformatexception problem
- Idea set method call ignore case
- 【AI实战】应用xgboost.XGBRegressor搭建空气质量预测模型(一)
猜你喜欢

Do you really understand relays?
![Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence](/img/60/bae0e8d92a53bcd2b2de3fb22b3b99.jpg)
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
![MySQL Real combat 45 [SQL query and Update Execution Process]](/img/cd/3a635f0c3bb4ac3c8241cb77285cc8.png)
MySQL Real combat 45 [SQL query and Update Execution Process]
![[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

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

Why does thread crash not cause JVM crash

The series of hyperbolic function in daily problem

Pytoch configuration

Lvgl usage experience

900w+ data, from 17s to 300ms, how to operate
随机推荐
Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training
umi 路由拦截(简单粗暴)
文件重命名
com. fasterxml. jackson. databind. Exc.invalidformatexception problem
Yolov5 project based on QT
MySql实战45讲【SQL查询和更新执行流程】
docker安装redis
Force deduction ----- the minimum path cost in the grid
The base value is too large (the error is marked as "08") [duplicate] - value too great for base (error token is'08') [duplicate]
900W+ 数据,从 17s 到 300ms,如何操作
敏捷认证(Professional Scrum Master)模拟练习题-2
File rename
Don't use the new Dede collection without the updated Dede plug-in
Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0
Limit of one question per day
从输入URL到页面展示这中间发生了什么?
[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
Pytorch轻量级可视化工具wandb(local)
VS克隆时显示403错误
用Three.js做一个简单的3D场景
