简体   繁体   English

在PHP中通过ffmpeg命令从avi文件转换为mp4文件

[英]To convert from avi file to mp4 file by ffmpeg command in php

The ffmpeg command in php below creates mp4 file from avi file without deleting the original avi file meaning that,for example, there are two files, 1221222.avi and 1221222.mp4 exist in the directry after all. 下面的php中的ffmpeg命令从avi文件创建mp4文件而不删除原始avi文件,这意味着,例如,该目录中毕竟存在两个文件1221222.avi和1221222.mp4。

('for i in /xxxxx/xxxxxx/*.avi; do ffmpeg -i "$i" -frames:v 1 "/xxxxx/xxxxxx/$(basename "$i" .avi).mp4"; done') (“对于/xxxxx/xxxxxx/*.avi中的i;执行ffmpeg -i“ $ i” -frames:v 1“ / xxxxx / xxxxxx / $(基本名称“ $ i” .avi).mp4”;完成”)

I'd like to delete this 1221222.avi file right after the command created 1221222.mp4 file. 我想在命令创建1221222.mp4文件后立即删除此1221222.avi文件。

Is there any command that converts the file from avi to mp4 by replacing it? 是否有任何命令通过替换将文件从avi转换为mp4? Or do I have to add delete command after the command above? 还是我必须在上述命令后添加delete命令?

I would appreciate if anyone could help me out for the command. 如果有人可以帮助我,我将不胜感激。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Even though the php script below can upload avi file from local drive to application I'm currently developping, the avi will not be played at html. 即使下面的php脚本可以将avi文件从本地驱动器上传到我当前正在开发的应用程序中,该avi也不会在html上播放。 So, I'm trying to convert from the avi file to mp4 file which is working fine by using ffmpeg command in php. 因此,我正在尝试从avi文件转换为mp4文件,通过在php中使用ffmpeg命令可以正常工作。 This ffmpeg command creates mp4, but the html still do not play it. 此ffmpeg命令可创建mp4,但html仍不会播放。 Is it because the original avi file still exists in the directory? 是因为原始avi文件仍然存在于目录中吗?

//php
case "video/x-msvideo":

if($header){
    header("Content-Type: video/x-msvideo");

 $dst_im = copy($path, $dst_file);
 return "";
 }else{ 

 $dst_file = $dst_file . ".avi";
 shell_exec('for i in  /xxxxxx/xxxxxx/*.avi; do ffmpeg -i "$i" - frames:v 1 "/xxxxxx/xxxxxx/$(basename "$i"  .avi).mp4"; done');      

 $dst_im = copy($path, $dst_file);
 }
 unlink($dst_im);
 break; 


//html
<video width="500"  height="250"  id="bgvid" poster="video.jpg"    controls="controls" preload="auto" autoplay>
<source type="video/mp4" src="xxxxxxxxxxxxxxxxxxxxx.mp4" />
</video>

There is no such operation, you can just append a bash command like 没有这样的操作,您可以追加一个bash命令,例如

rm filename.mp4

to the script or you remove the file through php with 到脚本或您通过php通过删除文件

unlink($filepath);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM