How to ignore auto rotation when reading videos with ffmpeg python?

Viewed 123

When reading a video with ffmpeg-python, if the video metadata contains a "rotate" attribute, it seems that by default ffmpeg transposes the incoming bytes according to the rotation value.

I would like to remove the automatic rotation. I tried the following, with no success:

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)
)

The code runs without any issue, but the rotation is not ignored, as I would have expected.

According to this:https://gist.github.com/vxhviet/5faf792f9440e0511547d20d17208a76, the noautorotate argument should be passed before input.

I tried the following:

process = (
        ffmpeg
        .global_args('-noautorotate')
        .input(filename)
        .output('pipe:', format='rawvideo', pix_fmt='yuv420p', loglevel=0, vsync='0')
        .run_async(pipe_stdout=True)
)

also with no success:

AttributeError: module 'ffmpeg' has no attribute 'global_args'

Any suggestion?

EDIT

Passing noautorotate as kwargs does not work either (size of video after reading is 0)

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

Replace **{'noautorotate':''} with **{'noautorotate':None}.

Correct syntax:

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

When using **{'noautorotate':''}, FFmpeg output an error:

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


For testing we may add .global_args('-report'), and look at the log file.

Executing the following command:

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


Executing the following command:

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

There is just an extra space before the -i, but for some reason FFmpeg interpret it as a URL (I think it might be a Unicode related issue - the empty strings is interpret as character that is not a space).

Related