gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 01:35:07 28 4
gpt4 key购买 nike

我正在使用 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/

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