Wednesday, August 20, 2014

Video is not streaming in Safari and Iphone

This may happen due to

RequestHeader unset Range
Header unset Accept-Ranges



>>Why do we need above configuration?
We do this to fix "Range header DoS vulnerability Apache HTTPD 1.3/2.x" issue. For details please check @ http://people.apache.org/~dirkx/CVE-2011-3192.txt



>>Does iPhone/iPad Safari require 'Accept-Ranges' header for video?
Yes. It requires these headers.Please find the apple documentation for the same.
"
https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariWebContent/CreatingVideoforSafarioniPhone/CreatingVideoforSafarioniPhone.html#//apple_ref/doc/uid/TP40006514-SW6
"



>>Any other solution?
Actually we can use another fix as suggested @ http://people.apache.org/~dirkx/CVE-2011-3192.txt . It is as below.

"
SetEnvIf Range (,.*?){5,} bad-range=1
RequestHeader unset Range env=bad-range
"

Here we are rejecting request when more than 5 ranges. But we can put very high value too.Please check these lines in same document.

"
The number 5 is arbitrary. Several 10's should not be an issue and may be
required for sites which for example serve PDFs to very high end eReaders
or use things such complex http based video streaming.
"

We will enable "Accept-Ranges" at .htaccess file for .mp4 videos only as below.

"

Header set Accept-Ranges bytes

"

other ffmpeg help link-
https://sites.google.com/site/linuxencoding/x264-ffmpeg-mapping
http://www.itbroadcastanddigitalcinema.com/ffmpeg_howto.html



Issue 1: Audio was not playing
Cause: Sample rate of the audio file did not match with the sample rate of the video.
Fix:
Check videos sample rate-- ffmpeg -i video.mp4
Use the flag -ar to specify Sample rate of audio.


Issue 2: Video was not streaming.
~~~~~: Video should be "Progressive" in nature. Video should provides its meta info at the beginning so that it playback as soon as possible.
Fix:
Use the following command:

qt-faststart output.mp4 output1.mp4

----------------------------

Final commands:
1) ffmpeg -i video.mp4 -i test.mp3 -vcodec copy -acodec aac -strict experimental -shortest output.mp4
2) qt-faststart output.mp4 output1.mp4