gerlv.blogg.se

Ffmpeg python merge audio and video
Ffmpeg python merge audio and video










Concatenation of files with same codecs.This gets split correctly by shlex.split(), but not by str.split(). For example: cmd = 'ffmpeg -i "C:\My long folder name with spaces\temp_vid.mp4"'

ffmpeg python merge audio and video

The reason this is safer is because the arguments can also contain spaces and str.split() won't account for that. P = subprocess.Popen(shlex.split(cmd), stdin=subprocess.PIPE, creationflags=subprocess.CREATE_NO_WINDOW) So: cmd = 'ffmpeg -i temp_vid.mp4 -i temp_voice.wav -c:v copy -c:a aac -strict experimental -strftime 1 ' + dt_file_name Thanks to for pointing out that a safer way to split a command would be to use shlex.split(). That's assuming those options are correct, of course. P = subprocess.Popen(cmd.split(), stdin=subprocess.PIPE, creationflags=subprocess.CREATE_NO_WINDOW) Instead, try this: cmd = 'ffmpeg -i temp_vid.mp4 -i temp_voice.wav -c:v copy -c:a aac -strict experimental -strftime 1 ' + dt_file_name You have this line: p =subprocess.Popen('ffmpeg -i temp_vid.mp4 -i temp_voice.wav -c:v copy -c:a aac -strict experimental -strftime 1 ' + dt_file_name ,stdin=subprocess.PIPE,creationflags = subprocess.CREATE_NO_WINDOW) It looks like in your particular case you can use command_line.split() as suggested, but I'd say it's error prone approach. P = subprocess.Popen(shlex.split(command_line). So the correct call to Popen should look like: command_line = 'ffmpeg -i temp_vid.mp4 -i temp_voice.wav -c:v copy -c:a aac -strict experimental -strftime 1 ' + dt_file_name Note in particular that options (such as -input) and arguments (such as eggs.txt) that are separated by whitespace in the shell go in separate list elements, while arguments that need quoting or backslash escaping when used in the shell (such as filenames containing spaces or the echo command shown above) are single list elements. bin/vikings -input eggs.txt -output "spam spam.txt" -cmd "echo '$MONEY'" shlex.split() can illustrate how to determine the correct tokenization for args: > import shlex, subprocess Note It may not be obvious how to break a shell command into a sequence of arguments, especially in complex cases.

ffmpeg python merge audio and video

However, this can only be done if not passing arguments to the program. On POSIX, if args is a string, the string is interpreted as the name or path of the program to execute. An example of passing some arguments to an external program as a sequence is: Popen()












Ffmpeg python merge audio and video