Rotate Android video for display on web - android

I'm building a website. I'm trying to load my first video onto it. This mp4 video is in portrait orientation and was recorded on an Android device.
When I load this mp4 onto my website, it plays perfectly (in portrait orientation) on Chrome; however, it plays in landscape orientation on Firefox & IE. I realise that this is because Chrome is using the rotation metadata that is stored within the mp4 to play the video in the correct orientation, while FF & IE don't use this metadata.
I've tried to correct this issue using FFMPEG, and various combinations of the Transpose, Metadata & Rotate commands. I am using MediaInfo to view the metadata associated with the files that I produce using FFMPEG.
My problem is:
1) If I use Transpose=1, then on FF & IE & Windows Media Player, the resulting video is actually rotated through 180 degrees, and the metadata shows the file width and depth to be the same as the original file.
2) If I use -metadata:s:v rotate=0 (I've also tried rotate=90), then MediaInfo tells me that the resulting files width & depth are now portrait, but FF & IE & WMP will not play the resulting file. WMP plays the sound but no image, and FF gives an error message "Error Loading This Resource".
What ffmpeg command do I need to use to convert a portrait MP4 recorded an android device into an mp4 that will play in the correct orientation on Firefox?
Thanks in advance

You will have to re-encode it to "physically" rotate the video if you want the browsers or players that do not respect the rotation metadata to play it using the proper orientation.
A modern version of ffmpeg will automatically rotate the video according to the rotation metadata (and will avoid copying the input rotation metadata to the output), so just run:
ffmpeg -i input.mp4 -c:a copy -movflags +faststart output.mp4

Related

How to re-encode a 120fps (or higher) MP4 from my Samsung Galaxy to a 30fps (example) so it plays on Windows like it does on the Samsung

I have some high fps slow-motion videos (mp4) that I've recorded on my phone, but when I copy them to windows and play them back, they play at the normal speed (or they play really fast), unless I slow down playback but this isn't a good result.
What I'd like to do is re-encode (if that's the right word) the video to a standard fps (such as 30) to get a longer video (keeping all the frames), i.e. a 10 second 120fps would end up being a 40 second video at 30fps.
Try using -r such as:
ffmpeg -y -r 30 -i inputSlowMotion.mp4 outputSlowMotion.mp4

Rotating an Mp4 on android without using the metadata rotation tag

I'm having a problem which I have spent the past few days trying to resolve regarding MP4 file rotation on Android. I'm currently working on application which will send the MP4 file across from an android device as a byte stream to be played on another device.
The problem I'm having is that videos recorded in portrait mode on the android device are being displayed rotated 90 degrees on the player receiving the stream.
I have tried creating a new MP4 from the original with rotation changed using MP4Parser. I have also tried changing the rotation by creating a new MP4 changing the key-rotation in the media format and have also tried changing orientation hint when creating a new Muxer.
All of these methods work but only seem to change the rotation metadata. In some players this metadata is being read and a rotation is being applied. However, the player used in the target player used for our application is not capable of reading this metadata.
my only solution would be to create a temporary MP4 which has had the video data rotated then send that across instead. I've found resources to rotate individual YUV image frames within an MP4 but my question is how can I retrieve these frames from an inputted MP4 and write the modified one to a new file?
NOTE: I'm building the application with Xamarin and I've tried using FFMPEG but adding the binaries would make the project too large and I also have concerns about licensing.
We ended up going with an FFMPEG implementation sending the files elsewhere to be converted.

Streaming Android-recorded video online

I'm working on a project for courier service. I have developed an Android Application for our employees wich works as a camera app, they can make photos and video records with. When the photo or video file is ready, this app can automatically upload it to the server (if WiFi connection is active). The server maintains a web site where we can see each employee's daily job, including links to photo and video files. Of course, there is no problem accessing photos through any browser, but there is such problem with video files.
We don't restrict Android devices with which an employee works, only that it is powered by Android 2.3.3 or later (and certainly must have a camera). Video is written with CamcorderProfile.QUALITY_LOW setting, so it's format is up to device's decision what this CamcorderProfile.QUALITY_LOW is. There is no problem in viewing video files from varying devices on a desktop (Windows). Me and my chief have some browser plugins so this files can be open in a browser. But we want to have a video viewing solution on site that does not require any browser plugin or additional software at the client's side.
So the questions are:
What is the best video format that can enable online video viewing without downloading the whole file to the client's side (like at YouTube), video records can be very long (an hour, two hours or even more).
What tool I need for a universal conversion of Android-recorded video files to that format, without manually specifying input file format (as it can be quite different)? Our server is powered by "SMP Debian 3.2.63-2+deb7u1 x86_64".
I may have missed something. I'm sorry, this is my first project to deal with video, I lack knowledge.
I answer my own question, as it all seems decided already. After further research I came to decision that we will stream everything at our site with tag, the only source will be .mp4 (H.264), as we thought that 99.9% of our users will have no problem with it. I'a a windows user, and I have no problem with watching H.264 video in Google Chrome, Mozilla Firefox and Microsoft Internet Explorer, and so most of our clients will do.
As for video conversion into H.264, ffmpeg will do the job. I have already done some tests, all great. The real problem was to manage video rotation, as all video is recorded from Android phones in portrait mode, and it appeared that at Android this is done by recording frames in landscape mode (native camera orientation), but specifying 90 degree rotation attribute in meta data. And a great quantity of video players and Firefox refused to understand it. The problem can be solved by "transpose" and "rotate" in a command like this:
ffmpeg -i 1.avi -vf "transpose=1" -r 25 -b:a 64k -b:v 256k -metadata:s:v:0 rotate=0 r1.mp4
-vf "transpose=1" physically rotates frames 90 degrees
-metadata:s:v:0 rotate=0 clears rotation attribute in meta data because rotation is already done
Left is the job to tune parameters for output quality, write a batch conversion script, put it on crontab, and write HTML and JS to allow people to watch this video.

Mp4 video rotation metadata

I have developed an android/ios video sharing app that records a video and uploads it to amazon s3. For compatibility both android/ios record in mp4 format with H264/AAC codecs.
The users might shoot portrait or landscape and the app, getting info from the sensors, set the rotation of the file (mediarecorder.setOrientationHint on android and something similar on iOS)
The videos from iOS play fine on android and vice versa. The problem is when i want to play a video on a web browser. The browsers that support mp4 format (ie, chrome) display the video but ignore the rotation metadata. The same thing happens when i playback those videos with mplayer on linux.
The first solution that comes to mind is
ffmpeg -i in.mp4 -vf transpose=<rotation value> out.mp4
Is there a reason why browsers ignore rotation metadata? Is it a bug? Could i do something to fix this while recording the video?
Here are 2 sample from iOS and android respectively.
Thansk
ios video
android video
Method 1: Rotate the HTML Element if the aspect ratio is not horizontal
Chrome HTML5 Video Flipping Portrait Sideways
Method 2: Re-encode the iPhone-Video
Displaying vertical videos with html5 on chrome
Method 3: Set orientation properly on iOS-Devices (Advanced)
iOS AVFoundation: Setting Orientation of Video
Method 4: Ask this guy if he has found an answer
Use FFmpeg to rotate the video based on its <rotate> metadata? Why does Android put the wrong metadata?

Retrieve orientation info for video under Android

Just like ExifInterface.TAG_ORIENTATION's working for JPEG, how can I retrieve orientation info for video ?
For example I record a video in portrait mode, the orientation of video should be 90 or 270.
And when I record a video in landscape mode, the value should be 0 or 180.
When playing video, MediaPlayer in SDK always works correctly, but I don't find any way to retrieve this info.
Finally, if I cannot get orientation of video using android SDK, can I get this info using FFMPEG ?
Thanks very much for your help~
You can do this using FFmpeg:
$ ffprobe -show_streams input.avi | grep rotate
TAG:rotate=90
$
I found the following blog post that shows how to get the metadata of a media file. All functionality requires API level >= 10 though.

Categories

Resources