fixed bug in re encode script

This commit is contained in:
Chris
2018-10-24 13:42:11 +02:00
parent e57360bcfc
commit 977d3f6bda

View File

@@ -59,21 +59,41 @@ if(count($localfiles)==0) exit('No MP4 files found'."\n");
echo "[i] Got ".count($localfiles)." files\n"; echo "[i] Got ".count($localfiles)." files\n";
//TESTING
echo "[i] Checking hashes for wrongly encoded ones\n";
foreach($localfiles as $akey => $hash)
{
$mp4 = $dir.$hash.DS.$hash;
$cmd = ROOT.DS.'bin'.DS."ffmpeg -i $mp4 -hide_banner 2> ".ROOT.DS.'tmp'.DS.$hash.'.txt';
system($cmd);
$results = file(ROOT.DS.'tmp'.DS.$hash.'.txt');
foreach($results as $l)
{
$elements = explode(':',trim($l));
$key=trim(array_shift($elements));
$value = trim(implode(':',$elements));
if($key=='encoder')
{
if(startsWith(strtolower($value),'lav'))
{
echo " [i] Removing $hash because it's already correctly encoded\n";
unset($localfiles[$akey]);
}
}
}
}
echo "[i] Starting to convert\n"; echo "[i] Starting to convert\n";
foreach($localfiles as $hash) foreach($localfiles as $hash)
{ {
$img = $dir.$hash.DS.$hash; $mp4 = $dir.$hash.DS.$hash;
$tmp = ROOT.DS.'tmp'.DS.$hash; $tmp = ROOT.DS.'tmp'.DS.$hash;
if(file_exists($tmp) && $allowskipping==true) $cmd = ROOT.DS.'bin'.DS."ffmpeg -loglevel panic -y -i $mp4 -vcodec libx264 -an -profile:v baseline -level 3.0 -pix_fmt yuv420p -vf \"scale=trunc(iw/2)*2:trunc(ih/2)*2\" $tmp && cp $tmp $mp4";
echo "Skipping $hash\n"; echo " [i] Converting '$hash'";
else system($cmd);
{ if(defined('ALT_FOLDER') && ALT_FOLDER && is_dir(ALT_FOLDER))
$cmd = ROOT.DS.'bin'.DS."ffmpeg -loglevel panic -y -i $img -vcodec libx264 -an -profile:v baseline -level 3.0 -pix_fmt yuv420p -vf \"scale=trunc(iw/2)*2:trunc(ih/2)*2\" $tmp && cp $tmp $img"; copy($mp4,ALT_FOLDER.DS.$hash);
echo " [i] Converting $hash"; echo "\tdone\n";
system($cmd);
if(defined('ALT_FOLDER') && ALT_FOLDER && isdir(ALT_FOLDER))
copy($img,ALT_FOLDER.DS.$hash);
echo "\tdone\n";
}
} }