使用ffmpeg-python读取视频时,如果视频元数据包含"rotate"属性,则默认情况下ffmpeg会根据旋转值转置传入的字节.

我想取消自动旋转.我try 了以下方法,但没有成功:

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参数应该在输入之前传递.

我try 了以下方法:

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'),并查看日志(log)文件.

执行以下命令:

process = (
    ffmpeg
    .input('input.mkv', **{'noautorotate':None})
    .output('pipe:', format='rawvideo', pix_fmt='yuv420p', vsync='0')
    .global_args('-report')
    .run_async()
    .wait()
)

The log file shows the built FFmpeg command line - looks correct:
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()
)

The log file shows the following built FFmpeg command line:
ffmpeg -noautorotate -i input.mkv -f rawvideo -pix_fmt yuv420p -vsync 0 pipe: -report

-i之前只有一个额外的空格,但出于某种原因,FFmpeg将其解释为URL(我认为这可能是一个与Unicode相关的问题-空字符串被解释为不是空格的字符).

Python相关问答推荐

大Pandas 胚胎中产生组合

如何将ctyles.POINTER(ctyles.c_float)转换为int?

将输入管道传输到正在运行的Python脚本中

当从Docker的--env-file参数读取Python中的环境变量时,每个\n都会添加一个\'.如何没有额外的?

关于Python异步编程的问题和使用await/await def关键字

Python+线程\TrocessPoolExecutor

在pandas中使用group_by,但有条件

mypy无法推断类型参数.List和Iterable的区别

通过ManyToMany字段与Through在Django Admin中过滤

旋转多边形而不改变内部空间关系

下三角形掩码与seaborn clustermap bug

手动设置seborn/matplotlib散点图连续变量图例中显示的值

如何在GEKKO中使用复共轭物

freq = inject在pandas中做了什么?''它与freq = D有什么不同?''

如何在一组行中找到循环?

需要帮助使用Python中的Google的People API更新联系人的多个字段'

当HTTP 201响应包含 Big Data 的POST请求时,应该是什么?  

遍历列表列表,然后创建数据帧

奇怪的Base64 Python解码

对包含JSON列的DataFrame进行分组