imageio / imageio-ffmpeg

FFMPEG wrapper for Python
BSD 2-Clause "Simplified" License
221 stars 50 forks source link

Video rotation metadata #38

Closed miguel-lorenzo closed 1 year ago

miguel-lorenzo commented 4 years ago

I am getting this warning when reading videos from mobile phones

imageio_ffmpeg - WARNING - The frame size for reading (480, 720) is different from the source frame size (720, 480).

This means I have to rotate frames either 90º or 270º.

ffmpeg -i provides such rotation info of videos, For example:

ffmpeg -i myrotatedMOV.mov
....

Duration: 00:00:14.31, start: 0.000000, bitrate: 778 kb/s
    Stream #0:0(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 480x360, 702 kb/s, 29.98 fps, 30 tbr, 600 tbn, 1200 tbc
    Metadata:
      rotate          : 180
      creation_time   : 2013-01-09 12:47:36
      handler_name    : Core Media Data Handler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, s16, 62 kb/s
    Metadata:
      creation_time   : 2013-01-09 12:47:36
      handler_name    : Core Media Data Handler

How can I get such information with imageio_ffmpeg? Tried _get_metadata() function but is not there

almarklein commented 4 years ago

Interesting. imageio-ffmpeg does not consider the rotation at all at the moment. We should probably read that metadata info and deal with it appropriately. I think that ideally it should just produce the images in the correct shape, so there should be no need for the user to see whether the video was stored rotated.

almarklein commented 4 years ago

How can I get such information with imageio_ffmpeg?

At the moment you can't.

almarklein commented 4 years ago

As a first step, it should be possible to add code here to add the rotation info to the metadata. That way users at least have a way to deal with it.

miguel-lorenzo commented 4 years ago

This code does it.

    # get the rotation
    reo_rotation = re.compile('rotate\s+:\s([0-9]+)')
    match = reo_rotation.search(text)
    rotation = 0
    if match is not None:
        rotation = match.groups()[0]
    meta["rotation"] = rotation

Check my PR please https://github.com/imageio/imageio-ffmpeg/pull/39

hmaarrfk commented 1 year ago

I think this can likely get closed.