使用cURL,我收到此错误
$ ./rtspclient.o rtsp://192.168.1.5:554/streamingVideos_10/Movie8minMedium.mov 2000 0 10
rtsp://192.168.1.5:554/streamingVideos_10/Movie8minMedium.mov
* Protocol rtsp not supported or disabled in libcurl
* Unsupported protocol
根据manual,这是因为错别字而发生的!但是,这并不适用于我的情况。
更多信息:
我已成功安装cURL,如下所示
mkdir curlinst
./configure --prefix=/path/to/curldirectory/curlinst/ --enable-rtsp
make
make install
使用代码rtspclientfinal.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream){
printf("Size is: %d\n",size);
printf("Nmemb is: %d\n",nmemb);
return size*nmemb;
}
int main(int argc, char *argv[])
{
CURL *csession;
CURLcode res;
struct curl_slist *custom_msg = NULL;
char URL[256];
char temp_URL[256];
char request[256];
long rc;
int port = 48000;
FILE * protofile = NULL;
protofile = fopen("Dump","wb");
if (argc < 2)
{
fprintf (stderr, "ERROR: enter a valid URL\n");
return -1;
}
csession = curl_easy_init();
if (csession == NULL)
return -1;
printf("%s\n", argv[1]);
sprintf (URL, "%s", argv[1]);
port = atoi(argv[2]);
int timeoutend = atoi(argv[3]);
timeoutend *= 30; //timeoutend holds the correct number of seconds the stream is expected to last
curl_easy_setopt(csession, CURLOPT_URL, URL);
curl_easy_setopt(csession, CURLOPT_RTSP_STREAM_URI, URL);
curl_easy_setopt(csession, CURLOPT_HEADER, 1);
curl_easy_setopt(csession, CURLOPT_VERBOSE, 1);
/** retrieve OPTIONS */
curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
res = curl_easy_perform(csession);
res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
if((res == CURLE_OK) && rc)
{
fprintf(stderr, "OPTIONS Response Code: %ld\n\n", rc);
}
else
return -1;
/** send DESCRIBE */
custom_msg = curl_slist_append(custom_msg, "Accept: application/x-rtsp-mh, application/rtsl, application/sdp");
curl_easy_setopt(csession, CURLOPT_RTSPHEADER, custom_msg);
curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
res = curl_easy_perform(csession);
res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
if((res == CURLE_OK) && rc)
{
fprintf(stderr, "DESCRIBE Response Code: %ld\n\n", rc);
}
else
return -1;
/** send SETUP */
sprintf(temp_URL, "%s/trackID=3", URL);
printf("%s\n",temp_URL);
curl_easy_setopt(csession, CURLOPT_RTSP_STREAM_URI, temp_URL);
sprintf (request, "RTP/AVP/UDP;unicast;client_port=%d-%d", port,port+1);
curl_easy_setopt(csession, CURLOPT_RTSP_TRANSPORT, request);
curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
res = curl_easy_perform(csession);
res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
if((res == CURLE_OK) && rc)
{
fprintf(stderr, "SETUP Response Code: %ld\n\n", rc);
}
else
return -1;
sprintf(temp_URL, "%s/trackID=4", URL);
printf("%s\n",temp_URL);
curl_easy_setopt(csession, CURLOPT_RTSP_STREAM_URI, temp_URL);
sprintf (request, "RTP/AVP/UDP;unicast;client_port=%d-%d", port,port+1);
curl_easy_setopt(csession, CURLOPT_RTSP_TRANSPORT, request);
curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
res = curl_easy_perform(csession);
res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
if((res == CURLE_OK) && rc)
{
fprintf(stderr, "SETUP Response Code: %ld\n\n", rc);
}
else
return -1;
/** send PLAY */
curl_easy_setopt(csession, CURLOPT_RTSP_STREAM_URI, URL);
curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
fprintf(stderr, "playing...\n\n");
res = curl_easy_perform(csession);
if(res != CURLE_OK)
{
fprintf(stderr, "PLAY failed: %d (%s)\n\n", res, curl_easy_strerror(res));
return -1;
} else {
res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
fprintf(stderr, "PLAY Response Code: %ld\n\n", rc);
}
sleep(timeoutend);
/** send TEARDOWN */
curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN);
res = curl_easy_perform(csession);
res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
if((res == CURLE_OK) && rc)
{
fprintf(stderr, "TEARDOWN Response Code: %ld\n\n", rc);
}
else
return -1;
curl_easy_cleanup(csession);
return 0;
}
然后我使用以下命令编译rtspclientfinal.c
gcc -I /path/to/curl/curlinst/include -L /path/to/curl/curlinst/lib/ -lcurl rtspclientfinal.c -o rtspclient.o
没有任何错误。
答案 0 :(得分:0)
我猜您使用的是系统的共享库libcurl而不是您构建的库。
您可以使用命令ldd ./rtspclient.o
检查程序使用的libcurl。
为了加载您构建的库,您可以运行:
LD_LIBRARY_PATH=/path/to/curl/curlinst/lib/ ./rtspclient.o rtsp://192.168.1.5:554/streamingVideos_10/Movie8minMedium.mov 2000 0 10