gpt4 book ai didi

python - 如何使用ffmpeg在python中合并音频和视频文件?

转载 作者:行者123 更新时间:2023-12-04 22:46:06 24 4
gpt4 key购买 nike

我正在尝试创建一个 python 脚本,它将音频和视频文件合并到一个(音频+视频)文件中。

我正在使用 ffmpeg 来实现此目的,但它无法正常工作,并且出现错误。运行此脚本时,这里是我的脚本。

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')>

这里是错误

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

最佳答案

这是在你的环境中 pip install ffmpeg-python 后的 python 代码:

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()

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()

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')

关于python - 如何使用ffmpeg在python中合并音频和视频文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63190083/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com