Edit MP4 Hex data to vertically or horizontally flip video in a lossless manner












0















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.










share|improve this question























  • 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 at 5: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 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 at 4:14
















0















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.










share|improve this question























  • 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 at 5: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 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 at 4:14














0












0








0








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.










share|improve this question














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.







ffmpeg mp4 lossless flip






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 13 at 20:14









SayontanSayontan

12




12













  • 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 at 5: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 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 at 4:14



















  • 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 at 5: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 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 at 4:14

















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 at 5:08





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 at 5: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 at 18:49





@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 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 at 4:14





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 at 4:14










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1393880%2fedit-mp4-hex-data-to-vertically-or-horizontally-flip-video-in-a-lossless-manner%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1393880%2fedit-mp4-hex-data-to-vertically-or-horizontally-flip-video-in-a-lossless-manner%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy