Reputation: 6238
I'm having some issues trying to remove the rotation value of Android video's. For some reason convertion tools in the cloud cannot seem to handle android's rotation value correctly. f/e I have a portrait video recorded in 1080x1920 (so the file's headers tell me it's actually 1920x1080 with rotation: 90).
So now I'm trying to convert these video's to an actual 1080x1920 format when they have this rotation value but i'm kind of stuck, probably using the wrong search terms on SO and Google.
In the hope of making things clear I've actually added some ffmpeg libs to android following these steps, of course with some changes to parameters. I'm building this on a Mac and this all works fine now. http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/
Now the following, I have no real clue how these libs work and how to use them or which I actually need or if I even need them at all.
Is there anyone who can point me in the right direction of solving my issue? Basicly the video's are on my android filesystem and I can access them fully, before uploading I want to check the values and remove and rotate the video's if needed.
Upvotes: 0
Views: 1756
Reputation: 38672
This is assuming you have a working ffmpeg
binary for Android, for example using this.
See this answer on Super User. To remove the rotation field, you need to add
-metadata:s:v:0 rotate=0
to a command. If you want to keep the video/audio stream intact and simply remove the rotation information, all you need to do is:
ffmpeg -i in.mp4 -c copy -metadata:s:v:0 rotate=0 out.mp4
If you want to bring the video to the correct orientation though, you need the transpose
filter.
ffmpeg -i portrait.mov \
-c:v libx264 -filter:v "transpose=1" \
-c:a copy \
-metadata:s:v:0 rotate=0 out.mp4
Here, transpose=1
will rotate by 90°. If your video is upside down, you need to combine the options. You can for example use -filter:v "transpose=2,transpose=2"
.
Naturally, transposing will re-encode the video and you'll lose quality. Add the -crf
option after -c:v libx264
to set the Constant Rate Factor, which controls the quality. Use lower values to get better quality. 23 is actually the default, so you don't need to specify it at all, but you might want choose something as low as 18 if the video ends up looking bad otherwise, e.g., -c:v libx264 -crf 18
.
Upvotes: 1
Reputation: 81
It will be much easier to work with JavaCV than with ffmpeg with ndk. Javacv wraps the ffmpeg library so you could access it using pure java.
regarding the rotation, this is how videos are created. what do you try to achieve from the rotation? you can do whatever you need with these values set. if you grab a frame and need it straight, just rotate it.
notice that the rotation value is only supported since JB.
Upvotes: 0