[FFmpeg-user] Concatenating mp4 files rotates the video

iburman at compuscience.com iburman at compuscience.com
Tue May 21 21:52:38 EEST 2024


I need to concatenate several mp4 videos taken with a cell phone. It happens
that the resulting concatenated video ends up rotated.

 

I am using the method shown in https://trac.ffmpeg.org/wiki/Concatenate,
more specifically concat protocol, where I convert the mp4 in a MPEG-2 TS
file and than concatenate the TS files.

 

Below is the output of the used commands. I noticed that converting to TS
files has some rotate info under metadata but I don't have the required
knowledge to understand why this is there.

 

Anyways, what do I need to do to avoid these unrequested rotations?

 

Commands Output:

 

Concatenating 2 files

    11_PeopleWaitingForTheTrain.mp4

    12_I_Am_Waiting.mp4

Protocol: mp4

EXE: -i 11_PeopleWaitingForTheTrain.mp4 -c copy 001.ts

ffmpeg version 2021-03-14-git-1d61a31497-essentials_build-www.gyan.dev
Copyright (c) 2000-2021 the FFmpeg developers

  built with gcc 10.2.0 (Rev6, 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-lzma --enable-zlib
--enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth
--enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265
--enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx
--enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab
--enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm
--enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc
--enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme
--enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame
--enable-libtheora --enable-libvo-amrwbenc --enable-libgsm
--enable-libopencore-amrnb --enable-libopus --enable-libspeex
--enable-libvorbis --enable-librubberband

  libavutil      56. 68.100 / 56. 68.100

  libavcodec     58.131.100 / 58.131.100

  libavformat    58. 74.100 / 58. 74.100

  libavdevice    58. 12.100 / 58. 12.100

  libavfilter     7.109.100 /  7.109.100

  libswscale      5.  8.100 /  5.  8.100

  libswresample   3.  8.100 /  3.  8.100

  libpostproc    55.  8.100 / 55.  8.100

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '11_PeopleWaitingForTheTrain.mp4':

  Metadata:

    major_brand     : isom

    minor_version   : 512

    compatible_brands: isomiso2avc1mp41

    encoder         : Lavf58.74.100

  Duration: 00:00:06.02, start: 0.000000, bitrate: 17254 kb/s

  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv,
bt709), 1920x1080, 17036 kb/s, 30 fps, 30 tbr, 90k tbn, 180k tbc (default)

    Metadata:

      rotate          : 90

      handler_name    : VideoHandle

      vendor_id       : [0][0][0][0]

    Side data:

      displaymatrix: rotation of -90.00 degrees

  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 256 kb/s (default)

    Metadata:

      handler_name    : SoundHandle

      vendor_id       : [0][0][0][0]

Output #0, mpegts, to '001.ts':

  Metadata:

    major_brand     : isom

    minor_version   : 512

    compatible_brands: isomiso2avc1mp41

    encoder         : Lavf58.74.100

  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv,
bt709), 1920x1080, q=2-31, 17036 kb/s, 30 fps, 30 tbr, 90k tbn, 90k tbc
(default)

    Metadata:

      rotate          : 90

      handler_name    : VideoHandle

      vendor_id       : [0][0][0][0]

    Side data:

      displaymatrix: rotation of -90.00 degrees

  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 256 kb/s (default)

    Metadata:

      handler_name    : SoundHandle

      vendor_id       : [0][0][0][0]

Stream mapping:

  Stream #0:0 -> #0:0 (copy)

  Stream #0:1 -> #0:1 (copy)

Press [q] to stop, [?] for help

frame=    0 fps=0.0 q=-1.0 size=       0kB time=00:00:00.00 bitrate=N/A
speed=   0x    

frame=  180 fps=0.0 q=-1.0 Lsize=   12993kB time=00:00:05.99
bitrate=17756.2kbits/s speed= 147x    

video:12476kB audio:188kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 2.598021%

 

----------------

 

EXE: -i 12_I_Am_Waiting.mp4 -c copy 002.ts

ffmpeg version 2021-03-14-git-1d61a31497-essentials_build-www.gyan.dev
Copyright (c) 2000-2021 the FFmpeg developers

  built with gcc 10.2.0 (Rev6, 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-lzma --enable-zlib
--enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth
--enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265
--enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx
--enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab
--enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm
--enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc
--enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme
--enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame
--enable-libtheora --enable-libvo-amrwbenc --enable-libgsm
--enable-libopencore-amrnb --enable-libopus --enable-libspeex
--enable-libvorbis --enable-librubberband

  libavutil      56. 68.100 / 56. 68.100

  libavcodec     58.131.100 / 58.131.100

  libavformat    58. 74.100 / 58. 74.100

  libavdevice    58. 12.100 / 58. 12.100

  libavfilter     7.109.100 /  7.109.100

  libswscale      5.  8.100 /  5.  8.100

  libswresample   3.  8.100 /  3.  8.100

  libpostproc    55.  8.100 / 55.  8.100

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '12_I_Am_Waiting.mp4':

  Metadata:

    major_brand     : isom

    minor_version   : 512

    compatible_brands: isomiso2avc1mp41

    encoder         : Lavf58.74.100

  Duration: 00:00:10.01, start: 0.000000, bitrate: 19003 kb/s

  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv,
bt709), 1920x1080, 18717 kb/s, 30 fps, 30 tbr, 90k tbn, 180k tbc (default)

    Metadata:

      rotate          : 270

      handler_name    : VideoHandle

      vendor_id       : [0][0][0][0]

    Side data:

      displaymatrix: rotation of 90.00 degrees

  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 281 kb/s (default)

    Metadata:

      handler_name    : SoundHandle

      vendor_id       : [0][0][0][0]

Output #0, mpegts, to '002.ts':

  Metadata:

    major_brand     : isom

    minor_version   : 512

    compatible_brands: isomiso2avc1mp41

    encoder         : Lavf58.74.100

  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv,
bt709), 1920x1080, q=2-31, 18717 kb/s, 30 fps, 30 tbr, 90k tbn, 90k tbc
(default)

    Metadata:

      rotate          : 270

      handler_name    : VideoHandle

      vendor_id       : [0][0][0][0]

    Side data:

      displaymatrix: rotation of 90.00 degrees

  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 281 kb/s (default)

    Metadata:

      handler_name    : SoundHandle

      vendor_id       : [0][0][0][0]

Stream mapping:

  Stream #0:0 -> #0:0 (copy)

  Stream #0:1 -> #0:1 (copy)

Press [q] to stop, [?] for help

frame=    0 fps=0.0 q=-1.0 size=       0kB time=00:00:00.00 bitrate=N/A
speed=   0x    

frame=  330 fps=0.0 q=-1.0 Lsize=   23803kB time=00:00:09.98
bitrate=19525.4kbits/s speed= 158x    

video:22860kB audio:344kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 2.580378%

 

----------------

 

ffmpeg cmd: -i "concat:001.ts|002.ts" -c copy concatenated.mp4

EXE: -i "concat:001.ts|002.ts" -c copy concatenated.mp4

ffmpeg version 2021-03-14-git-1d61a31497-essentials_build-www.gyan.dev
Copyright (c) 2000-2021 the FFmpeg developers

  built with gcc 10.2.0 (Rev6, 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-lzma --enable-zlib
--enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth
--enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265
--enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx
--enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab
--enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm
--enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc
--enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme
--enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame
--enable-libtheora --enable-libvo-amrwbenc --enable-libgsm
--enable-libopencore-amrnb --enable-libopus --enable-libspeex
--enable-libvorbis --enable-librubberband

  libavutil      56. 68.100 / 56. 68.100

  libavcodec     58.131.100 / 58.131.100

  libavformat    58. 74.100 / 58. 74.100

  libavdevice    58. 12.100 / 58. 12.100

  libavfilter     7.109.100 /  7.109.100

  libswscale      5.  8.100 /  5.  8.100

  libswresample   3.  8.100 /  3.  8.100

  libpostproc    55.  8.100 / 55.  8.100

Input #0, mpegts, from 'concat:001.ts|002.ts':

  Duration: 00:00:11.00, start: 1.400000, bitrate: 27406 kb/s

  Program 1 

    Metadata:

      service_name    : Service01

      service_provider: FFmpeg

  Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B),
yuv420p(tv, bt709, progressive), 1920x1080, 30 tbr, 90k tbn, 180k tbc

  Stream #0:1[0x101](eng): Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000
Hz, stereo, fltp, 258 kb/s

Output #0, mp4, to 'concatenated.mp4':

  Metadata:

    encoder         : Lavf58.74.100

  Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709,
progressive), 1920x1080, q=2-31, 30 tbr, 90k tbn, 90k tbc

  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 258 kb/s

Stream mapping:

  Stream #0:0 -> #0:0 (copy)

  Stream #0:1 -> #0:1 (copy)

Press [q] to stop, [?] for help

frame=    0 fps=0.0 q=-1.0 size=       0kB time=00:00:00.00 bitrate=N/A
speed=   0x    

[mpegts @ 00000272e61fcec0] Packet corrupt (stream = 0, dts = 664006).

[mpegts @ 00000272e61fcec0] DTS 126018 < 664006 out of order

frame=  510 fps=0.0 q=-1.0 Lsize=   35890kB time=00:00:17.00
bitrate=17292.3kbits/s speed= 237x    

video:35340kB audio:538kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 0.036390%

 

----------------

 



More information about the ffmpeg-user mailing list