rotating video
Apr. 7th, 2021 01:23 amI had recorded some video upside-down and wanted to resave it in the correct orientation.
ffmpeg can do that with a command like this:
ffmpeg -i [input_file.mp4] -vf "transpose=2, transpose=2" -crf 23 [rotated_output_file.mp4]
However, when I tried that, the resulting file size was larger than the original. The "crf" parameter controls the quality and/or bitrate, so I tested different crf values. The number which resulted in a similar file size as the original had noticeably reduced quality. The number with a similar quality had a much larger file size.
Per information given on these pages, it is not possible to keep both the same file size and quality when rotating or otherwise editing the video. As I understand it now, the video in the original file has already been compressed, losing details. To play or edit the video, it is decompressed. To save changes, it has to be recompressed, which unavoidably results in losing even more details. To limit the loss of quality when resaving the edited file, one has to increase the file size.
https://video.stackexchange.com/questions/22553/how-do-i-edit-a-video-clip-without-increasing-size
https://forum.videohelp.com/threads/314112-How-to-rotate-a-video-without-re-encoding
So rather than resaving the video, it may be preferable to keep the original upside-down video file, and use a video player that can rotate it on the fly while playing it.
In VLC this can be done by right-clicking the video and selecting:
Tools - Effects & Filters - Video Effects - Geometry - Transform - Rotate by 180 degrees
ffmpeg can do that with a command like this:
ffmpeg -i [input_file.mp4] -vf "transpose=2, transpose=2" -crf 23 [rotated_output_file.mp4]
However, when I tried that, the resulting file size was larger than the original. The "crf" parameter controls the quality and/or bitrate, so I tested different crf values. The number which resulted in a similar file size as the original had noticeably reduced quality. The number with a similar quality had a much larger file size.
Per information given on these pages, it is not possible to keep both the same file size and quality when rotating or otherwise editing the video. As I understand it now, the video in the original file has already been compressed, losing details. To play or edit the video, it is decompressed. To save changes, it has to be recompressed, which unavoidably results in losing even more details. To limit the loss of quality when resaving the edited file, one has to increase the file size.
https://video.stackexchange.com/questions/22553/how-do-i-edit-a-video-clip-without-increasing-size
https://forum.videohelp.com/threads/314112-How-to-rotate-a-video-without-re-encoding
So rather than resaving the video, it may be preferable to keep the original upside-down video file, and use a video player that can rotate it on the fly while playing it.
In VLC this can be done by right-clicking the video and selecting:
Tools - Effects & Filters - Video Effects - Geometry - Transform - Rotate by 180 degrees