如何在ffmpeg-python中合并视频和音频文件 [英] How to combine The video and audio files in ffmpeg-python

查看:388
本文介绍了如何在ffmpeg-python中合并视频和音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将视频(无声音)及其单独的音频文件合并

I'm trying to combine a video(with no sound) and its separate audio file

我已经尝试过ffmpeg ffmpeg -i video.mp4 -i audio.mp4 -c复制output.mp4 而且效果很好.

I've tried ffmpeg ffmpeg -i video.mp4 -i audio.mp4 -c copy output.mp4 and it works fine.

我正在尝试从ffmpeg-python实现相同的输出,但是没有运气.有关如何执行此操作的任何帮助?

i'm trying to achieve the same output from ffmpeg-python but with no luck. Any help on how to do this?

推荐答案

我遇到了同样的问题.

在您的环境中 pip安装ffmpeg-python 后,这是python代码:

Here is the python code after you have pip install ffmpeg-python in your environment:

import ffmpeg

input_video = ffmpeg.input('./test/test_video.webm')

input_audio = ffmpeg.input('./test/test_audio.webm')

ffmpeg.concat(input_video, input_audio, v=1, a=1).output('./processed_folder/finished_video.mp4').run()

v = 1 :设置输出视频流的数量,即每个段中的视频流的数量.默认值为1.

v=1: Set the number of output video streams, that is also the number of video streams in each segment. Default is 1.

a = 1 :设置输出音频流的数量,也就是每个段中的音频流的数量.默认值为0.

a=1: Set the number of output audio streams, that is also the number of audio streams in each segment. Default is 0.

有关 ffmpeg.concat 的详细信息,请查看: https://ffmpeg.org/ffmpeg-filters.html#concat .

For the details of ffmpeg.concat, check out: https://ffmpeg.org/ffmpeg-filters.html#concat.

您可以在此处查看更多示例: https://github.com/kkroening/ffmpeg-python/issues/281

You can check out more examples here: https://github.com/kkroening/ffmpeg-python/issues/281

希望这会有所帮助!

PS.如果您使用的是MacOS,但出现错误: FileNotFoundError:[错误2]没有这样的文件或目录:'ffmpeg'在运行代码时,只需在终端中 brew install ffmpeg .

PS. If you are using MacOS and have the error: FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg' while running the code, just brew install ffmpeg in your terminal.

这篇关于如何在ffmpeg-python中合并视频和音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆