[FFmpeg-devel] [PATCH] Extract rotation in MOV metadata

Baptiste Coudurier baptiste.coudurier at gmail.com
Wed Mar 30 17:18:52 CEST 2011


Hi Dave,

On 03/26/2011 03:31 AM, Dave Badia wrote:
> Interrogate MOV metadata for orientation of video so that software can
> determine if the video needs to be rotated for proper display.
> ---
>  libavformat/isom.h |    1 +
>  libavformat/mov.c  |    5 +++++
>  2 files changed, 6 insertions(+), 0 deletions(-)
> 
> diff --git a/libavformat/isom.h b/libavformat/isom.h
> index 1df666f..dde1ba1 100644
> --- a/libavformat/isom.h
> +++ b/libavformat/isom.h
> @@ -123,6 +123,7 @@ typedef struct MOVStreamContext {
>      int width;            ///< tkhd width
>      int height;           ///< tkhd height
>      int dts_shift;        ///< dts shift when ctts is negative
> +    int rotation;         ///< rotation 0 if normal, 180 if inverted
>  } MOVStreamContext;
> 
>  typedef struct MOVContext {
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index e9435a9..7faa225 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -1907,6 +1907,11 @@ static int mov_read_tkhd(MOVContext *c,
> AVIOContext *pb, MOVAtom atom)
>      sc->width = width >> 16;
>      sc->height = height >> 16;
> 
> +    if(display_matrix[0][0] == -65536 && display_matrix[1][1] == -65536) {
> +       sc->rotation = 180;
> +    }
> +
> +
>      // transform the display width/height according to the matrix
>      // skip this if the display matrix is the default identity matrix
>      // or if it is rotating the picture, ex iPhone 3GS

I'm not against this. You can export this information as metadata I
think: use av_metadata_set with "rotate" on the AVStream, that way
applications can retrieve it through the API.

-- 
Baptiste COUDURIER
Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
FFmpeg maintainer                                  http://www.ffmpeg.org


More information about the ffmpeg-devel mailing list