Log in

View Full Version : Rotating video without re-encoding (MP4 etc).


mustardman
26th January 2015, 07:26
Before anyone jumps down my throat, I have done a global search on the doom9 forums, and have come across nothing of use.

It seems a common question to ask, but it also seems to be one that is quite elusive : rotating video (by multiples of 90deg) just like a JPG still can be rotated - without re-encoding.

I have searched wider, and there is a tool to rotate MJPEG losslessly, and there also seem to be a few tools that claim to rotate MP4 video losslessly (VideoGo, Video Cutter). However, it seems exceedingly unclear whether this process simply changes the way the video is displayed by the player (setting a 'display' flag in the stream), or actually rotating the video data in the stream itself.

Personally, I suspect the former. Rotating MJPEG is really a step up from rotating a single JPG image, but rotating a stream with any sort of past/future frame references would be hard.

Do any readers with superior knowledge on this subject have a definitave answer on this one?

Thanks,
MM

Warperus
26th January 2015, 14:47
I've not seen any rotation flag in H.264 stream.
But macroblocks follow raster order, pictures are filled from left to right, from top to bottom. Intra prediction uses left and upper part of slice counting from current macroblock.
I don't think rotation with such limitations is possible in lossless mode unless file size grows by times.
Counting references to previous frames/blocks looks doable, but file size can grow a bit as well.

Asmodian
26th January 2015, 19:11
I have searched wider, and there is a tool to rotate MJPEG losslessly, and there also seem to be a few tools that claim to rotate MP4 video losslessly (VideoGo, Video Cutter). However, it seems exceedingly unclear whether this process simply changes the way the video is displayed by the player (setting a 'display' flag in the stream), or actually rotating the video data in the stream itself.

Personally, I suspect the former. Rotating MJPEG is really a step up from rotating a single JPG image, but rotating a stream with any sort of past/future frame references would be hard.

There is a non-standard flag (not well respected) for rotating video in MP4 but there is no way to rotate H.264 video losslessly. I am assuming H.264/AVC is what is inside your MP4?

mustardman
26th January 2015, 21:47
In actual fact my video's are not MP4 (generally speaking). I have video from several different brands of 'still' cameras, which include AVI and MOV : i have not looked further into the specific codecs they use.

I started by doing a search for "rotate video lossless" on google, and apart from MJPEG, I found nothing concrete. A lot of people (forum posts here and there) claimed "no", but then quite a few claimed "yes" for MP4. Additionally I came across a single thread that talked about rotating quicktime without re-encoding, but different posters seemed to have varying success with that.

So I checked out the home pages for the tools mentioned, and the claim is made pretty clearly there as well (lossless MP4 rotation). But there was nothing on how the process is implemented, either on the home pages or in forums.

MM

nevcairiel
26th January 2015, 21:49
You can't rotate MP4 as such, you can only put a flag into the MP4 that tells the player to rotate the video during playback. However, as others have indicated before, its not that well supported.
MJPG might be the only codec where this works properly due to lossless jpeg rotation.