Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php和curl将Mjpeg转换为jpg_Php_Html_Curl_Video Streaming_Mjpeg - Fatal编程技术网

使用php和curl将Mjpeg转换为jpg

使用php和curl将Mjpeg转换为jpg,php,html,curl,video-streaming,mjpeg,Php,Html,Curl,Video Streaming,Mjpeg,我想在摄像机拍摄东西的视频html标签中显示视频流 我必须通过身份验证连接到相机,所以我使用curl。我设法做到了这一点,并检索到了流。 现在我必须治疗它。 我得到这个流的JPEG图像。除此之外,无法转换图片中的数据 下面是显示一幅图像的部分测试代码: $_SESSION['img'] = ""; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://$ip/cgi-bin/mjpg/video.cgi'); curl_setopt

我想在摄像机拍摄东西的视频html标签中显示视频流

我必须通过身份验证连接到相机,所以我使用curl。我设法做到了这一点,并检索到了流。 现在我必须治疗它。 我得到这个流的JPEG图像。除此之外,无法转换图片中的数据

下面是显示一幅图像的部分测试代码:

$_SESSION['img'] = "";
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://$ip/cgi-bin/mjpg/video.cgi'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($ch, CURLOPT_USERPWD, '$user:$pass');
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($ch, $str) use ($i) {
    $pos = strpos($str, '--myboundary');

    if ($pos !== FALSE && strlen($_SESSION['img']) > 0) {
        //Complete the image data
        $imagePart = substr($str, 0, $pos-1);
        $_SESSION['img'] .= $imagePart;

        //Parse data
        $imgstr = str_replace("--myboundary\r\n", '', $_SESSION['img']);
        $imgstr = str_replace("Content-Type: image/jpeg\r\n", '', $imgstr);
        $imgstr = str_replace("Content-Length: ", '', $imgstr);
        $imgstr = preg_replace("/\d+\r\n\r\n/", '', $imgstr);

        //save in file - file not loaded
        file_put_contents('img/test.jpg', $imgstr);

        //generate image - doesn't work 
        $im = imagecreatefromstring($imgstr);
        if ($im !== false) {
            header("Content-Type: image/jpeg");
            imagejpeg($im);
            imagedestroy($im);
        }

        session_destroy();
        die();
    }

    $_SESSION['img'] .= $str;

    return strlen($str);

}); 

$output = curl_exec($ch); 
curl_close($ch); 
如果你有想法,让我知道

多谢各位