qix
qix

Reputation: 7952

Rotate a video based on the rotate metadata with ffmpeg?

I know I can transpose the video with the transpose video filter if I know how the video is rotated in advance, and update the metadata using something like this -metadata:s:v:0 rotate=0, but how can I use the correct transpose value dependent on the metadata rotate bit in the video? Basically I want to bake the rotate information into the video data itself, and clear the rotate metadata.

Is it possible to do this with ffmpeg alone, or must I write some sort of script to extract the rotation value, and call ffmpeg with the appropriate options? If the latter, does anyone have a working script already? :) I see this as one guy's approach using exiftool and rails; is it possible to do it without?

Upvotes: 3

Views: 2031

Answers (1)

max
max

Reputation: 31

the rotation info belong to "video stream",not the video file(which also has audio stream).so you need to look at AVStream.metadata.

AVFormatContext *inputFormatCtx = ...;
for(int i=0; i<inputFormatCtx->nb_streams; i++) {
        if(inputFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) {

            AVDictionary* metadata = (AVDictionary*)inputFormatCtx->streams[i]->metadata;

            for(int i =0;i<metadata->count;i++)
            {
                AVDictionaryEntry entity = (AVDictionaryEntry)(metadata->elems[i]);
                LOGD("metadata %s %s",entity.key,entity.value);
            }

            break;
        }
}

Upvotes: 3

Related Questions