1

I have some MP4 video files that were created with a cell phone. Some of them were taken in landscape, others not. It happens that by concatenating them using ffmpeg the ones that are not landscape end up rotated by 90 or 270 degrees.

I need to concatenate these videos without any rotation. I found a few posts with similar issues but so far nothing solved my problem. In particular, this one seems very close: Is there any way to reset the rotation flag of videos while using concat to combine them?

The suggestion here is to simply add "rotate=0" after -c copy. I tried this but it didn't made any difference.

Any idea on how to solve this problem?

Original output removed. Now for additional data:

After trying a few things, I seem to understand better how things work, but I still was not able to accomplish my initial goal. Repeating what I need to accomplish for completeness: I have some mp4 videos taken with a cellphone, some of them taken landscape others portrait. I want to concatenate these videos. By doing so, the portrait ones end up rotated by 90 degrees in the final concatenated file.

What I understand better now: The portrait videos are stored rotated by 90 degrees in the raw stream The rotate metadata instruct the player to rotate the video by -90 degrees, so you see the video playing as expected The ffmpeg concat command the way I use it, ignores the rotate metadata, so when you view the concatenated file, the portrait portions are shown as if rotated by 90 degrees. This is nothing else then simply adding the raw stream as it is.

The command that I was using is: ffmpeg -y -f concat -safe 0 -i merge_list.txt -c copy -metadata:s:v:0 rotate=0 merged.mp4 In it, the rotate=0 does nothing to solve the problem. It just tells ffmpeg to not include any rotate metadata in the final file. (this is how I understand it).

This post helped me to understand things better: How can I get ffmpeg to autorotate input files while concatenating?. The conclusion was that to accomplish what I need, I would have to rotate each portrait video individually myself, before concatenate the whole set. So I tried this and got in a new problem.

To test it out, I took a portrait video, removed the rotate metadata using Exiftool, and next rotated it using: ffmpeg -i inputFile -vf "transpose=1" outputfile. I used the resulting file to concatenate it to some landscape videos. In terms of rotation it actually worked but the portrait video seems to be static on one of the initial frames. In other words, the initial frame is shown for the duration of the video.

In the ffmpeg output I see hundreds of messages like this, when it comes to add the portrait video:

[vost#0:0/copy @ 000002622cf5d1c0] Non-monotonic DTS; previous: 1777162, current: 302790; changing to 1777163. This may result in incorrect timestamps in the output file.

I am adding the full output below.

What do these messages mean, and how can I fix this problem?

latest output:

D:\99_FFMpeg>D:\01_Apl\ffmpeg_2024\bin\ffmpeg -y -f concat -safe 0 -i merge_list.txt -c copy merged.mp4 ffmpeg version 2024-05-23-git-ece95dc3dc-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. 19.100 / 59. 19.100 libavcodec 61. 5.104 / 61. 5.104 libavformat 61. 3.103 / 61. 3.103 libavdevice 61. 2.100 / 61. 2.100 libavfilter 10. 2.102 / 10. 2.102 libswscale 8. 2.100 / 8. 2.100 libswresample 5. 2.100 / 5. 2.100 libpostproc 58. 2.100 / 58. 2.100 [mov,mp4,m4a,3gp,3g2,mj2 @ 000002622c581180] Auto-inserting h264_mp4toannexb bitstream filter Input #0, concat, from 'merge_list.txt': Duration: N/A, start: 0.000000, bitrate: 17345 kb/s Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080, 17088 kb/s, 30 fps, 30 tbr, 90k tbn Metadata: creation_time : 2024-05-23T13:02:03.000000Z handler_name : VideoHandle vendor_id : [0][0][0][0] Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s Metadata: creation_time : 2024-05-23T13:02:03.000000Z handler_name : SoundHandle vendor_id : [0][0][0][0] Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Output #0, mp4, to 'merged.mp4': Metadata: encoder : Lavf61.3.103 Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080, q=2-31, 17088 kb/s, 30 fps, 30 tbr, 90k tbn Metadata: creation_time : 2024-05-23T13:02:03.000000Z handler_name : VideoHandle vendor_id : [0][0][0][0] Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s Metadata: creation_time : 2024-05-23T13:02:03.000000Z handler_name : SoundHandle vendor_id : [0][0][0][0] Press [q] to stop, [?] for help [mov,mp4,m4a,3gp,3g2,mj2 @ 000002622c5a1000] Auto-inserting h264_mp4toannexb bitstream filter Last message repeated 1 times [vost#0:0/copy @ 000002622cf5d1c0] Non-monotonic DTS; previous: 1777162, current: 302790; changing to 1777163. This may result in incorrect timestamps in the output file. [vost#0:0/copy @ 000002622cf5d1c0] Non-monotonic DTS; previous: 1777163, current: 303302; changing to 1777164. This may result in incorrect timestamps in the output file. [vost#0:0/copy @ 000002622cf5d1c0] Non-monotonic DTS; previous: 1777164, current: 303814; changing to 1777165. This may result in incorrect timestamps in the output file. [vost#0:0/copy @ 000002622cf5d1c0] Non-monotonic DTS; previous: 1777165, current: 304326; changing to 1777166. This may result in incorrect timestamps in the output file. ..... removed tons of similar messages for brevity ..... [vost#0:0/copy @ 000002622cf5d1c0] Non-monotonic DTS; previous: 1777429, current: 439494; changing to 1777430. This may result in incorrect timestamps in the output file. [vost#0:0/copy @ 000002622cf5d1c0] Non-monotonic DTS; previous: 1777430, current: 440006; changing to 1777431. This may result in incorrect timestamps in the output file. [vost#0:0/copy @ 000002622cf5d1c0] Non-monotonic DTS; previous: 1777431, current: 440518; changing to 1777432. This may result in incorrect timestamps in the output file. [out#0/mp4 @ 000002622c566940] video:43055KiB audio:760KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 0.050455% size= 43838KiB time=00:00:04.90 bitrate=73284.9kbits/s speed=9.63x

4
  • Perhaps start by looking through these other questions about ffmpeg rotation? I'm guessing you'll want to read the existing rotation value: superuser.com/search?q=ffmpeg+rotation Commented May 23 at 21:13
  • If you want to use the solution from my previous answer, try applying -c copy -metadata:s:v:0 rotate=0 to every input video file (create 10 temporary copies for 10 input files for example), and apply the concat to the temporary copies. It is probably not the best solution, but I think it should work... In case it's not working, you may play each of the temporary videos (created with rotate=0), and watch if they are (played) rotated or not (there is a chance that the rotation is not defined in the metadata). In a second thought, you probably don't want to disable the rotation but try...
    – Rotem
    Commented May 23 at 22:25
  • Thanks for your replies. My answer is too long to be posted as a comment, so I will edit my question with new data...
    – Israel
    Commented May 24 at 19:36
  • 1
    Use mkv. Change the container from mp4 to mkv BEFORE concat. Use -c copy -avoid_negative_ts make_zero on the initial files and make sure you output to .mkv also when concatenating. That will solve the [vost#0:0/copy @ 000002622cf5d1c0] Non-monotonic DTS; previous...This may result in incorrect timestamps in the output file. problem.
    – JayCravens
    Commented Jun 10 at 22:39

0

You must log in to answer this question.

Browse other questions tagged .