python - ffmpeg-python:测试视频剪辑是否有音频

标签 python ffmpeg ffmpeg-python

我正在使用 ffmpeg-python 进行一些视频转换。

如果我有以下内容:

infiles = []
infile = ffmpeg.input("/tmp/xxx.mp4")
infiles.append(
    infile['v']
    .filter('scale', size='1920x1080', force_original_aspect_ratio='decrease')
    .filter('pad', '1920', '1080', '(ow-iw)/2', '(oh-ih)/2')
)
infiles.append(infile['a'])

(
    ffmpeg
    .concat(
        *infiles, v=1, a=1, unsafe=True)
    .output(out_tmp_file)
    .run()
)

当我运行它时,出现以下错误:

Stream specifier ':a' in filtergraph description [0:v]scale=force_original_aspect_ratio=decrease:size=1920x1080[s0];[s0]pad=1920:1080:(ow-iw)/2:(oh-ih)/2[s1];[s1][0:a]concat=a=1:n=1:unsafe=True:v=1[s2] matches no streams.

如果视频有音频,以上方法有效

最佳答案

您可以使用 ffmpeg.probe 测试音频流是否存在

示例:

import ffmpeg

# Run ffprobe on the specified file and return a JSON representation of the output.
# https://kkroening.github.io/ffmpeg-python/
# Use select_streams='a' for getting only audio streams information
p = ffmpeg.probe('in.mp4', select_streams='a');

# If p['streams'] is not empty, clip has an audio stream
if p['streams']:
    print('Video clip has audio!')

关于python - ffmpeg-python:测试视频剪辑是否有音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59829293/

相关文章:

cocoa-touch - iOS 上的音频转码

filter - 尝试使用 2 个叠加层创建视频

python ffmpeg : overlaying videos is dropping all audio

python-3.x - ffmpeg-python 从 x11grab 获取输入

python - 无法在 matplotlib 中保存动画 : Windows permission denied

python - 如何将 FFmpeg 命令行转换为 ffmpeg-python 代码?

python - 我怎样才能在pygame中进行二段跳?

python - 将字符串/列表转换为数据框

python - 更改新 URL 的 Selenium 驱动程序

php - 网络广播流代理