Javascript ffmpeg不返回持续时间,在完成之前无法播放视频。流图像2视频通过PHP

Javascript ffmpeg不返回持续时间,在完成之前无法播放视频。流图像2视频通过PHP,javascript,php,ffmpeg,html5-video,Javascript,Php,Ffmpeg,Html5 Video,我真的在和ffmpeg做斗争。我正在尝试将图像转换为视频,我有一个ip摄像头,我正在录制。每幅图像录制1帧 我正在尝试用php创建一个脚本,这样我就可以从最新创建一个视频,这需要通过image2pipe输入图像,然后创建视频 问题是,ffmpeg确实返回了持续时间和开始统计数据,因此我无法计算视频何时完成或完成的百分比。这段视频要完成才能播放,而且效果也不是很好 任何关于如何解决这个问题的想法,视频格式可以是任何我愿意接受的建议 PHP: Javascript: //Javascript to

我真的在和ffmpeg做斗争。我正在尝试将图像转换为视频,我有一个ip摄像头,我正在录制。每幅图像录制1帧

我正在尝试用php创建一个脚本,这样我就可以从最新创建一个视频,这需要通过image2pipe输入图像,然后创建视频

问题是,ffmpeg确实返回了持续时间和开始统计数据,因此我无法计算视频何时完成或完成的百分比。这段视频要完成才能播放,而且效果也不是很好

任何关于如何解决这个问题的想法,视频格式可以是任何我愿意接受的建议

PHP:

Javascript:

//Javascript to create the loop until video is loaded
<script>
           $(document).ready(function() {
                var loader = $("#clip_load").percentageLoader();
                $.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
                var interval = setInterval(updateProgress,1000);
                function updateProgress(){ $.get( "'.base_url().'video/getVideoCompile_Process?l='.$vid_name.'-output.txt&t=per", function( data ) { if(data=>\'100\'){ $("#clip_load").html(\''.$video_play.'\'); clearInterval(interval); }else{loader.setProgress(data); } });                    }
            });
            </script>
//This is the script which returns the current percentage
$logloc = $this->input->get('l');
$content = @file_get_contents($logloc);

if($content){
    //get duration of source
    preg_match("/Duration: (.*?), start:/", $content, $matches);

    $rawDuration = $matches[1];

    //rawDuration is in 00:00:00.00 format. This converts it to seconds.
    $ar = array_reverse(explode(":", $rawDuration));
    $duration = floatval($ar[0]);
    if (!empty($ar[1])) $duration += intval($ar[1]) * 60;
    if (!empty($ar[2])) $duration += intval($ar[2]) * 60 * 60;

    //get the time in the file that is already encoded
    preg_match_all("/time=(.*?) bitrate/", $content, $matches);

    $rawTime = array_pop($matches);

    //this is needed if there is more than one match
    if (is_array($rawTime)){$rawTime = array_pop($rawTime);}

    //rawTime is in 00:00:00.00 format. This converts it to seconds.
    $ar = array_reverse(explode(":", $rawTime));
    $time = floatval($ar[0]);
    if (!empty($ar[1])) $time += intval($ar[1]) * 60;
    if (!empty($ar[2])) $time += intval($ar[2]) * 60 * 60;

    //calculate the progress
    $progress = round(($time/$duration) * 100);
    if ($this->input->get('t')=='per'){
        echo $progress;
    }else{
            echo "Duration: " . $duration . "<br>";
            echo "Current Time: " . $time . "<br>";
    echo "Progress: " . $progress . "%";}
}else{ echo "cannot locate";}
PHP页面通过javascript调用:

//Javascript to create the loop until video is loaded
<script>
           $(document).ready(function() {
                var loader = $("#clip_load").percentageLoader();
                $.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
                var interval = setInterval(updateProgress,1000);
                function updateProgress(){ $.get( "'.base_url().'video/getVideoCompile_Process?l='.$vid_name.'-output.txt&t=per", function( data ) { if(data=>\'100\'){ $("#clip_load").html(\''.$video_play.'\'); clearInterval(interval); }else{loader.setProgress(data); } });                    }
            });
            </script>
//This is the script which returns the current percentage
$logloc = $this->input->get('l');
$content = @file_get_contents($logloc);

if($content){
    //get duration of source
    preg_match("/Duration: (.*?), start:/", $content, $matches);

    $rawDuration = $matches[1];

    //rawDuration is in 00:00:00.00 format. This converts it to seconds.
    $ar = array_reverse(explode(":", $rawDuration));
    $duration = floatval($ar[0]);
    if (!empty($ar[1])) $duration += intval($ar[1]) * 60;
    if (!empty($ar[2])) $duration += intval($ar[2]) * 60 * 60;

    //get the time in the file that is already encoded
    preg_match_all("/time=(.*?) bitrate/", $content, $matches);

    $rawTime = array_pop($matches);

    //this is needed if there is more than one match
    if (is_array($rawTime)){$rawTime = array_pop($rawTime);}

    //rawTime is in 00:00:00.00 format. This converts it to seconds.
    $ar = array_reverse(explode(":", $rawTime));
    $time = floatval($ar[0]);
    if (!empty($ar[1])) $time += intval($ar[1]) * 60;
    if (!empty($ar[2])) $time += intval($ar[2]) * 60 * 60;

    //calculate the progress
    $progress = round(($time/$duration) * 100);
    if ($this->input->get('t')=='per'){
        echo $progress;
    }else{
            echo "Duration: " . $duration . "<br>";
            echo "Current Time: " . $time . "<br>";
    echo "Progress: " . $progress . "%";}
}else{ echo "cannot locate";}
谢谢