OT: Can I losslessly invert an MP4 video?

PeterDuke schrieb am 30.12.2015 um 02:57 Uhr
If I hold my mobile phone in the wrong landscape orientation when recording a video, the video appears upside down when viewed on the computer. Is there a lossless way of inverting such a video?

I saw a Youtube video where the presenter used Free Video Flip and Rotate to invert the image for playback on a computer, but it was still upside down when uploaded to Youtube. Several viewers also commented that the utility is loaded with malware.

Kommentare

musicvid10 schrieb am 30.12.2015 um 03:55 Uhr
There is -- but it's not not quite lossless in Vegas because pixel interpolation is not quite perfect.
Last time I had to do this I believe it was with GoPro Studio, and with quite good results.

All the command-line utilities (Avisynth/MeGUI, ffmpeg, etc.) should do this as well.
PeterDuke schrieb am 30.12.2015 um 13:49 Uhr
Thanks. I'll explore them.

I wouldn't have thought pixel interpolation was necessary. Merely rotation of each frame by 180 degrees (or perhaps each GOP) (or perhaps I am just ignorant).
musicvid10 schrieb am 30.12.2015 um 15:27 Uhr
I actually ran one of my silly tests a few years ago and found differences from the original in the way Vegas does it.
Interpolation may be an inaccurate choice of words; remapping to new coordinates might be closer to what goes on.
PeterDuke schrieb am 31.12.2015 um 00:00 Uhr
Well, the dumb straight forward way would be to fully decode each frame, rotate 180 degrees and then re-encode. Perhaps that is what Vegas does.

t seems to me that there should be a way to rotate losslessly, just as can be done for JPEG images. MPEG is further complicated by the interframe predictive coding, but that should only be a complication, not something insurmountable. All coefficients applying to pixel (x,y) are "simply" transferred to pixel (N-x-1, M-y-1), where the frame size is NxM pixels.
John_Cline schrieb am 31.12.2015 um 00:26 Uhr
Given the math involved and the complex intraframe encoding of MP4 files, I know of no way to losslessly invert the video without a decoding/encoding cycle.
musicvid10 schrieb am 31.12.2015 um 00:48 Uhr
Correct. Only one in every 300 frames or so constitutes an actual image, called an i-frame.
Incomplete macroblocks would result in errored or "filled in" bits.


DeadRadioStar schrieb am 31.12.2015 um 03:11 Uhr
Just turn your TV upside down.
I'll get me coat ....
TheHappyFriar schrieb am 31.12.2015 um 03:36 Uhr
Maybe rendering to a PNG image sequence & then re-rendering a new video would be the highest quality way. Except for the "rotate TV" method. Works every time. Windows even let's you flip the display w/o physically doing it so that might work too. :)
John_Cline schrieb am 31.12.2015 um 06:22 Uhr
Rendering to a PNG image sequence would be absolutely no different than just having Vegas rotate the video. Of course, the visual quality of the subsequent encoding to MP4 will be significantly affected by the choice of MP4 encoding parameters and bit rate. Rotating the video is the easy part and Vegas is perfectly capable of this.
imaginACTION_films schrieb am 31.12.2015 um 07:44 Uhr
Use your mobile phone to capture a video the right way up, then put a Dymo label on the camera saying THIS WAY UP. Then you'll never have to flip the video...
Happy New Year, everyone!
David
Chienworks schrieb am 31.12.2015 um 14:24 Uhr
"All coefficients applying to pixel (x,y) are "simply" transferred to pixel (N-x-1, M-y-1), where the frame size is NxM pixels."

The problem is that in highly compressed formats like MP4 with GOP encoding, there are no pixels in the data stream. All you have is mathematical descriptions of amorphous waveforms that represent an approximation of the original image, and that only on I frames. In between the I frames are merely differences between the previous I frame and the next.

The only way to pull pixel data out of that is to decompress and decode it completely, of course with the concomitant loss of quality that the original encoding introduced. If you then want an MP4 file out of it after the transformation then you have to re-encode and compress it again, introducing more quality loss.
Gyan schrieb am 01.01.2016 um 14:13 Uhr
You may not need to actually transpose the stored matrices (if no flipping is needed) . If the video player understands embedded rotation tag, then the following ffmpeg command will quickly (and losslessly) indicate to the video player on how to orient the decoded video stream


ffmpeg -i input.mp4 -c copy -metadata:s:v rotate=180 output.mp4
PeterDuke schrieb am 02.01.2016 um 01:57 Uhr
The trouble with the rotation tag is that some apps ignore it (MPC-HC and VideoReDo for instance).

The tag is apparently already set. I was looking for a universal solution and I suffer from a tidy mind :(
PeterDuke schrieb am 02.01.2016 um 02:24 Uhr
Lossless rotation of MP4 by 180 degrees seems like it should be possible in principle, but after an extensive search I have found many people looking for it but no solutions.

One person said that the matrices are scanned in a certain order during decoding, and rotation of the matrices (as can be done with JPEG for instance) would lead to non-standard scanning. I know not whether this is true or not, nor whether it is important (Jelly wobble?)