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?
Related
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
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.
I am working with html5 video tag, i am using .m3u8 file for source. I can not able to seek video by using currentTime property in android 4+ whereas if i using .mp4 file i can able to seek.
In ipad its working properly but not working in android. Please guide me to rectify this issue.
Thanks,
Thavaprakash. S.
HLS and Android are not the best of friends.
Some problems I know of are:
No adaptive bitrate switching: the first quality is picked, no switching will occur.
When pausing, the video restarts from the beginning (for example with VOD).
When going fullscreen, the video restarts from the beginning.
When offering a livestream with DVR, the stream starts at the beginning of the DVR instead of at the "live" moment.
You cannot seek. <-- this is the one for you
Aspect ratio's are not detected properly. (tho this should be fixed in 4.1)
On top of these problems, there is no support for HLS in pre 2.3 Android and in 3.0 it actually makes your tablet crash.
Basically: only use HLS on Android for live video without DVR and set the correct aspect ratio. Oh, and try to pick a "suitable" quality, cause it won't switch.
I have a web-view in an application and i use html5 tag.
I have had all kinds of issues on different android devices(samsung, sony, etc) with different android versions. Some could not play .mp4 and only played .m4v extensions. Another old tablet could only play mp4.
On an Xperia I had a special case. The webview couldn't play the video in html and played it in another custom video view(although this didn't bother me at all).
I need the videos to autoplay as soon as i open the webview(and have managed to do it on those few videos that work), and i have end-video event handlers that have to fire at the right time.
If anyone knows what video format + video and audio codification to use in order to have compatibility with all webviews on android please
Android webview and HTML5 player that works with the video codecs that Android supports (.mp4 is best for progressive video as it has by far the widest support), and it also supports .flv with flash plugin.
When i run my application on the tablet(android) and hit the pause button it pauses the screen of the video but the video will jump a head how ever many seconds the pause when i un-pause the video. So if i start the video and then click pause and walk away i can come back and un-pause the video and it well jump right to the end.
The code i am using is ns.togglePause(); This same code works on the desktop and works with .flv and .f4v but will not work when i am using a mp4 on the tablet.
Has anyone seen this before or know why it would do something like this?
i am using flashdevelop to debug the application.
I found out that my problem is caused by encoding. This helped me solve my problem.I found this on adobes forms.
Video encoding is very important.
For example, use baseline profile level 3.1 for H264 for mobile
(and not High profile level 4.1 recommended for desktop).
For more information, see the MAX session of Fabio Sonnati:
"Encoding for Performance on Multiple Devices"
And if you have an Android phone/tablet, there is my AIR application
to watch Adobe MAX 2011 videos :
https://market.android.com/details?id=air.fr.inway.maxVideos2011
Search "Sonnati" for this session's video.
(For info, i use a video player based on OSMF 1.6)
The pdf presentation is available on Sonmati's blog:
http://sonnati.wordpress.com/