From 977d3f6bdaddb41cf0abce87793cdd16c651920a Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 24 Oct 2018 13:42:11 +0200 Subject: [PATCH] fixed bug in re encode script --- tools/re-encode_mp4.php | 44 ++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/tools/re-encode_mp4.php b/tools/re-encode_mp4.php index 1cf4122..e54cc8e 100644 --- a/tools/re-encode_mp4.php +++ b/tools/re-encode_mp4.php @@ -59,21 +59,41 @@ if(count($localfiles)==0) exit('No MP4 files found'."\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"; foreach($localfiles as $hash) { - $img = $dir.$hash.DS.$hash; + $mp4 = $dir.$hash.DS.$hash; $tmp = ROOT.DS.'tmp'.DS.$hash; - if(file_exists($tmp) && $allowskipping==true) - echo "Skipping $hash\n"; - else - { - $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"; - echo " [i] Converting $hash"; - system($cmd); - if(defined('ALT_FOLDER') && ALT_FOLDER && isdir(ALT_FOLDER)) - copy($img,ALT_FOLDER.DS.$hash); - echo "\tdone\n"; - } + $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 " [i] Converting '$hash'"; + system($cmd); + if(defined('ALT_FOLDER') && ALT_FOLDER && is_dir(ALT_FOLDER)) + copy($mp4,ALT_FOLDER.DS.$hash); + echo "\tdone\n"; }