Created
June 22, 2015 06:35
-
-
Save arth2o/ced65bce081c163e3fb2 to your computer and use it in GitHub Desktop.
Batch video convert from flv to mp4 via Linux CMD use avconv binary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
$folder = dirname(__FILE__)."/"; | |
//or you can set this by manual | |
//$folder = "/var/www/lorem/ipsum/" | |
$outputFolder = "mp4/"; | |
$from = ".flv"; | |
$to = ".mp4"; | |
//enter to directory | |
chdir($folder); | |
/** | |
* Examples to convert and install | |
* # apt-get install libav-tools | |
* Convert a FLV file to MP4, preserving audio & video: | |
* $ avconv -i input.flv -codec copy output.mp4 | |
* To extract audio only: | |
* $ avconv -i input.flv -codec copy -vn output_a.mp4 | |
* To extract video only: | |
* $ avconv -i input.flv -codec copy -an output_v.mp4 | |
*/ | |
foreach(glob($folder.'*.[fF][lL][vV]') as $fileName){ | |
$file = str_replace($folder, "", $fileName); | |
$correctedFileName = (strtolower(str_replace(" ", "_", $file))); | |
$newFileName = str_replace(array($from, " "), array($to, "\ "), $correctedFileName); | |
rename($file, $correctedFileName); | |
$result = false; | |
$status = false; | |
//sudo apt-get install avconv | |
$command = "avconv -i {$correctedFileName} -codec copy {$outputFolder}/{$newFileName}"; | |
$escaped_command = escapeshellcmd($command); | |
exec($escaped_command, $result, $status); | |
var_dump($file, $correctedFileName, $newFileName, $escaped_command, $result, $status);echo "\n\n\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment