Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play mp4 video file with HTML5 video tag on iOS (iPhone and iPad)?

I want to display HTML5 video to my users using the video tag. For Firefox, Chrome and Opera WEBM works as expected. In Safari on Windows and Mac my MP4 version works, too. The only problem I'm experiencing is, that it won't play on iPad and iPhone (Safari of course).

Create video

The MP4 (h.264 + acc-lc) is converted like this (with profile: baseline and level 3.0 for maximum compatibility with iOS):

  • Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x352, 198 kb/s, 17 fps, 17 tbr, 17408 tbn, 34 tbc (default)
  • Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 56 kb/s (default)

Edit: Whole ffprobe output (slight changes in bitrate etc. to the above mentioned):

Metadata:
major_brand     : isom
minor_version   : 512
compatible_brands: isomiso2avc1mp41
encoder         : Lavf56.30.100
Duration: 00:01:00.05, start: 0.046440, bitrate: 289 kb/s
Stream #0:0(eng): Video: h264 (Constrained Baseline) 
(avc1 /0x31637661), yuv420p, 640x352, 198 kb/s, 25 fps, 25 tbr, 
12800 tbn, 50 tbc (default)
Metadata:
  handler_name    : VideoHandler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, 
stereo, fltp, 85 kb/s (default)
Metadata:
  handler_name    : SoundHandler

I found various requirements for iOS devices like this and this, also someone mentioned to add the yuv420p pixel format when converting.

In fact the ffmpeg cmd looks like this:

ffmpeg -i __inputfile__ -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level 3.0 -b:v 200K -r 17 -bt 800K -c:a libfdk_aac -b:a 85k -ar 44100 -y __outputfile_lowversion__.mp4

Display video

With Modernizr I detect which format is "supported" and add it to the src or the video tag. Last thing is adding the right MIME type. For mp4 I add type="video/mp4". The full code for the video tag is:

<video class="p-video" preload="auto" autoplay="" type="video/mp4" src="http://full.url/to/video_low.mp4"/>

I tried various ways: own implementation with own interface, controls and stuff from browser vendors and video.js just to check whether i'm too studip for this. All work in the environments listed above except for iPhone and iPad.

I read this article on Video on the web, especially this part and only serve the "right" file with the "right" type without a posterattribute set.

My Apache has

AddType video/mp4                      mp4 m4v f4v f4p
AddType video/ogg                      ogv
AddType video/webm                     webm

And byte-ranges are enabled. This is needed to get partial content from the server.

Has anyone a clue what's going on there? Thanks in advance!

Edit: Safari and Chrome both throw MEDIA_ERR_SRC_NOT_SUPPORTED Error on iPad. There must be an issue with the encoding.

like image 261
Marc Saleiko Avatar asked Apr 17 '15 09:04

Marc Saleiko


1 Answers

Try toggling 'controls' attribute - or define src differently.

 <video src="http://example.com/path/mymovie.mov"
         controls
         height=340 width=640
         poster="http://example.com/path/poster.jpg">
  </video>

Check out this article 'About HTML5 Audio and Video for Safari' (developers guide)

Also, a nice stable assistance to the HTML5 <video> tag for iPad / iPhone is JW player. (works with it)

 jwplayer('video').setup({
     flashplayer: '/Scripts/jwplayer/player.swf',
     file: 'seanpenn.mp4',
     autostart: false,
     controlbar: 'over',
     image: 'spicoli.jpg',
     width: 295,
     height: 214,
     skin: '/Scripts/jwplayer/glow.xml',
     stretching: 'exactfit'
 });
like image 194
fred randall Avatar answered Oct 14 '22 20:10

fred randall