使用CURL從IP Camera Panasonic獲取MJPEG流時出現問題。如何從IP Camera Panasonic獲得MJPEG流?
這是我的代碼。
int _tmain(int argc, _TCHAR* argv[])
{
CURL *curl;
CURLcode res;
/* Minimalistic http request */
char request[1000];
strcpy(request, "GET /nphMotionJpeg?Resolution=640x480&Quality=Standard HTTP/1.1\r\n\r\n") ;
curl_socket_t sockfd; /* socket */
long sockextr;
size_t iolen;
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.253");
curl_easy_setopt(curl, CURLOPT_USERPWD, "my_usr:my_pass");
/* Do not do the transfer - only connect to host */
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
res = curl_easy_perform(curl);
if(CURLE_OK != res)
{
printf("Error: %s\n", strerror(res));
return 1;
}
res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr);
if(CURLE_OK != res)
{
printf("Error: %s\n", curl_easy_strerror(res));
return 1;
}
sockfd = sockextr;
/* wait for the socket to become ready for sending */
if(wait_on_socket(sockfd, false, 6000L) < 0)
{
printf("Error: timeout.\n");
return 1;
}
iolen = 0;
res = curl_easy_send(curl, request, strlen(request), &iolen);
if(CURLE_OK != res)
{
printf("Error: %s\n", curl_easy_strerror(res));
return 1;
}
//puts("Reading response.");
/* read the response */
for(;;)
{
char* buf = new char[1024*100];
iolen = 0;
wait_on_socket(sockfd, true, 60000L);
res = curl_easy_recv(curl, buf, 1024*100, &iolen);
if(CURLE_OK != res)
break;
fstream f;
f.open("out.txt", ios::out|ios::binary|ios::app);
if(!f.fail())
{
f.write(buf,iolen);
f.close();
}
delete []buf;
}
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
結果是在作爲Panasonic文檔的說明的第一個循環之後的buf中的內容。
但它只有3幀jpeg數據響應。總大小隻有3056字節。這意味着大約1KB/Jpeg image.It是錯誤的。
而在第二個循環中,curl_easy_recv()總是返回CURLE_UNSUPPORTED_PROTOCOL。
我也改變請求字符串相同松下文檔的描述: 「GET http://xxx.xxx.xxx.xxx:yy/nphMotionJpeg?Resolution=640x480&Quality=Standard HTTP/1.0 \ r \ n」 個 OR 「GET http://usr:[email protected]:yy/nphMotionJpeg?Resolution=640x480&Quality=Standard HTTP/1.0 \ r \ n」 個 - >它會響應「錯誤的請求」。
我的相機型號是松下BL-C111CE。
謝謝,我已閱讀您鏈接中的示例。 但我不知道如何發送GET命令來檢索運動Jpeg流。你可以幫我嗎?謝謝。 – Levanphong7887 2012-02-10 10:18:56
更多信息:如果我用SnapshotJPEG替換nphMotionJpeg命令=>我用上面的代碼正常工作。 – Levanphong7887 2012-02-10 10:39:35
當您要求libcurl獲取HTTP URL時,GET是默認請求 – 2012-02-10 14:41:41