0

I have a video that shows fine in media player, but when uploaded on youtube it shows rotated.

Metadata shown in ffmpeg -i thefile.mp4 shows a rotation of 270 degrees.

I read here

Strip metadata from all formats with FFmpeg

That

this command,

ffmpeg -i in.mov -map_metadata -1 -c:v copy -c:a copy out.mov

would get rid of the metadata.

But for me it doesn't.

Here's my file

C:\blah>dir first.mp4 
...
21/12/2019  21:51        21,487,116 first.mp4

Notice ffmpeg -i shows the rotate in this file that I am starting with, first.mp4

C:\Users\User\aa\sdf>ffmpeg -i first.mp4
ffmpeg version N-94664-g0821bc4eee Copyright (c) 2000-2019 the FFmpeg developers
....
libpostproc    55.  6.100 / 55.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'first.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.31.104
  Duration: 00:00:10.03, start: 0.000000, bitrate: 17138 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/smpte170m), 1920x1080, 17003 kb/s, SAR 1:1 DAR 16:9, 28.61
30 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      rotate          : 270
      handler_name    : VideoHandle
    Side data:
      displaymatrix: rotation of 90.00 degrees
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandle
At least one output file must be specified

--

And mediainfo shows the rotation in the file i'm starting with, first.mp4

C:\Users\User\aa\sdf>mediainfo first.mp4
General
Complete name                            : first.mp4
...

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
....
Rotation                                 : 270°
Frame rate mode                          : Variable
...

Audio
ID                                       : 2
Format                                   : AAC LC
....

--

Now I apply the command in that solution I linked to, but notice it doesn't work for me

C:\Users\User\aa\sdf>ffmpeg -i first.mp4 -map_metadata -1 -c:v copy -c:a copy zzz.mp4
ffmpeg version N-94664-g0821bc4eee Copyright (c) 2000-2019 the FFmpeg developers
....
  libpostproc    55.  6.100 / 55.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'first.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.31.104
  Duration: 00:00:10.03, start: 0.000000, bitrate: 17138 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/smpte170m), 1920x1080, 17003 kb/s, SAR 1:1 DAR 16:9, 28.61
30 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      rotate          : 270
      handler_name    : VideoHandle
    Side data:
      displaymatrix: rotation of 90.00 degrees
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandle
Output #0, mp4, to 'zzz.mp4':
  Metadata:
    encoder         : Lavf58.31.104
    Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 17003 kb/s, 28
ps, 30 tbr, 90k tbn, 90k tbc (default)
    Side data:
      displaymatrix: rotation of 90.00 degrees
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=  287 fps=0.0 q=-1.0 Lsize=   20984kB time=00:00:09.99 bitrate=17192.4kbits/s speed= 323x
video:20818kB audio:156kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.044614%

see the rotate data is still there

C:\Users\User\aa\sdf>ffmpeg -i zzz.mp4
ffmpeg version N-94664-g0821bc4eee Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.1.1 (GCC) 20190807
...
  libpostproc    55.  6.100 / 55.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'zzz.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.31.104
  Duration: 00:00:10.03, start: 0.000000, bitrate: 17138 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/smpte170m), 1920x1080, 17003 kb/s, SAR 1:1 DAR 16:9, 28.61
30 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      rotate          : 270
      handler_name    : VideoHandler
    Side data:
      displaymatrix: rotation of 90.00 degrees
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
At least one output file must be specified

--

C:\Users\User\aa\sdf>mediainfo zzz.mp4
General
Complete name                            : zzz.mp4
Format                                   : MPEG-4
...

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Rotation                                 : 270°
...

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
...

C:\Users\User\aa\sdf>
0

I see two solutions that seem to work

This command is relatively quick.. it writes the metadata to be rotate=0.. The -c copy is important. To write the metadata one doesn't need to re-encode, one can just copy the codecs. If you don't do -c copy(which copies the video and audio codecs), then it will be slow and re-encode and it will also use some default encodings which aren't so good. So there are two big advantages there to doing -c copy. You wouldn't want to not do -c copy. when doing that command. The metadata is what a video player can read and it tells it to rotate the video or not or how much to rotate it.

ffmpeg -i first.mp4 -metadata:s:v rotate="0" -c copy tttt.mp4

Another solution is this command.. with -vf "transpose=....", in my case i've used =1 i.e. -vf "transpose=1" 'cos I need the video rotated 90 degrees further to remove rotation.. but whatever amount you do, from what I understand, it won't put metadata on there. And it will reencode each frame individually. If you don't know and also agree with the default codecs used, then I suggest adding parameters for encoding or reencoding eg -vcodec and -acodec. You should specify both so it doesn't reencode both, you only need to reencode the video, you can copy the audio.

ffmpeg -i first.mp4 -vf "transpose=1" -vcodec libx264 -acodec copy uuuu.mp4

You can see the results with ffmpeg -i and with mediainfo, that there is no longer a 270 degree rotation or any rotation at all(besides 0 at least).

for 180 degrees, -vf "transpose=2,transpose=2" see here.

For the metadata one ffmpeg -i first.mp4 -map_metadata 0 -metadata:s:v rotate="0" -c copy tttt.mp4 should preserve other metadata.

I tend to do the command to remove rotation metadata, then I do -vf transpose, to write the rotation into the file. Not all video players obey metadata so if you leave it there then some players may play it with different orientation to others if rotate metadata is in there.

  • maybe for the second one it's good to specify a video and audio codec so that it doesn't fall to defaults. e.g. for mp4 could do -vcodec libx264 -acodec libmp3lame or -acodec libfaac codecs that are recommended seem to change with time – barlop Dec 21 '19 at 22:35
  • maybe ffmpeg -i inputFile -vf "transpose=1" -vcodec libx264 -c:a copy outputFile and ffmpeg -i input.mp4 -map_metadata 0 -metadata:s:v rotate="90" -codec copy output.mp4 see stackoverflow.com/questions/3937387/rotating-videos-with-ffmpeg – barlop Dec 22 '19 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.