I have to convert a.mp4 video file to.yuv (YUV420) and vice versa in my python program. How do you do this using FFmpeg and subprocess module in python?
Try this:
from subprocess import Popen
# create command to use ffmpeg to convert mp4 to yuv
cmd = ['ffmpeg', '-i', 'video.mp4','video.yuv']
# execute command in "shell"
process = Popen(cmd, shell=True)
Explaination in code comment.
Make sure FFMPEG is added to your system PATH or else call by its path ie
from subprocess import Popen
# create command to use ffmpeg to convert mp4 to yuv
cmd = ['C:/ffmpeg/bin/ffmpeg', '-i', 'video.mp4','video.yuv']
# execute command in "shell"
process = Popen(cmd, shell=True)
As @llogan mentioned to convert from yuv to mp4 use:
cmd = ['ffmpeg', '-video_size', '1280x720', '-pixel_format', 'yuv420p', '-framerate', '25', '-i', 'video.yuv', 'output.mp4']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.