FFmpeg Fails to Rotate Landscape MP4 Videos Concatenation
MP4 videos created on cellphones, especially when taken in landscape mode, can cause issues when concatenating using FFmpeg. This article will cover the key concepts, including subtitles, and provide a detailed context on the topic.
Understanding the Problem
When concatenating MP4 videos using FFmpeg, users may encounter an issue where videos taken in landscape mode are not rotated correctly. This issue arises because FFmpeg does not automatically rotate videos based on their orientation metadata.
Rotating Videos with FFmpeg
To rotate a video using FFmpeg, you can use the following command:
ffmpeg -i input.mp4 -c:v copy -metadata:s:v:0 rotate=90 output.mp4Replace "input.mp4" with the name of the video file you want to rotate, and "output.mp4" with the name you want to give to the rotated video. The "rotate" metadata value can be set to 90, 180, or 270 degrees, depending on the orientation of the video.
Concatenating Rotated Videos
After rotating the videos, you can concatenate them using the following command:
ffmpeg -f concat -i <(for f in ./*.mp4; do echo "file '$PWD/$f'"; done) -c copy output.mp4This command will concatenate all the MP4 videos in the current directory and create a new video file called "output.mp4".
Adding Subtitles
If you want to add subtitles to your concatenated video, you can use the following command:
ffmpeg -i output.mp4 -vf "subtitles=subtitle.srt" -c:a copy output_with_subtitles.mp4Replace "subtitle.srt" with the name of your subtitle file. The subtitle file must be in the same directory as the video file and must be in SRT format.
FFmpeg is a powerful tool for concatenating MP4 videos, but it can fail to rotate landscape videos correctly. By using the commands provided in this article, you can rotate and concatenate your videos, ensuring that they are displayed correctly.