<?php
// voiceover.php
// RJM Programming
// May, 2023


$rs='';
$outf='';
if (isset($_GET['fcommand'])) {
   if (PHP_OS == "Darwin") {
    putenv('PATH=/usr/local/bin');
   }
   //file_put_contents('x.x', str_replace('+',' ',urldecode($_GET['fcommand'])));
   $cmdis=str_replace('+',' ',urldecode($_GET['fcommand']));
   $precmd=explode('>', $cmdis);
   $subcmd=explode('-shortest ', trim($precmd[0]));
   if (sizeof($subcmd) > 1) {
      $outf=$subcmd[1];
      if (file_exists($outf)) { 
       $wassuff='';
       while (file_exists($outf . '_was' . $wassuff)) {
         if ($wassuff == '') {
           $wassuff='0';
         } else {
           $wassuff='' . (1 + intval('' . $wassuff));
         }
       }
       rename($outf, $outf . '_was' . $wassuff); 
      }
   }
   if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
     $cmdis=str_replace(' > ', ' 2> ', $cmdis);
   } 
   $rs=shell_exec($cmdis);
   if ($outf != '') {
     if (file_exists($outf)) {
       $rs.='<br><br><video controls><source src="' . $outf . '" type="video/' . strtolower(explode('.', $outf)[-1 + sizeof(explode('.', $outf))]) . '"></source></video>';  
     }
   }
} else if (PHP_OS == "Darwin") {
   $rs='<details style=background-color:yellow;><summary style=background-color:lightblue;>Video and Audio Files ...</summary><br>' . str_replace("\n","<br>",shell_exec("file *.* | egrep -B 0 'ISO Media|Audio|WebM|Matroska|.ts:'")) . '</details>';
}


if (isset($_GET['infilegetsize'])) {
   exit;
}

if (isset($_GET['ffmpeg'])) {
  $fnd=false;
  if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
    if (file_exists('./ffmpeg.txt')) {
      $pplace=file_get_contents('./ffmpeg.txt');
      if (strpos($pplace, 'ffmpeg.exe') !== false) {
        $fnd=true;
      }
    }
    if (!$fnd) {
     $huhexe=shell_exec("where ffmpeg.exe");
     if ($huhexe == '') {
      $huhexes=rglob("C:\\ffmpeg.exe"); //shell_exec("where pdfimages.exe");
      if (sizeof($huhexes) > 0) {
       file_put_contents('./ffmpeg.txt', $huhexes[0]);
       if (strpos($huhexes[0], ' ') !== false) { 
       $huhexes[0]=str_replace('"','',$huhexes[0]);
       echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"fcommand\")) { if (1 == 1) { parent.document.getElementById(\"fcommand\").value=parent.document.getElementById(\"fcommand\").value.replace(parent.document.getElementById(\"fcommand\").value.split(\"ffmpeg.exe\")[0] + \"ffmpeg.exe\", String.fromCharCode(34) + \"" . str_replace("\\","\\\\",explode('ffmpeg.exe',$huhexes[0])[0]) . "ffmpeg.exe\").replace('.exe ','.exe' + String.fromCharCode(34) + ' '); } } }'></body></html>";
       } else {
       $huhexes[0]=str_replace('"','',$huhexes[0]);
       echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"fcommand\")) { if (1 == 1) { parent.document.getElementById(\"fcommand\").value=parent.document.getElementById(\"fcommand\").value.replace(parent.document.getElementById(\"fcommand\").value.split(\"ffmpeg.exe\")[0] + \"ffmpeg.exe\", \"" . str_replace("\\","\\\\",explode('ffmpeg.exe',$huhexes[0])[0]) . "ffmpeg.exe\").replace('.exe' + String.fromCharCode(34) + ' ', '.exe '); } } }'></body></html>";
       }
      }
     }
    }
  }
  exit;
}

$dn='';
$ffmpegpre='';
$ffmpegsuf='';
$whereffmpeg="?infilegetsize=";
if (PHP_OS == "Darwin") {
  $dn=' /dev/null';
} else if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
  $ffmpegpre="\"C:\\Program Files\\ImageMagick-7.1.0-Q16-HDRI\\";
  $ffmpegsuf=".exe\"";
  if (!file_exists($ffmpegpre . 'ffmpeg' . $ffmpegsuf)) {
   if (file_exists('./ffmpeg.txt')) {
     if (!file_exists(file_get_contents('./ffmpeg.txt'))) {
       unlink('./ffmpeg.txt');
       $whereffmpeg="?ffmpeg=where";
     } else {
       $ffmpegpre="\"" . str_replace('ffmpeg.exe','',file_get_contents('./ffmpeg.txt')) . "\"";
     }
   }
   if (file_exists('ffmpeg' . $ffmpegsuf)) {
    $ffmpegpre="";
   } else if (!file_exists('./ffmpeg.txt')) {
     $huhexe=shell_exec("where ffmpeg.exe");
     if (strpos($huhexe, 'ffmpeg.exe') === false) {
       $whereffmpeg="?ffmpeg=where";
     } else {
       $ffmpegpre=str_replace('ffmpeg.exe','',$huhexe);
     }
   }
  }
  $pdfimagespre="\"C:\\MAMP\\htdocs\\xpdf-tools-win-4.04\\bin32\\";
  $pdfimagessuf=".exe\"";
  if (!file_exists($pdfimagespre . 'pdfimages' . $pdfimagessuf)) {
   if (file_exists('./pdfimages.txt')) {
     if (!file_exists(file_get_contents('./pdfimages.txt'))) {
       unlink('./pdfimages.txt');
       $wherepdfimages="?pdfimages=where";
     } else {
       $pdfimagespre="\"" . str_replace('pdfimages.exe','',file_get_contents('./pdfimages.txt')) . "\"";
     }
   }
   if (file_exists('pdfimages' . $pdfimagessuf)) {
     $pdfimagespre="";
   } else if (!file_exists('./pdfimages.txt')) {
     $huhexe=shell_exec("where pdfimages.exe");
     if (strpos($huhexe, 'pdfimages.exe') === false) {
       $wherepdfimages="?pdfimages=where";
     } else {
       $pdfimagespre=str_replace('pdfimages.exe','',$huhexe);
     }
   }
  }
}

function ourshell_exec($onea, $twoa = NULL, $threea = NULL) {
   $folder='';
   $pattern=''; 
   $size='';
   $filesa=[];
   if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows' || (strpos(('~@!' . $onea), '~@!forfiles /P "') !== false && strpos(('~@!' . $onea), '/M "') !== false && strpos(('~@!' . $onea), 'find "') !== false)) {
     if (strpos(('~@!' . $onea), '~@!forfiles /P "') !== false && strpos(('~@!' . $onea), '/M "') !== false && strpos(('~@!' . $onea), 'find "') !== false) {
       $folder=explode('"', explode('forfiles /P "', $onea)[1])[0] . substr(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, 0, 1);
       if (strpos($folder, ' ') !== false) {  $folder='"' . $folder . '"';  }
       $pattern=explode('"', explode('/M "', $onea)[1])[0];
       if (strpos($pattern, ' ') !== false || substr(($folder . ' '),0,1) == '"') {  $pattern='"' . $pattern . '"'; if (substr(($folder . ' '),0,1) != '"') {  $folder='"' . $folder . '"';  }  }
       $size=explode('"', explode('find "', $onea)[1])[0];
       //$basis=str_replace('""','',$folder . str_replace(str_replace('"','',explode('.',$pattern)[0]),'*',$pattern));
       $basis=str_replace('""','',$folder . str_replace(str_replace('"','',explode('.',$pattern)[0]),str_replace(' ','*',str_replace('"','',explode('.',$pattern)[0])),$pattern));

       if (strpos($basis, ' ') === false) { $basis=str_replace('"','',$basis);  }
// file_put_contents('xs23.xs23', "swqzzui " . str_replace('""','',$folder . str_replace(str_replace('"','',explode('.',$pattern)[0]),'*',$pattern)) . ' ... ' . $basis . ' --- ' . str_replace('"','',$folder) . ' ' . str_replace('"','',$pattern) . ' ' . $size);
// exit;
       $filesa=scandir_through(str_replace('"','',$folder), str_replace('"','',$pattern), $size);
       if (sizeof($filesa) == 0) { return ''; }
       return $filesa[0];
       
       if (4 == 5) {
       
echo "bzmbvzqsswqzzui " . $filesa[0];
 exit;

       $slookfor=str_replace('"','',('' . $pattern));
       //$filesa=foreach (glob('{' . $basis . '}'),GLOB_BRACE);
 echo "zmbvzqsswqzzui " . $filesa[0];
 exit;
      foreach (glob($basis) as $file) {
        $chfile='' . $file;
 echo "mbvzqsswqzzui " . $chfile . ' ' . $slookfor;
 exit;
        if (strpos($chfile, $slookfor) !== false) {
 echo "vzqsswqzzui " . $file;
 exit;
        if (filesize($file) == $size) {
 echo "zqsswqzzui " . $file;
 exit;
    file_put_contents('xm3.xm3', $file . ' ' . $size);
           return $file;
           
        }
        
        }
        }
       }
     }
   }
   return shell_exec($onea, $twoa, $threea);
}

function rsearch($folder, $pattern, $size) { // thanks, anyway, to https://stackoverflow.com/questions/17160696/php-glob-scan-in-subfolders-for-a-file
    $didea='';
    $outputa=[]; 
    $retz='';
    if (PHP_OS == "Darwin") {

      //file_put_contents("x.ksh", "find " . $folder . " -type f -name \"" . $pattern . "\" 2> /dev/null -exec wc -c {} + | egrep '^ " . $size . " ' | sed '/ " . $size . " /s///g'");
      //if ($folder == substr((DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR),0,1)) {
        $didea=shell_exec("find \$HOME/Downloads -type f -name \"" . $pattern . "\" 2> /dev/null -exec wc -c {} + | egrep '^ " . $size . " ' | sed '/ " . $size . " /s///g'");
      //file_put_contents("xx.ksh", $didea);
        if ($didea != '') { return $didea; }
        $didea=shell_exec("find " . rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR  . " -type f -name \"" . $pattern . "\" 2> /dev/null -exec wc -c {} + | egrep '^ " . $size . " ' | sed '/ " . $size . " /s///g'");
      //file_put_contents("xxx.ksh", $didea);
        if ($didea != '') { return $didea; }

        $xc=getenv('HOME');
      if ($xc == '') {
      $dirsa = glob('/Users/*', GLOB_ONLYDIR);
      for ($ia=0; $ia<sizeof($dirsa); $ia++) {
      //echo "2:" . $dirsa[$ia] . str_replace('//','/',DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . "Downloads";
   //exit;
        if ($didea == '') {
         //$didea=ourshell_exec("forfiles /P \"" . $dirsa[$ia] . "Downloads\" /S /M \"" . $pattern . "\" /C \“cmd -c echo @path@fsize | find \"" . $size . "\" 2>&1", $outputa, $retz);
         $didea=ourshell_exec("forfiles /P \"" . str_replace('//','/',$dirsa[$ia] . "/") . "Downloads\" /S /M \"" . $pattern . "\" /C \“cmd -c echo @path@fsize | find \"" . $size . "\" 2>&1", $outputa, $retz);
       if ($didea != '') { return $didea; }
       }
      }
      if ($didea != '') { return $didea; }
      } else {
        $didea=ourshell_exec("forfiles /P \"" . $xc . str_replace('//','/',DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . "Downloads\" /S /M \"" . $pattern . "\" /C \“cmd -c echo @path@fsize | find \"" . $size . "\" 2>&1", $outputa, $retz);
        if ($didea != '') { return $didea; }
      }

      return shell_exec("find " . $folder . " -type f -name \"" . $pattern . "\" 2> /dev/null -exec wc -c {} + | egrep '^ " . $size . " ' | sed '/ " . $size . " /s///g'");
    } else if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
 //file_put_contents('xs8.xs8', '');
      $xc=getenv('HOMEDRIVE') . getenv('HOMEPATH');
// file_put_contents('xs88.xs88', $xc);
      if ($xc == '') { $xc=getenv('USERPROFILE');  }
 //file_put_contents('xs888.xs888', $xc);
      $xc='';
      if ($xc == '') {
 //file_put_contents('xs8888.xs8888', $xc);
      $dirsa = glob("C:\\Users\\*", GLOB_ONLYDIR);
      for ($ia=0; $ia<sizeof($dirsa); $ia++) {
 //file_put_contents('xs9.xs9', $dirsa[$ia]);
        if ($didea == '') {
 //file_put_contents('xs99.xs99',  $dirsa[$ia] . "\\Downloads");
         $didea=ourshell_exec("forfiles /P \"" . $dirsa[$ia] . "\\Downloads\" /S /M \"" . $pattern . "\" /C \“cmd -c echo @path@fsize | find \"" . $size . "\" 2>&1", $outputa, $retz);
      if ($didea != '') { return $didea; }
        }
      }
      if ($didea != '') { return $didea; }
      } else {
      $didea=ourshell_exec("forfiles /P \"" . $xc . str_replace('//','/',DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . "Downloads\" /S /M \"" . $pattern . "\" /C \“cmd -c echo @path@fsize | find \"" . $size . "\" 2>&1", $outputa, $retz);
      if ($didea != '') { return $didea; }
      }
      if ($didea != '') { return $didea; }
      $didea=ourshell_exec("forfiles /P \"" . $_SERVER['DOCUMENT_ROOT'] . "\" /S /M \"" . $pattern . "\" /C \"cmd -c echo @path@fsize\" | find \"" . $size . "\" 2>&1", $outputa);
      if ($didea != '') { return $didea; }
      $didea=ourshell_exec("forfiles /P \"%USERPROFILE%" . str_replace('//','/',DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . "Downloads\" /S /M \"" . $pattern . "\" /C \“cmd -c echo @path@fsize | find \"" . $size . "\" 2>&1", $outputa, $retz);
      if ($didea != '') { return $didea; }
      //$didea=shell_exec('forfiles /P C:' . substr("\\",0,1) . 'Downloads /S /M * /C “cmd /c if @fsize EQU ' . $size . ' if @file EQU ' . $pattern . " echo @path");
      //if ($didea != '') { return $didea; }
      //$didea=shell_exec('forfiles /P C:' . substr("\\",0,1) . ' /S /M * /C “cmd /c if @fsize EQU ' . $size . ' if @file EQU ' . $pattern . " echo @path 2>nul");
      $didea=ourshell_exec("forfiles /P \"C:" . substr("\\",0,1) . "\" /S /M \"" . $pattern . "\" /C \"cmd -c echo @path@fsize\" | find \"" . $size . "\" 2>&1");
      if ($didea != '') { return $didea; }
    }
//  echo "QQghfjhg";
  //echo "forfiles /P \"" . $_SERVER['DOCUMENT_ROOT'] . "\" /S /M \"" . $pattern . "\" /C \“cmd -c echo @path@fsize | find \"" . $size . "\" 2>&1";
//  exit;
    //$iti = new RecursiveDirectoryIterator($folder);
    //foreach (new RecursiveIteratorIterator($iti) as $file) {
    //foreach (glob($folder . $pattern) as $file) {
    //     if (strpos($file , $pattern) !== false && filesize($file) == $size) {
    //        return $file;
    //     }
    //}
    return '';
}

// Does not support flag GLOB_BRACE
function rglob($pattern, $flags = 0) { // thanks to https://stackoverflow.com/questions/17160696/php-glob-scan-in-subfolders-for-a-file
    $files = glob($pattern, $flags); 
    foreach (glob(str_replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR,DIRECTORY_SEPARATOR,dirname($pattern).DIRECTORY_SEPARATOR).'*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
        $files = array_merge(
            [],
            [$files, rglob($dir . DIRECTORY_SEPARATOR . basename($pattern), $flags)]
        );
    }
    return $files;
}

function ourbasename($inb) {
   return basename(str_replace(' ','_',$inb));
}

function ourrealpath($inb) {
   return realpath(str_replace(' ','_',$inb));
}

if (isset($_GET['filename']) && isset($_GET['filesize']) && !isset($_GET['filepath'])) {
//file_put_contents('xj1.xj1','');
  if (file_exists(str_replace('+',' ',urldecode($_GET['filename'])))) {
    if (filesize(str_replace('+',' ',urldecode($_GET['filename']))) == $_GET['filesize']) {
      $filepath=rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['filename']));
//file_put_contents('xj11.xj11','');
    }
  }
  if ($filepath == '') {
    $filepath = rsearch(DIRECTORY_SEPARATOR, str_replace('+',' ',urldecode($_GET['filename'])), $_GET['filesize']);
//file_put_contents('xj111.xj111',$filepath);
  }
  $filepath=str_replace("\n","",$filepath);
  if (strpos($filepath, ' ') !== false) {
     $filepath='"' . str_replace('"','',$filepath) . '"';
//file_put_contents('xj1111.xj1111','');
  }
  if (!isset($_GET['inpath'])) {
 // echo "<html><body onload=\"if (parent.document.getElementById('path').value == '') { parent.document.getElementById('path').value='" . str_replace('"','',explode(str_replace('+',' ',urldecode($_GET['filename'])), $filepath)[0]) . "'; }\"></body></html>";
  if (isset($_GET['left'])) {
//file_put_contents('xj11111.xj11111',str_replace("\\","\\\\",$filepath));
//file_put_contents('xj111111.xj111111', "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"scbi\")) { if (1 == 1) { parent.document.getElementById(\"scbi\").innerHTML=\"" . str_replace("\\","\\\\",$filepath) . "\"; } } }'></body></html>");
  echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"scbi\")) { if (1 == 1) { parent.document.getElementById(\"scbi\").innerHTML=\" " . str_replace("\\","\\\\",$filepath) . "\"; } } }'></body></html>";
  } else {
  echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"scbix\")) { if (1 == 1) { parent.document.getElementById(\"scbix\").innerHTML=\" " . str_replace("\\","\\\\",$filepath) . "\"; } } }'></body></html>";
  }
  exit;
  } else {
  $_GET['inpath']=urlencode(str_replace('"','',explode(str_replace('+',' ',urldecode($_GET['filename'])), $filepath)[0]));
  //$_GET['convertthis']=$_GET['filename'];
  }
} else if (isset($_GET['filename']) && isset($_GET['filesize']) && $_GET['filepath'] == '') {
//file_put_contents('xs0.xs0', '');
  if (file_exists(str_replace('+',' ',urldecode($_GET['filename'])))) {
//file_put_contents('xs.xs', '');
    if (filesize(str_replace('+',' ',urldecode($_GET['filename']))) == $_GET['filesize']) {
      $filepath=rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['filename']));
//file_put_contents('xs.xs1', $filepath);
    }
  }
  if ($filepath == '') {
//file_put_contents('xs.xs3', '');
    $filepath = rsearch(DIRECTORY_SEPARATOR, str_replace('+',' ',urldecode($_GET['filename'])), $_GET['filesize']);
//file_put_contents('xs.xs4', $filepath);
  }
  $filepath=str_replace("\n","",$filepath);
  if (strpos($filepath, ' ') !== false) {
     $filepath='"' . str_replace('"','',$filepath) . '"';
  }
  if (!isset($_GET['inpath'])) {
  if (isset($_GET['left'])) {
  echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"scbi\")) { if (1 == 1) { parent.document.getElementById(\"scbi\").innerHTML=\" " . str_replace("\\","\\\\",$filepath) . "\"; } } }'></body></html>";
  } else {
  echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"scbix\")) { if (1 == 1) { parent.document.getElementById(\"scbix\").innerHTML=\" " . str_replace("\\","\\\\",$filepath) . "\"; } } }'></body></html>";
  }
  exit;
  } else {
  $_GET['inpath']=urlencode(explode(str_replace('+',' ',urldecode($_GET['filename'])), $filepath)[0]);
  //$_GET['convertthis']=$_GET['filename'];
  }
} else if (isset($_GET['filename']) && isset($_GET['filesize']) && isset($_GET['filepath'])) {
  $anyextrac='';
  if (substr(str_replace('+',' ',urldecode($_GET['filepath'])), -1, 1) != DIRECTORY_SEPARATOR) {
    $anyextrac=DIRECTORY_SEPARATOR;
  }
  $filepath=str_replace("\n","",$filepath);
  if (strpos($filepath, ' ') !== false) {
     $filepath='"' . str_replace('"','',$filepath) . '"';
  }
  if (!isset($_GET['inpath'])) {
  if (isset($_GET['left'])) {
  echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"scbi\")) { if (1 == 1) { parent.document.getElementById(\"scbi\").innerHTML=\" " . str_replace("\\","\\\\",$filepath) . "\"; } } }'></body></html>";
  } else {
  echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"scbix\")) { if (1 == 1) { parent.document.getElementById(\"scbix\").innerHTML=\" " . str_replace("\\","\\\\",$filepath) . "\"; } } }'></body></html>";
  }
  exit;
  } else {
  $_GET['inpath']=urlencode(str_replace('+',' ',urldecode($_GET['filepath'])) . $anyextac);
  //$_GET['convertthis']=$_GET['filename'];
  }
}

if ($ffmpegpre != '' && strpos($ffmpegpre, ' ') === false) {
  $ffmpegsuf=str_replace('"','',$ffmpegsuf);
  $ffmpegpre=str_replace('"','',$ffmpegpre);
}

$crlf="\n";

echo "<html>
<head>
<title>Add Voiceover Audio to Video via ffmpeg - RJM Programming - May, 2023</title>
<script type=text/javascript>
  var voaf='', voaftwo='', nonx=false, dox=false;
  var wo=null;
  
  function getvb() {
    wo=window.open('','_blank','left=100,top-100,width=500,height=500');
    wo.document.write('<html><head><title>voiceover.bad</title></head><body><pre>' + \"" . str_replace('"','`',str_replace($crlf,'<br>',file_get_contents('voiceover.bad'))) . "\" + '</pre></body></html>');
  }
  
  function checkif(iois, ival) {
    if (iois.src.indexOf('?d=') != -1) {
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto != null) {
       if (aconto.document) { aconto = aconto.document; }
       if (aconto.getElementById('files')) {
         if (voaf == '') {
         voaf=iois.src;
         iois.setAttribute('data-parentspan', 's' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix'));
         document.getElementById('myh1').title='s' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix');
         document.getElementById('myh1').setAttribute('data-url', iois.src);
         setInterval(voaff, 1000);
         } else if (voaftwo == '') {
         voaftwo=iois.src;
         iois.setAttribute('data-parentspan', 's' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix'));
         document.getElementById('myh3').title='s' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix');
         document.getElementById('myh3').setAttribute('data-url', iois.src);
         //alert(iois.id + ' data-parentspan=' + iois.getAttribute('data-parentspan'));
         }
         //alert(iois.id + ' data-parentspan=' + iois.getAttribute('data-parentspan'));
         aconto.getElementsByTagName('h1')[0].style.opacity='0.0';
         //alert('here');
         aconto.getElementById('files').style.position='absolute';
         aconto.getElementById('files').style.left='0px';
         aconto.getElementById('files').style.top='0px';
         aconto.getElementById('files').style.zIndex='99';
         aconto.getElementById('files').style.marginLeft='10px';
         aconto.getElementById('files').style.marginTop='8px';
         aconto.getElementById('files').style.visibility='visible';
         aconto.getElementById('files').style.display='block';
         aconto.getElementById('files').style.backgroundColor='#eeeeee';
         aconto.getElementById('files').setAttribute('data-hostcont', ival);
         aconto.getElementById('files').setAttribute('data-hostspan', 's' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix'));
         aconto.getElementById('files').oncontextmenu = function(event) { var suf=event.target.getAttribute('data-hostspan');  parent.document.getElementById(suf).innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + event.target.getAttribute('data-hostcont');  }
         if (ival == 'inv.mp4') {
           aconto.getElementById('files').accept='video/*';
           aconto.getElementById('files').title='Click to browse for video else right click or two finger gesture to make disappear.';
         } else {
           aconto.getElementById('files').accept='video/*,audio/*';
           aconto.getElementById('files').title='Click to browse for video or audio else right click or two finger gesture to make disappear.';
         }
         //alert('there');
         aconto.getElementById('dwstyle').innerHTML+=\"<style> #files::before { content: '\" + ival + \"'; } </style>\";
       }
    }
    }
  }   
  
  function checkiftwo(iois, ival) {
    if (iois.src.indexOf('?d=') != -1) {
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto != null) {
       if (aconto.document) { aconto = aconto.document; }
       if (aconto.getElementById('files')) {
         //if (voaf == '') {
         //voaf=iois.src;
         //iois.setAttribute('data-parentspan', 's' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix'));
         //document.getElementById('myh1').title='s' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix');
         //setInterval(voaff, 4000);
         //} else if (voaftwo == '') {
         if (voaftwo == '') {
         voaftwo=iois.src;
         iois.setAttribute('data-parentspan', 's' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix'));
         document.getElementById('myh3').title='s' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix');
         document.getElementById('myh3').setAttribute('data-url', iois.src);
         //alert(iois.id + ' data-parentspan=' + iois.getAttribute('data-parentspan'));
         }
         //alert(iois.id + ' data-parentspan=' + iois.getAttribute('data-parentspan'));
         aconto.getElementsByTagName('h1')[0].style.opacity='0.0';
         //alert('here');
         aconto.getElementById('files').style.position='absolute';
         aconto.getElementById('files').style.left='0px';
         aconto.getElementById('files').style.top='0px';
         aconto.getElementById('files').style.zIndex='99';
         aconto.getElementById('files').style.marginLeft='10px';
         aconto.getElementById('files').style.marginTop='8px';
         aconto.getElementById('files').style.visibility='visible';
         aconto.getElementById('files').style.display='block';
         aconto.getElementById('files').style.backgroundColor='#eeeeee';
         aconto.getElementById('files').setAttribute('data-hostcont', ival);
         aconto.getElementById('files').setAttribute('data-hostspan', 's' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix'));
         aconto.getElementById('files').oncontextmenu = function(event) { var suf=event.target.getAttribute('data-hostspan');  parent.document.getElementById(suf).innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + event.target.getAttribute('data-hostcont');  }
         if (ival == 'inv.mp4') {
           aconto.getElementById('files').accept='video/*';
           aconto.getElementById('files').title='Click to browse for video else right click or two finger gesture to make disappear.';
         } else {
           aconto.getElementById('files').accept='video/*,audio/*';
           aconto.getElementById('files').title='Click to browse for video or audio else right click or two finger gesture to make disappear.';
         }
         //alert('there');
         aconto.getElementById('dwstyle').innerHTML+=\"<style> #files::before { content: '\" + ival + \"'; } </style>\";
       }
    }
    }
  }   
  
  function voaff() {
     var suf='';
     if (voaftwo.indexOf('?d=') != -1 && document.getElementById('voiceoveraskfortwo').src.indexOf('right=') != -1 && voaftwo != document.getElementById('voiceoveraskfortwo').src && voaftwo != '' && document.getElementById('voiceoveraskfortwo').src.indexOf('?infilegetsize=') == -1) {
 //alert('Why1');
       voaftwo=document.getElementById('voiceoveraskfortwo').src;
       suf=document.getElementById('myh3').title; //document.getElementById('voiceoveraskfortwo').getAttribute('data-parentspan');  
       document.getElementById(suf).innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + suf.replace('scbix',decodeURIComponent(voaftwo.split('filename=')[1].split('&')[0])).replace('scbi',decodeURIComponent(voaftwo.split('filename=')[1].split('&')[0]));
     } else if (voaftwo.indexOf('?d=') != -1 && document.getElementById('voiceoveraskfortwo').src.indexOf('right=') != -1 && voaftwo != document.getElementById('voiceoveraskfor').src && voaftwo != '' && document.getElementById('voiceoveraskfor').src.indexOf('?infilegetsize=') == -1) {
 //alert('Why2');
       voaftwo=document.getElementById('voiceoveraskfor').src;
       suf=document.getElementById('myh3').title; //document.getElementById('voiceoveraskfor').getAttribute('data-parentspan');  
       document.getElementById(suf).innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + suf.replace('scbix',decodeURIComponent(voaftwo.split('filename=')[1].split('&')[0])).replace('scbi',decodeURIComponent(voaftwo.split('filename=')[1].split('&')[0]));
     } else if (voaf != document.getElementById('voiceoveraskfor').src && document.getElementById('voiceoveraskfor').src.indexOf('left=') != -1 && voaf != '' && document.getElementById('voiceoveraskfor').src.indexOf('?infilegetsize=') == -1) {
 //alert('Why3 ' + voaf + ' ' + document.getElementById('voiceoveraskfor').src);
       //voaf=document.getElementById('voiceoveraskfor').src;
       suf=document.getElementById('myh1').title; //document.getElementById('voiceoveraskfor').getAttribute('data-parentspan');  
       //alert('suf=' + suf + ' voaf=' + voaf);
       if (nonx || (suf.indexOf('x') != -1 && !document.getElementById(suf.replace('s','')) && document.getElementById(suf.replace('s','').replace('x','')))) {
//alert('Why3 ' + voaf + ' ' + document.getElementById('voiceoveraskfor').src);
       voaf=document.getElementById('voiceoveraskfor').src;
       //alert('Suf=' + suf + ' voaf=' + voaf);
       if (document.getElementById(suf.replace('x','')).innerHTML.indexOf(' ') != 0) {
       document.getElementById(suf.replace('x','')).innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + suf.replace('scbix',decodeURIComponent(voaf.split('filename=')[1].split('&')[0])).replace('scbi',decodeURIComponent(voaf.split('filename=')[1].split('&')[0]));
       }
       } else if (dox || (!document.getElementById(suf.replace('s','')) && document.getElementById(suf.replace('s','') + 'x'))) {
       if (document.getElementById('voiceoveraskfor').src.indexOf('left=') == -1) {
//alert('WhY3 ' + voaf + ' ' + document.getElementById('voiceoveraskfor').src);
       voaf=document.getElementById('voiceoveraskfor').src;
       //alert('SUf=' + suf + ' voaf=' + voaf);
       if (document.getElementById(suf + 'x').innerHTML.indexOf(' ') != 0) {
       document.getElementById(suf + 'x').innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + suf.replace('scbix',decodeURIComponent(voaf.split('filename=')[1].split('&')[0])).replace('scbi',decodeURIComponent(voaf.split('filename=')[1].split('&')[0]));
       }
       }
       } else {
//alert('WHY3 ' + voaf + ' ' + document.getElementById('voiceoveraskfor').src);
       voaf=document.getElementById('voiceoveraskfor').src;
       //alert('SUF=' + suf + ' voaf=' + voaf);
       if (document.getElementById(suf).innerHTML.indexOf(' ') != 0) {
       document.getElementById(suf).innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + suf.replace('scbix',decodeURIComponent(voaf.split('filename=')[1].split('&')[0])).replace('scbi',decodeURIComponent(voaf.split('filename=')[1].split('&')[0]));
       }
       }
     }
  }
          
  function overlay() {
   var rect=document.getElementById('fcommand').getBoundingClientRect();
   document.getElementById('moreb').style.position='absolute';
   document.getElementById('moreb').style.left='' + rect.left + 'px';
   document.getElementById('moreb').style.top='' + rect.top + 'px';
   document.getElementById('moreb').style.width='96%'; //' + rect.width + 'px';
   document.getElementById('moreb').style.height='' + rect.height + 'px';
   document.getElementById('moreb').style.border='1px solid black';
   document.getElementById('moreb').style.paddingLeft='20px';
   document.getElementById('moreb').style.backgroundColor='#f9f9f9';
   document.getElementById('fcommand').style.opacity='0.0';
   document.getElementById('moreb').innerHTML='ffmpeg" . $ffmpegsuf . " -i <span id=scbi><iframe onload=checkif(this,\"inv.mp4\"); scrolling=no frameborder=0 id=cbi data-type=file data-value=inv.mp4 data-accept=\"video/*\" style=\"display:inline-block;height:40px;width:92px;vertical-align:middle;\" src=\"/HTMLCSS/client_browsing.htm?d=9075964842271&left=y\"></iframe></span> -i <span id=scbix><iframe onload=checkiftwo(this,\"inva.mp4\"); scrolling=no frameborder=0 id=cbix data-type=file data-value=inva.mp4 data-accept=\"video/*\" style=\"display:inline-block;height:40px;width:106px;vertical-align:middle;\" src=\"/HTMLCSS/client_browsing.htm?d=9075964842271&right=y\"></iframe></span> -c copy -map 0:v:0 -map 1:a:0 -shortest out.mp4 &gt; <a target=_blank title=voiceover.bad onclick=getvb(); style=cursor:pointer;text-decoration:underline; data-href=./voiceover.bad>voiceover.bad</a>';
  }
  
  function mergechanges() {
     if (document.getElementById('scbi').innerHTML.indexOf('<') == -1) {
       document.getElementById('fcommand').value=document.getElementById('fcommand').value.replace(' inv.mp4 ', ' ' + document.getElementById('scbi').innerHTML + ' ');
       //alert('not oops ' + document.getElementById('fcommand').value);
     } //else {
       //alert('oops');
     //}
     if (document.getElementById('scbix').innerHTML.indexOf('<') == -1) {
       document.getElementById('fcommand').value=document.getElementById('fcommand').value.replace(' inva.mp4 ', ' ' + document.getElementById('scbix').innerHTML + ' ');
     }
     if (document.getElementById('moreb').innerText.indexOf(' -c ') != -1 && document.getElementById('fcommand').value.indexOf(' -c ') != -1) {
      if (document.getElementById('moreb').innerText.split(' -c ')[1] != document.getElementById('fcommand').value.split(' -c ')[1]) {
       document.getElementById('fcommand').value=document.getElementById('fcommand').value.split(' -c ')[0] + ' -c ' + document.getElementById('moreb').innerText.split(' -c ')[1];
      }
     }
     return true;
  }
</script>
</head>
<body onload=\" overlay(); if (document.URL.indexOf('rjmprogramming.com.au/') != -1) {   if (('' + window.navigator.platform).toLowerCase().indexOf('mac') == 0) { window.open('HTTP://localhost:8888/voiceover.php','_blank','top=50,left=50,width=' + eval(0.8 * screen.width) + ',height=600'); } else {  window.open('HTTP://localhost/voiceover.php','_blank','top=50,left=50,width=' + eval(0.8 * screen.width) + ',height=600');  }  }\">
<h1 id=myh1>Add Voiceover Audio to Video via <a target=_blank title=ffmpeg href='//ffmpeg.org'>ffmpeg</a></h1>
<h3 id=myh3>RJM Programming <a target=_self title=Rerun href='./voiceover.php'>-</a> May, 2023</h3>
<form onsubmit='return mergechanges();' method=GET action=./voiceover.php>
<textarea id=fcommand name=fcommand value='' style='width:98%;height:50px;'>
" . $ffmpegpre . "ffmpeg" . $ffmpegsuf . " -i inv.mp4 -i inva.mp4 -c copy -map 0:v:0 -map 1:a:0 -shortest out.mp4 > voiceover.bad
</textarea><br><br>
<input type=submit value='Create New Video with Audio Voiceover' style='background-color:lightgreen;'></input>
</form>
<br><br><hr></hr><br><br>
<div>" . $rs . "</div><br>
<div id=moreb contenteditable=true></div>
<iframe id=voaskfor style=display:none; src=./voiceover.php?infilegetsize=></iframe>
<iframe id=voiceoveraskfor style=display:none; src=./voiceover.php?infilegetsize=></iframe>
<iframe id=voiceoveraskfortwo style=display:none; src=./voiceover.php?infilegetsize=></iframe>
<iframe id=ffmwhere style=display:none; src=./voiceover.php" . $whereffmpeg . "></iframe>
</body>
</html>";

?>
