当前位置:网站首页>Ffmpeg one / more pictures synthetic video
Ffmpeg one / more pictures synthetic video
2022-07-03 03:28:00 【Water W】
Catalog
ffmpeg Synthesize a picture into a video , And set the video duration
ffmpeg And opencv Combined Multi picture composite video
ffmpeg Synthesize a picture into a video , And set the video duration
(1) Execute code ,
Complete code :
import subprocess
import os
# Synthesize a picture into a video , Set the video duration
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) Running results :

ffmpeg And opencv Combined Multi picture composite video
Be careful : Attention should be paid to the selection of parameters and image size
img_root: yes jpg The way to store the pictures
out_root: yes avi The path to save the video
string = img_root + 'img' + str(im_name) + '.jpg': Is the storage path of the picture . My picture here is in images Under the folder ,
fps: Is the frame rate , It will directly cause the frame number and duration of the video to be different
Parameters

(1) You can modify some variables and parameters in the code according to your own needs ,
(2) Execute code ,
My complete code :
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") # Support 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()
# Change the output video into mp4 Format or compress
dir = out_root.strip(".avi")
command = "ffmpeg -i %s.avi %s.mp4" % (dir, dir)
call(command.split())(3) In the process of execution , We can see that a total of 3 A picture ,

Wait for the code to run ,

(4) Execution results : Two video files will be generated ,avi Video files and mp4 Video file ,



边栏推荐
- MySQL practice 45 [SQL query and update execution process]
- Docker install and start MySQL service
- 900w+ data, from 17s to 300ms, how to operate
- PHP generates PDF tcpdf
- Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
- [Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)
- 基于Qt的yolov5工程
- @Accessors annotation function specifies that the prefix follows the hump naming
- Nanning water leakage detection: warmly congratulate Guangxi Zhongshui on winning the first famous brand in Guangxi
- float与0比较
猜你喜欢
随机推荐
使用InputFilter限制EditText时踩坑及解决方案
3D drawing example
Yolov5 project based on QT
Limit of one question per day
FileZilla Client下载安装
UMI route interception (simple and rough)
The file marked by labelme is converted to yolov5 format
@Accessors注解作用指定前缀遵守驼峰命名
The difference between static web pages and dynamic web pages & the difference between Web1.0 and Web2.0 & the difference between get and post
On the adjacency matrix and adjacency table of graph storage
基于QT的tensorRT加速的yolov5
LVGL使用心得
Unity3d RPG implementation (medium)
Bigvision code
Limit of one question per day
[combinatorics] Application of exponential generating function (multiple set arrangement problem | different balls in different boxes | derivation of exponential generating function of odd / even sequ
softmax的近似之NCE详解
二进制流转换成字节数组
机械臂速成小指南(八):运动学建模(标准DH法)
numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences







![MySQL practice 45 [SQL query and update execution process]](/img/cd/3a635f0c3bb4ac3c8241cb77285cc8.png)

