I am trying to create a python script which merge the audio and video file in one (audio+video) file.
And i am using ffmpeg to achieve this but it is not working and i am getting a errors. while running this script here is my script.
import os
import subprocess
import time
from datetime import datetime
def merge_all():
global p
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)
time.sleep(2)
print('merging done')
os.remove('temp_vid.mp4')
os.remove('temp_voice.wav')
print('file delete done')>
here is the error
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\kp\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:\Users\kp\Desktop\test.py", line 179, in change_icon
merge_all()
File "C:\Users\kp\Desktop\test.py", line 104, in merge_all
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)
File "C:\Users\kp\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\kp\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
Here is the python code after you have pip install ffmpeg-python in your environment:
import ffmpeg
input_video = ffmpeg.input('./test_Directory/test.webm')
input_audio = ffmpeg.input('./test_Directory/test.webm')
ffmpeg.concat(input_video, input_audio, v=1, a=1).output('./test_Directory/complete.mp4').run()
OR
video = ffmpeg.input('video.mp4')
audio = ffmpeg.input('audio.wav')
out = ffmpeg.output(video, audio, video_path, vcodec='copy', acodec='aac', strict='experimental')
out.run()
OR
cmd = 'ffmpeg -y -i Audio.wav -r 30 -i Video.h264 -filter:a aresample=async=1 -c:a flac -c:v copy av.mkv'
subprocess.call(cmd, shell=True)
print('Mixing Done')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With