FFmpeg不工作

时间:2013-07-12 21:44:43

标签: ffmpeg

我拥有与youtube类似的网站www.goploom.com,允许用户上传和观看视频。上传的视频将转换为mp4格式,以便与我们网站的html5视频播放器兼容。我的问题是,虽然FFmpeg成功地从上传的视频生成视频缩略图并将图像存储在正确的目录中,但我的代码的视频转换方面不会产生任何输出。我已将代码调整了几个小时,但我无法解决此问题,但是,我被告知我可以使用html,php和ffmpeg执行视频转换。

我的ffmpeg路径是正确的,因为缩略图生成工作正常。

**上传时从上传的视频中收集的信息。                     $ name = $ _FILES ['video'] ['name'];                     $ title = $ _POST ['videotitle'];                     $ type = explode('。',$ name);
                    $ type = end($ type);                     $ size = $ _FILES ['video'] ['size'];                     $ random_name = rand();                     $ tmp = $ _FILES ['video'] ['tmp_name'];

                if($type != 'mp4' && $type != 'MP4' && $type != 'flv' && $type != 'FLV' && $type != 'mov' && $type != 'MOV'){
                    $message = "Video Format Not Supported<br>";
                } else {
            $username_query = mysql_query("SELECT `username` FROM `users` WHERE `user_id` = $session_user_id");
                    $username = mysql_fetch_assoc($username_query); 
                    $username = $username['username'];

**缩略图生成完美无缺。                         $ ffmpeg =“/ usr / local / bin / ffmpeg”;                         $ videoFile = $ _FILES ['video'] ['tmp_name'];                         $ imageFile =“uploads /".$ username。”/ thumbnails /".$ random_name。“。jpg”;                         $ size =“160x90”;                         $ getFromSecond = 5;                         $ cmd =“$ ffmpeg -i $ videoFile -an -ss $ getFromSecond -s $ size $ imageFile”;                         如果(!了shell_exec(CMD $)){                             echo“Thumbnail Created!
”;
                        } else {                             echo“创建缩略图时出错!”;                         }

**将上传的文件移动到其永久目录以进行视频转换。                         $ newFileLocation =“uploads /".$ username。”/ temp“。$ random_name。”。“。$ type;                         move_uploaded_file($ tmp,$ newFileLocation);

*视频转换代码。                         $ outputFile =“uploads /".$ username。”/“。$ random_name。”。mp4“;                         $ databaseStoredVideoUrl =“uploads /".$ username。”/“。$ random_name。”。mp4“;                         $ video_cmd =“$ ffmpeg -i $ newFileLocation $ outputFile”;                         echo $ video_cmd;                         如果(!了shell_exec(video_cmd $)){                             echo“Video Converted!
”;                         } else {                             echo“创建缩略图时出错!”;
                        }

**正确地将输出src链接存储在数据库中,但由于视频不存在,因此无法查看该视频。                         //视频存储到正确的用户名和用户目录下的数据库中                         mysql_query(“INSERT INTO videos VALUES('$ session_user_id','','$ name','$ outputFile','$ title','','$ imageFile')”);                         $ message =“视频上传成功。
”;

任何帮助或见解都会很棒。 感谢。

**编辑:使用以下行修复。 $ video_cmd =“$ ffmpeg -i $ newFileLocation -vcodec libx264 -vpre normal -acodec libfaac $ outputFile”;

然后将$ video_cmd输入shell_exec

1 个答案:

答案 0 :(得分:0)

说不上。 我自己使用FFMPEG和PHP几次,你可能遇到的一些问题如下:

  1. 内存限制,因为它似乎正在运行视频编码服务器端,我宁愿不推荐。
  2. 其次,ffmpeg进程本身可能需要很长时间,因为视频对话的执行需要多长时间才能完成Web服务器Apache / Nginx允许的最大脚本执行。
  3. 如果您正在将编码作为Web请求运行,您应该避免这样做,而是创建一个cron作业或一个单独的服务来检查是否有任何应该处理和编码的新视频(视频队列服务)。 / p>

    确保这大致的步骤:

    1. 首先直接从cmdline测试您的编码。
    2. 更新您的视频表并标记应处理的视频表,或制作视频队列表。
    3. 拥有一个cron作业或服务,检查要处理的新视频,然后逐个处理。
    4. 如果您对PHP最熟悉,请使用ini_set(“set_time_limit”,0)创建一个php脚本,以确保脚本不会超时。其他选项可以是bash脚本,或者例如使用node.js以及foreverffmpeg library来创建处理服务。