使用python中的ffmpeg合并音频和视频
我正在尝试将两个文件(.mp3& mp4)合并到一个.mp4。
视频和音频位于与我的main..py的同一文件夹中,并且在这里没有损坏,
这似乎是创建的代码错误:
if (haveAudio):
infile1 = ffmpeg.input(title+"_video.mp4")
infile2 = ffmpeg.input(title+"_audio.mp3")
merged = ffmpeg.concat(infile1, infile2, v=1, a=1)
output = ffmpeg.output(merged[0], merged[1], title+".mp4")
我在最后一行中遇到了一个错误:
Traceback (most recent call last):
File "C:\Users\...\projectName\main.py", line 67, in <module>
output = ffmpeg.output(merged[0], merged[1], title+".mp4")
File "C:\Users\...\Python\Python39\lib\site-packages\ffmpeg\nodes.py", line 70, in __getitem__
raise TypeError("Expected string index (e.g. 'a'); got {!r}".format(index))
TypeError: Expected string index (e.g. 'a'); got 0
我的猜测是调用ffmpeg.output()时缺少一个参数,但基于文档似乎是正确的。
I am trying to merge two files (.mp3 & .mp4) to a single .mp4
The videos and audio are located in the same folder as my main.py, and aren't corrupted
Here is the code that seems to create the error:
if (haveAudio):
infile1 = ffmpeg.input(title+"_video.mp4")
infile2 = ffmpeg.input(title+"_audio.mp3")
merged = ffmpeg.concat(infile1, infile2, v=1, a=1)
output = ffmpeg.output(merged[0], merged[1], title+".mp4")
I am getting an error on the last line:
Traceback (most recent call last):
File "C:\Users\...\projectName\main.py", line 67, in <module>
output = ffmpeg.output(merged[0], merged[1], title+".mp4")
File "C:\Users\...\Python\Python39\lib\site-packages\ffmpeg\nodes.py", line 70, in __getitem__
raise TypeError("Expected string index (e.g. 'a'); got {!r}".format(index))
TypeError: Expected string index (e.g. 'a'); got 0
My guess would be that an argument is missing when calling ffmpeg.output() but based on the documentation it seems correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从本教程中学到了: https://github.com/github.com/jnyh/pytube/ blob/master/pytube_sample_code.ipynb
我使用了以下2种方法,它们都为我工作:
或
I learnt from this tutorial: https://github.com/JNYH/pytube/blob/master/pytube_sample_code.ipynb
I used below 2 ways and they both worked for me:
or