Skip to content

Commit

Permalink
Add support for rotation metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand Nouvel authored and ddennedy committed Sep 24, 2015
1 parent 6760862 commit bce7962
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/modules/avformat/producer_avformat.c
Expand Up @@ -272,6 +272,31 @@ static int first_video_index( producer_avformat self )
return i;
}

#if (LIBAVFORMAT_VERSION_INT >= ((55<<16)+(39<<8)+100))
#include <libavutil/display.h>

static double get_rotation(AVStream *st)
{
AVDictionaryEntry *rotate_tag = av_dict_get( st->metadata, "rotate", NULL, 0 );
uint8_t* displaymatrix = av_stream_get_side_data( st, AV_PKT_DATA_DISPLAYMATRIX, NULL);
double theta = 0;

if ( rotate_tag && *rotate_tag->value && strcmp( rotate_tag->value, "0" ) )
{
char *tail;
theta = strtod( rotate_tag->value, &tail );
if ( *tail )
theta = 0;
}
if ( displaymatrix && !theta )
theta = -av_display_rotation_get( (int32_t*) displaymatrix );

theta -= 360 * floor( theta/360 + 0.9/360 );

return theta;
}
#endif

/** Find the default streams.
*/

Expand Down Expand Up @@ -324,6 +349,10 @@ static mlt_properties find_default_streams( producer_avformat self )
mlt_properties_set_int( meta_media, key, codec_context->width );
snprintf( key, sizeof(key), "meta.media.%d.codec.height", i );
mlt_properties_set_int( meta_media, key, codec_context->height );
#if (LIBAVFORMAT_VERSION_INT >= ((55<<16)+(39<<8)+100))
snprintf( key, sizeof(key), "meta.media.%d.codec.rotate", i );
mlt_properties_set_int( meta_media, key, get_rotation(context->streams[i]) );
#endif
snprintf( key, sizeof(key), "meta.media.%d.codec.frame_rate", i );
AVRational frame_rate = { codec_context->time_base.den, codec_context->time_base.num * codec_context->ticks_per_frame };
mlt_properties_set_double( meta_media, key, av_q2d( frame_rate ) );
Expand Down

0 comments on commit bce7962

Please sign in to comment.