python-3.x - 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!')
推荐阅读
- javascript - 如何更改 webpack 模块导出需要字符串?
- amazon-web-services - 如何使用 aws-cli 创建具有 AWS 托管策略的角色?
- apache-spark - 如何使用 Spark SQL Scala API(不是 SQL)检查 Hive 表是否为外部表
- flutter - 如何在没有包的情况下在 Flutter 中实现下拉列表?
- jquery - http_request_duration_seconds_sum / http_request_duration_seconds_count 显示 2 个图表
- cross-browser - Blob PDF 数据未在 IE 11 中呈现
- db2 - 获取 11424 行后,源限定符中的 Informatica SQL30081N 出现错误
- c# - Xamarin Android 模拟器显示黑屏
- c# - 验证文本字段的前 2 个字符,后跟 4 个 int
- ios - 如何在 Swift 中删除我的位置的注释?我只想要一个脉动的点