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



边栏推荐
- PAT乙级“1104 天长地久”DFS优化思路
- 程序员新人上午使用 isXxx 形式定义布尔类型,下午就被劝退?
- 使用InputFilter限制EditText时踩坑及解决方案
- Why does thread crash not cause JVM crash
- 模型转换onnx2engine
- VS 2019 配置tensorRT生成engine
- MongoDB简介
- Using jasmine to monitor constructors - spying on a constructor using Jasmine
- Agile certification (professional scrum Master) simulation exercises
- ffmpeg录制屏幕和截屏
猜你喜欢
随机推荐
MySQL practice 45 [global lock and table lock]
navicat 导出数据库的表结构
Limit of one question per day
Vs 2019 configuration tensorrt
FileZilla Client下载安装
Ansible introduction [unfinished (semi-finished products)]
小程序获取用户头像和昵称
Lvgl usage experience
Elsevier latex submitted the article pdftex def Error: File `thumbnails/cas-email. jpeg‘ not found: using draf
Node start server
Mysql Mac版下载安装教程
MySQL practice 45 lecture [row lock]
Captura下载安装及在Captura配置FFmpeg
Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
LVGL使用心得
PAT乙级“1104 天长地久”DFS优化思路
用Three.js做一个简单的3D场景
[mathematical logic] predicate logic (individual word | individual domain | predicate | full name quantifier | existence quantifier | predicate formula | exercise)
Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0










