Last active
November 25, 2020 03:22
-
-
Save stephenjtong/9992ee9767c625f1323efa43c8771681 to your computer and use it in GitHub Desktop.
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
<?php | |
$file = $argv[1]; | |
$ffmpeg = './ffmpeg'; | |
if(empty($file)){ | |
die('no file provide'); | |
} | |
$length = shell_exec("$ffmpeg -i $file 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,//"); | |
$length = trim($length); | |
//copy会产生前几帧跳帧,多截20秒 | |
$length = strtotime("1970-01-01 $length UTC") + 20; | |
$info = shell_exec("$ffmpeg -i $file 2>&1 | perl -lane 'print $1 if /([1-9]\d+x\d+)/'"); | |
$info = trim($info); | |
list($width, $height) = explode('x', $info); | |
shell_exec("$ffmpeg -y -i $file -vf hflip -c:a copy ${file}_OUTPUT.mp4"); | |
shell_exec("mv ${file}_OUTPUT.mp4 $file"); | |
$start_m = mt_rand(0,45); | |
$start_s = mt_rand(0,59); | |
shell_exec("$ffmpeg -y -i overlay.mp4 -ss $start_m:$start_s -t $length -c copy ${file}_overlay.mp4"); | |
//-10TB,overlay从第10秒开始截取,防止前几帧跳帧 | |
shell_exec("$ffmpeg -y \ | |
-i $file -i ${file}_overlay.mp4 \ | |
-filter_complex \" \ | |
[0:v]setpts=PTS-STARTPTS[top]; \ | |
[1:v]setpts=PTS-10/TB, \ | |
scale=$width:$height, | |
format=yuva420p,colorchannelmixer=aa=0.02[bottom]; \ | |
[top][bottom]overlay=eof_action=endall\" \ | |
-vcodec libx264 ${file}_out.mp4"); | |
shell_exec("rm ${file}_overlay.mp4"); | |
shell_exec("mv ${file}_out.mp4 $file"); | |
/* | |
shell_exec("echo 'file $file | |
file tail.mp4' | \ | |
$ffmpeg -safe 0 -protocol_whitelist file,pipe,http,https,tcp,tls -f concat -i - ${file}_OUTPUT.mp4"); | |
shell_exec("$ffmpeg -y -i ${file}_OUTPUT.mp4 $file"); | |
shell_exec("rm ${file}_OUTPUT.mp4"); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment