PHP HTML5兼容MP4视频使用FFMPEG [英] PHP HTML5 compatible MP4 video using FFMPEG

查看:250
本文介绍了PHP HTML5兼容MP4视频使用FFMPEG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  echo转换练习开始...< BR /><峰; br />中; 

/ *循环遍历目录中的所有文件* /
if($ handle = opendir('assets / uploaded_videos')){
while(false!==新评新新新新新新旗新新新旗新新新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新新新新新新新新p新新新新新新新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新新新新旗新新新新新旗新新新新旗新新旗新新旗新新旗新新新200新新新新新新新新p45 && in_array(substr($ entry,strrpos($ entry,'。')),array(.wmv,.mpg,.mpeg,.flv,.ogg .mp4)))
{
$ filename = substr($ entry,0,strrpos($ entry,'。'));

// $ command =ffmpeg -i assets / uploaded_videos / $ entry -vcodec libx264 assetss / videos / $ filename.mp4;

$ command =ffmpeg -i assets / uploaded_videos / $ entry -vcodec mpeg4 -acodec libfaac files / videos / $ filename.mp4;

echo $ command。< br />;

shell_exec($ command。> / dev / null 2> / dev / null&);
}
}
closedir($ handle);
}

我已经将播放器嵌入视图文件,如下所示:

 < video width =350poster =<?php echo $ first_video ['thumb_path'];?&控制> 
< source src =<?php echo $ first_video ['video_path'];?> />
< span id =silverlight_player_for_fallback>< / span>
< / video>

现在,当我在IE10中运行时,播放器给我无效源错误。我有这个问题与 libx264 mpeg4 MP4编解码器。


$ b $新评新新新旗新新新新旗新新旗旗新新旗新新旗新新旗旗新新旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新旗旗新新旗旗新新旗旗新新旗旗新旗旗新新旗旗新新旗旗新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新旗旗新旗旗新新新新新旗新新旗200新新200新200新新旗200新新200新200新200新新旗200 200 200新新新新旗新新旗200新新200新200新新200新200新新旗200新新200新200新新200新200新新旗200新新200新200新新200新200新新旗200新新200新200新新200新200新新旗200新新200新200新新200新新200新200新新旗200新新200新200新新新200新新。我已经使用 baseline-level3 配置文件与 libx264 。您可以提供额外的参数,但我猜是个人资料是关键!我尝试了几个配置文件,并观察到vimeo和youtube上的所有HTML5视频都使用此基准L3配置文件。的用户不45200 200 200 200 200 200 -40 200 200 200 -40 -40 200 200 200 -40 -40 200 200 -40 200 200 200 -40 200 200 200 200 200 200: > / *以下命令将所有上传的* .wmv文件转换为mp4 * /
$ command =ffmpeg -i files / uploaded_videos / $ entry -vcodec libx264 -profile:v baseline -level 3个文件/视频/ $ filename.mp4\" ;你在其他浏览器中测试了生成的MP4文件(/支持MP4),如Chrome和Safari?新新新新旗新新新旗新新旗新新旗新新旗新新旗旗新新旗新新200新200新新新新旗新新旗200新新新旗新新旗200新新新旗新200旗新200旗新200旗新200新新旗新新旗200新新新旗新200旗新200旗新200新新旗新新旗200 200 200 200 200 200 200 200 200 -40 -40 200 200 -40 200 200 -40 200 200 -40 -40 200 200 -40 200 200 -40 200 200 -40 -40 200 200 -40 200 200 -40 -40 200 200 -40 200 200 -40 200 200 200 -40 200 200 200 -40 -40 200 200浏览器),看看它是否可以播放。这样,您可以尝试查看是否是编码的问题。



有许多不同的风格(称为个人资料),并不都可以在浏览器中播放。


Hi I am using FFMPEG to convert the uploaded video with PHP.

echo "conversion exercise started...<br/><br/>";

/* looping through all files in the directory */
if ($handle = opendir('assets/uploaded_videos')) {
    while (false !== ($entry = readdir($handle))) {

        /* filtering the desired extensions */
        if ($entry != "." && $entry != ".." && in_array(substr($entry, strrpos($entry, '.')), array(".wmv", ".mpg", ".mpeg", ".flv", ".ogg", ".mp4")))
        {
            $filename = substr($entry, 0, strrpos($entry, '.'));

            //$command = "ffmpeg -i assets/uploaded_videos/$entry -vcodec libx264 assetss/videos/$filename.mp4";

            $command = "ffmpeg -i assets/uploaded_videos/$entry -vcodec mpeg4 -acodec libfaac files/videos/$filename.mp4";

            echo $command."<br />";

            shell_exec($command."> /dev/null 2>/dev/null &");
        }
    }
    closedir($handle);
}

I have embedded the player in view file like this:

<video width="350" poster="<?php echo $first_video['thumb_path'];?>" controls>
    <source src="<?php echo $first_video['video_path']; ?>" />
    <span id="silverlight_player_for_fallback"></span>
</video>

Now, when I run in IE10, the player gives me invalid source error. I am having this issue with both libx264 and mpeg4 MP4 codecs.

Any ideas whats going wrong?

Update

Following Ian's direction, I finally get it working. I have used baseline-level3 profile with libx264. You can provide extra parameters but I guess profile is the key! I experimented couple of profiles and observed that all HTML5 videos on vimeo and youtube use this baseline L3 profile.

Anyone struggling with MP4 can consider the following command for conversion:

/* following command converted all my uploaded *.wmv files to mp4 */
$command = "ffmpeg -i files/uploaded_videos/$entry -vcodec libx264 -profile:v baseline -level 3 files/videos/$filename.mp4";

解决方案

Have you tested the generated MP4 file in other browsers (that support MP4) such as Chrome and Safari? The first step is to ensure that the file actually plays.

You could also save the generated MP4 and try and drag it into Chrome/Safari and then IE10 (if the other browser works) to see if it can play. This way you can attempt to see if it's the encoding that's the issue.

There are many different flavours (known as profiles) of MP4, not all can play in browsers.

这篇关于PHP HTML5兼容MP4视频使用FFMPEG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆