2

I am trying to do something similar to the questions here and here, but with a small difference. I am trying to flip the video along the Y or X axes instead of doing a rotation.

The solution in those threads to modify the rotation matrix seems like the perfect approach, and I am able to modify the parameters to perform the rotation. But I cannot figure out what the values should be for flipping the video.

To quote from those threads:

- no rotation:
00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
40
- 180°:
FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00
FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00
40
- 90° cw:
00 00 00 00 00 01 00 00 00 00 00 00 FF FF 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
40
- 90° ccw:
00 00 00 00 FF FF 00 00 00 00 00 00 00 01 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
40

I was unable to find documentation online that talks about what the values in those two lines indicate, hence I was not able to achieve the flip.

I tried alternatives with ffmpeg as well, but I run into issues:

ffmpeg -i input.mp4 -vf hflip output.mp4

... This re-encodes the file because of the "vf" flag that applies filtering.

ffmpeg -i input.mp4 -vf "transpose=0,transpose=1" output.mp4

... This too re-encodes the file because of the "vf" flag.

ffmpeg -i input.mp4 -metadata:s:v rotate="90" -codec copy output.mp4

... This works without re-encoding (and is almost as fast as directly editing the file), but obviously rotation does not achieve a flip. Is there a way I could use the metadata option with transpose?

ffmpeg -i input.mp4 -vf "transpose=0,transpose=1" -codec copy output.mp4

... This gives me an error saying that filtering and streamcopy cannot be used together.

Is it possible to do what I am trying to do? How would I achieve a video flip without encoding? Even if I end up encoding, how can I do it in a lossless manner?

I would have posted on the threads I have referenced above for help, but I am a new user here and cannot post comments on threads as a result.

Sayontan
  • 21
  • 1
  • 4
  • In terms of the matrix mathematics, for horz. flip, you have to change, in `no rotation`, the first `00 01` to `FF FF`. For vert. flip, change the 2nd `00 01` to `FF FF`. However, it seems most players only check if the matrix values correspond to a pure rotation transform. If not, the image is untouched. – Gyan Jan 14 '19 at 05:08
  • @Gyan - So the interpretation of this is really player-specific? In other words the only true way to do this is to re-encode? – Sayontan Jan 14 '19 at 18:49
  • Short answer: yes. Longer answer: it's not really the interpretation that changes but whether the player checks for pure flips. Generally, they don't. – Gyan Jan 15 '19 at 04:14

0 Answers0