[FFmpeg-user] Rotate metadata flag not applied on mp4 ?

Vincent Deconinck vdeconinck at gmail.com
Sat Jul 6 21:55:01 EEST 2024


Hi,

I have a few videos that have been shot upside down but lack the rotate
flag so they play upside down in e.g. VLC.
Here is an example :
https://www.swisstransfer.com/d/48602faa-73aa-4c6d-b3bf-d2db6b2ffe9c

I'd like to add the rotation information without reencoding. Many pages
indicate it can be done with "-metadata:s:v rotate=180".
However, it seems that command has no effect on my file (no matter the
value of the rotate parameter btw):

D:\TEMP\rotate>ffmpeg -i in.mp4 -metadata:s:v rotate=180 -c copy out180.mp4
ffmpeg version 7.0.1-full_build-www.gyan.dev Copyright (c) 2000-2024 the
FFmpeg developers
  built with gcc 13.2.0 (Rev5, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static
--disable-w32threads --disable-autodetect --enable-fontconfig
--enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib
--enable-lzma --enable-libsnappy --enable-zlib --enable-librist
--enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth
--enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24
--enable-libaribcaption --enable-libdav1d --enable-libdavs2
--enable-libuavs3d --enable-libxevd --enable-libzvbi --enable-librav1e
--enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265
--enable-libxavs2 --enable-libxeve --enable-libxvid --enable-libaom
--enable-libjxl --enable-libopenjpeg --enable-libvpx
--enable-mediafoundation --enable-libass --enable-frei0r
--enable-libfreetype --enable-libfribidi --enable-libharfbuzz
--enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg
--enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2
--enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl
--enable-nvdec --enable-nvenc --enable-vaapi --enable-libshaderc
--enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio
--enable-libgme --enable-libmodplug --enable-libopenmpt
--enable-libopencore-amrwb --enable-libmp3lame --enable-libshine
--enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc
--enable-libcodec2 --enable-libilbc --enable-libgsm
--enable-libopencore-amrnb --enable-libopus --enable-libspeex
--enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite
--enable-libmysofa --enable-librubberband --enable-libsoxr
--enable-chromaprint
  libavutil      59.  8.100 / 59.  8.100
  libavcodec     61.  3.100 / 61.  3.100
  libavformat    61.  1.100 / 61.  1.100
  libavdevice    61.  1.100 / 61.  1.100
  libavfilter    10.  1.100 / 10.  1.100
  libswscale      8.  1.100 /  8.  1.100
  libswresample   5.  1.100 /  5.  1.100
  libpostproc    58.  1.100 / 58.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'in.mp4':
  Metadata:
    major_brand     : avc1
    minor_version   : 538182144
    compatible_brands: avc1isom
    creation_time   : 2024-07-06T16:31:05.000000Z
  Duration: 00:00:08.98, start: 0.000000, bitrate: 141271 kb/s
  Stream #0:0[0x1](eng): Video: hevc (Main) (hvc1 / 0x31637668),
yuvj420p(pc, bt709), 3840x2160 [SAR 1:1 DAR 16:9], 137474 kb/s, 59.94 fps,
59.94 tbr, 60k tbn (default)
      Metadata:
        creation_time   : 2024-07-06T16:31:05.000000Z
        handler_name    : ?INS.HVC
        vendor_id       : [0][0][0][0]
        encoder         : HVC encoder
  Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp, 189 kb/s (default)
      Metadata:
        creation_time   : 2024-07-06T16:31:05.000000Z
        handler_name    : ?INS.AAC
        vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Output #0, mp4, to 'out180.mp4':
  Metadata:
    major_brand     : avc1
    minor_version   : 538182144
    compatible_brands: avc1isom
    encoder         : Lavf61.1.100
  Stream #0:0(eng): Video: hevc (Main) (hvc1 / 0x31637668), yuvj420p(pc,
bt709), 3840x2160 [SAR 1:1 DAR 16:9], q=2-31, 137474 kb/s, 59.94 fps, 59.94
tbr, 60k tbn (default)
      Metadata:
        creation_time   : 2024-07-06T16:31:05.000000Z
        handler_name    : ?INS.HVC
        vendor_id       : [0][0][0][0]
        encoder         : HVC encoder
        rotate          : 180
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 189 kb/s (default)
      Metadata:
        creation_time   : 2024-07-06T16:31:05.000000Z
        handler_name    : ?INS.AAC
        vendor_id       : [0][0][0][0]
Press [q] to stop, [?] for help
[out#0/mp4 @ 000001b3d81f9f40] video:150625KiB audio:206KiB subtitle:0KiB
other streams:0KiB global headers:0KiB muxing overhead: 0.007482%
size=  150842KiB time=00:00:08.89 bitrate=138904.9kbits/s speed= 124x

Note the "rotate: 180" is indicated in the above output. However, VLC still
plays it upside down and it seems the rotate was not really written to the
output file:

D:\TEMP\rotate>ffprobe -i out180.mp4
[...]
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out180.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf61.1.100
  Duration: 00:00:08.98, start: 0.000000, bitrate: 137672 kb/s
  Stream #0:0[0x1](eng): Video: hevc (Main) (hvc1 / 0x31637668),
yuvj420p(pc, bt709), 3840x2160 [SAR 1:1 DAR 16:9], 137474 kb/s, 59.94 fps,
59.94 tbr, 60k tbn (default)
      Metadata:
        handler_name    : ?INS.HVC
        vendor_id       : [0][0][0][0]
        encoder         : HVC encoder
  Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp, 189 kb/s (default)
      Metadata:
        handler_name    : ?INS.AAC
        vendor_id       : [0][0][0][0]

I then tested a rotation of 90° of the same file:
D:\TEMP\rotate>ffmpeg -i in.mp4 -metadata:s:v rotate=90 -c copy out90.mp4
(the output also indicates a rotate:90 metadata is set)

But then comparing the two "rotated" files:
D:\TEMP\rotate>fc /b out180.mp4 out90.mp4
Comparing files out180.mp4 and out90.MP4
FC : no differences encountered

??

What am I missing ?

Thanks,

Vincent


More information about the ffmpeg-user mailing list