FFMPEG没有创建缩略图和转换视频

时间:2014-06-10 06:27:39

标签: php ffmpeg

  

这是我在阅读了许多博客和关于FFMPEG后编码的内容

 $ffmpeg = "C:\\FFMPEG\\bin\\ffmpeg";
 $video_file_path = $_FILES["file"]["name"];
 $converted_video_path = "converted_videos/" . $video_file_path;
 $image = $name .".jpg";
 $imagepath="thumbnail/" . $image;
 echo "<br>";
 echo $video_file_path; echo "<br>";echo "<br>";
 echo $converted_video_path; echo "<br>";echo "<br>";
 echo $image; echo "<br>";echo "<br>";
 echo $imagepath; 
 $size = "120x90";  
 $getFromSecond = 6;

 $cmd_thumbnail_create = ("$ffmpeg -i  C:\\xampp\\htdocs\\Media Barron\\assets\\uploaded_videos\\$video_file_path   -an -ss $getFromSecond -s $size C:\\xampp\\htdocs\\Media Barron\\assets\\thumbnail\\$image");

 $cmd_video_conversion = exec("$ffmpeg -i $video_file_path -qscale 4 -vcodec libx264 -f mp4 $converted_video_path.mp4");

 shell_exec($cmd_thumbnail_create);
 shell_exec($cmd_video_conversion);
  

PS:我之前的地址上有双引号,还累了“\ uploaded_videos \ video_file_path”,“uploaded_videos \ video_file_path”,单引号,“\ C:\ xampp \ htdocs \ Media Barron \ assets \ uploaded_videos \ $ video_file_path \“

     

这是我最近尝试过的新脚本

  <?php
  $ffmpeg = "C:\\FFMPEG\\bin\\ffmpeg";                                 
  $video_file_path = $_FILES["file"]["name"];               
  $ffmpegVideoLocation = "C:\\xampp\\htdoc\\Media  Barron\\uploaded_videos\\".$video_file_path;
  $converted_video_path = "C:\\xampp\\htdoc\\Media Barron\\converted_videos\\" . $video_file_path;
  $image = $name .".jpg";
  $imagepath="thumbnail\\" . $image;
echo "<br>";
echo $video_file_path; echo "<br>";echo "<br>";
echo $ffmpegVideoLocation; echo "<br>";echo "<br>";
echo $converted_video_path; echo "<br>";echo "<br>";
echo $image; echo "<br>";echo "<br>";
echo $imagepath; 
$size = "120x90";   
$getFromSecond = 6;


$cmd_thumbnail_create = ("$ffmpeg -i $ffmpegVideoLocation  -an -ss $getFromSecond -s $size  $converted_video_path.jpg"); 
$cmd_video_conversion = exec("$ffmpeg -i $ffmpegVideoLocation -qscale 4 -vcodec libx264 -f mp4 $converted_video_path.mp4");

   shell_exec($cmd_video_conversion);

shell_exec($cmd_thumbnail_create);

enter image description here

1 个答案:

答案 0 :(得分:0)

您是否尝试使用命令提示符下的命令转换并生成该文件? 或者是否有任何错误消息?

<强>更新

我试过你的代码。

$cmd_video_conversion返回null。因为你的命令中有exec()函数。 我删除它然后它完美地工作。

在我的测试脚本下面。     

$ffmpeg = "D:\\FFMPEG\\bin\\ffmpeg.exe";
echo "<br><br>--->ffmpeg = ".$ffmpeg;
echo "<br>--->file_exists =  ".file_exists($ffmpeg);

//$video_file_path = $_FILES["file"]["name"]; 
$video_file_path = "sample.mp4";
echo "<br><br>--->filename = ".$video_file_path;

//$ffmpegVideoLocation = "C:\\xampp\\htdoc\\Media  Barron\\uploaded_videos\\".$video_file_path; 
$ffmpegVideoLocation = getcwd().DIRECTORY_SEPARATOR."uploaded".DIRECTORY_SEPARATOR.$video_file_path;
echo "<br><br>--->filepath = ".$ffmpegVideoLocation;
echo "<br>--->file_exists =  ".file_exists($ffmpegVideoLocation);


//$converted_video_path = "C:\\xampp\\htdoc\\Media Barron\\converted_videos\\" . $video_file_path;
$converted_video_path = getcwd().DIRECTORY_SEPARATOR."converted".DIRECTORY_SEPARATOR.$video_file_path;
echo "<br><br>--->converted =  ".$converted_video_path;
echo "<br>--->file_exists =  ".file_exists($converted_video_path);

//$image = $name.".jpg";
$image = "thumbnail.jpg";
echo "<br><br>--->thumb names =  ".$image;

//$imagepath= "thumbnail\\".$image;
$imagepath= getcwd().DIRECTORY_SEPARATOR."converted".DIRECTORY_SEPARATOR.$image;
echo "<br><br>--->thumb path =  ".$imagepath;
echo "<br>--->file_exists =  ".file_exists($imagepath);

$size = "120x90";
echo "<br><br>--->size =  ".$size;

$getFromSecond = 6;
echo "<br><br>--->getFromSecond =  ".$getFromSecond;

$cmd_thumbnail_create = ("$ffmpeg -i $ffmpegVideoLocation  -an -ss $getFromSecond -s $size  $imagepath.jpg");
echo "<br><br>--->command create thumb =  ".$cmd_thumbnail_create;

$cmd_video_conversion = ("$ffmpeg -i $ffmpegVideoLocation -qscale 4 -vcodec libx264 -f mp4 $converted_video_path.mp4");
echo "<br><br>--->command convert =  ".$cmd_video_conversion;

$exe1 = shell_exec($cmd_video_conversion);
echo "<br><br>--->process 1 =  ".$exe1;

$exe2 = shell_exec($cmd_thumbnail_create);
echo "<br><br>--->process 2 =  ".$exe2;

?>