douke7274
2016-01-18 03:47
浏览 122
已采纳

PHP ffmpeg输出位置

My website allow users to upload video files to the server. Original file will be move to folder "Original" ffmpeg will compress the video and store the video in 480p folder. how to i setup ffmpeg so that it will store output of the compressed video file into original/480p?

Partial code of upload.php

$target_dir = "Original/"; //where you want to upload the files to
$target_file = $target_dir.basename($_FILES['file']['name']);
$fileType = pathinfo($target_file, PATHINFO_EXTENSION);
$newFileName = $target_dir.sha1(pathinfo(basename($_FILES['file']['name']), PATHINFO_FILENAME)).'480p'.'.'.$fileType;
//$newFileName = $target_dir.sha1(pathinfo(basename($_FILES['file']['name']), PATHINFO_FILENAME)).'-'.time().'.'.$fileType;
move_uploaded_file($_FILES['file']['tmp_name'], $newFileName);

using this FFMPEG command

shell_exec("C:\\ffmpeg\\bin\\ffmpeg.exe -y -i ".$newFileName." -c:v libx264 -s:v 854x480 -c:a copy \"480p\\{$newFileName}\" > logfile.txt 2>&1");

i get the error 480p\Original/ffbaf58f1231628f9ac2a583f038b51719006ec6480p.mp4: No such file or directory

i will like the output to be stored in original/480p/compressed-video-file

图片转代码服务由CSDN问答提供 功能建议

我的网站允许用户将视频文件上传到服务器。 原始文件将移动到文件夹“原始”ffmpeg将压缩视频并将视频存储在480p文件夹中。 如何设置ffmpeg以便将压缩视频文件的输出存储为原始/ 480p?

upload.php的部分代码

  $ target_dir =“Original /”;  //你想把文件上传到
 $ target_file = $ target_dir.basename($ _ FILES ['file'] ['name']); 
 $ fileType = pathinfo($ target_file,PATHINFO_EXTENSION); 
 $  newFileName = $ target_dir.sha1(pathinfo(basename($ _ FILES ['file'] ['name']),PATHINFO_FILENAME))。'480p'。'。'。$ fileType; 
 // $ newFileName = $ target_dir。  sha1(pathinfo(basename($ _ FILES ['file'] ['name']),PATHINFO_FILENAME))。' - '。time()。'。'。$ fileType; 
move_uploaded_file($ _ FILES ['file'] [  'tmp_name'],$ newFileName); 
   
 
 

使用此FFMPEG命令

  shell_exec(“C:\  \ ffmpeg \\ bin \\ ffmpeg.exe -y -i“。$ newFileName。” -  c:v libx264 -s:v 854x480 -c:copy \“480p \\ {$ newFileName} \”> logfile。  txt 2>& 1“); 
   
 
 

我收到错误 480p \ Original / ffbaf58f1231628f9ac2a583f038b51719006ec6480p.mp4:没有这样的文件或目录 \ n

我希望输出存储在原始/ 480p /压缩视频文件中

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duan7664 2016-01-18 03:59
    已采纳

    First you will need to create a folder in your server: original/480p
    Then change the code to:

    $target_dir = "original/"; //where you want to upload the files to
    $target_file = $target_dir.basename($_FILES['file']['name']);
    $fileType = pathinfo($target_file, PATHINFO_EXTENSION);
    $newFileName = $target_dir.'/480p/'.sha1(pathinfo(basename($_FILES['file']['name']), PATHINFO_FILENAME)).'480p'.'.'.$fileType;
    //$newFileName = $target_dir.sha1(pathinfo(basename($_FILES['file']['name']), PATHINFO_FILENAME)).'-'.time().'.'.$fileType;
    move_uploaded_file($_FILES['file']['tmp_name'], $newFileName);
    

    FFmpeg command:

    shell_exec("C:\\ffmpeg\\bin\\ffmpeg.exe -y -i ".$target_file.".".$fileType." -c:v libx264 -s:v 854x480 -c:a copy \"{$newFileName}\" > logfile.txt 2>&1");
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题