gpt4 book ai didi

python - 使用ffmpeg python阅读视频时如何忽略自动旋转?

转载 作者:行者123 更新时间:2023-12-04 22:48:57 39 4
gpt4 key购买 nike

使用 ffmpeg-python 读取视频时,如果视频元数据包含“旋转”属性,则默认情况下,ffmpeg 似乎会根据旋转值转置传入的字节。
我想删除自动旋转。我尝试了以下方法,但没有成功:

import ffmpeg

process = (
ffmpeg
.input(filename)
.output('pipe:', format='rawvideo', pix_fmt='yuv420p', loglevel=0, vsync='0')
.global_args('-noautorotate')
.run_async(pipe_stdout=True)
)
代码运行没有任何问题,但旋转没有被忽略,正如我所预料的那样。
据此: https://gist.github.com/vxhviet/5faf792f9440e0511547d20d17208a76 , noautorotate 参数应在输入之前传递。
我尝试了以下方法:
process = (
ffmpeg
.global_args('-noautorotate')
.input(filename)
.output('pipe:', format='rawvideo', pix_fmt='yuv420p', loglevel=0, vsync='0')
.run_async(pipe_stdout=True)
)
也没有成功:
AttributeError: module 'ffmpeg' has no attribute 'global_args'
有什么建议吗?
编辑
将 noautorotate 作为 kwargs 传递也不起作用(读取后的视频大小为 0)
    process = (
ffmpeg
.input(self.file, **{'noautorotate':''})
.output('pipe:', format='rawvideo', pix_fmt='yuv420p', loglevel=1, vsync='0')
.run_async(pipe_stdout=True)
)

最佳答案

替换 **{'noautorotate':''}**{'noautorotate':None} .
正确的语法:

process = (
ffmpeg
.input(self.file, **{'noautorotate':None})
.output('pipe:', format='rawvideo', pix_fmt='yuv420p', loglevel=1, vsync='0')
.run_async(pipe_stdout=True)
)

使用 **{'noautorotate':''} 时, FFmpeg 输出错误:

Option noautorotate (automatically insert correct rotate filters) cannot be applied to output url -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.
Error parsing options for output file .
Error opening output files: Invalid argument



为了测试,我们可以添加 .global_args('-report') ,并查看日志文件。
执行以下命令:
process = (
ffmpeg
.input('input.mkv', **{'noautorotate':None})
.output('pipe:', format='rawvideo', pix_fmt='yuv420p', vsync='0')
.global_args('-report')
.run_async()
.wait()
)
日志文件显示了构建的 FFmpeg 命令行 - 看起来正确: ffmpeg -noautorotate -i input.mkv -f rawvideo -pix_fmt yuv420p -vsync 0 pipe: -report
执行以下命令:
process = (
ffmpeg
.input('input.mkv', **{'noautorotate':''})
.output('pipe:', format='rawvideo', pix_fmt='yuv420p', vsync='0')
.global_args('-report')
.run_async()
.wait()
)
日志文件显示以下构建的 FFmpeg 命令行: ffmpeg -noautorotate -i input.mkv -f rawvideo -pix_fmt yuv420p -vsync 0 pipe: -report -i 之前只有一个额外的空格,但由于某种原因,FFmpeg 将其解释为 URL(我认为这可能是与 Unicode 相关的问题 - 空字符串被解释为不是空格的字符)。

关于python - 使用ffmpeg python阅读视频时如何忽略自动旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72284068/

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