Drupalist Drupalist - 4 months ago 15
HTML Question

PHP&FFMPEG, How to make sure the result video is suitable for web browsers?

I need to split a section of a video, paste a logo and also blur a video online. I know how to do these but the problem is, I don't know how to make sure that the result video is suitable for web. For example there is a

mp4
video in my website which is playing via the browser, and using this code I cut a section of it:

exec("ffmpeg -i ".$source." -ss ".$start." -to ".$end." -c copy ".$newVideo);


The problem is, when the distance between
$start
and
$end
is more than a few minutes, the split operation is done but it is not played via browser.

What codec or library do I need to add as filter to make sure that the result video is always playing on all modern browsers?

Answer

Use

exec("ffmpeg -i ".$source." -ss ".$start." -to ".$end." -movflags +faststart  ".$newVideo);

for a precise cut. This command will transcode the video.


Use

exec("ffmpeg -i ".$source." -ss ".$start." -to ".$end."  -c copy -avoid_negative_ts make_zero -movflags +faststart ".$newVideo);

for a cut, without transcoding. But this will be imprecise, depending on where the keyframes are.