溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

FFmpeg rtsp交互實(shí)現(xiàn)以及問題解決

發(fā)布時(shí)間:2020-07-24 16:20:23 來源:網(wǎng)絡(luò) 閱讀:4126 作者:fengyuzaitu 欄目:軟件技術(shù)

知識(shí)準(zhǔn)備

????????????默認(rèn)情況下,wireshark并沒有分析數(shù)據(jù)包的內(nèi)容,從而判斷是否是rtsp數(shù)據(jù)包,它是根據(jù)端口,默認(rèn)端口是554,認(rèn)為是進(jìn)行rtsp協(xié)議會(huì)話,所以會(huì)在捕獲界面顯示數(shù)據(jù)包的Protocol協(xié)議,如果知道哪些端口也是進(jìn)行rtsp會(huì)話的情況下,可以在菜單欄中選擇分析,點(diǎn)擊編碼為,在字段中選擇tcp port 值填寫指定的端口,然后在當(dāng)前的協(xié)議中,選擇RTSP。另外,可以通過鼠標(biāo)右鍵選擇追蹤流,點(diǎn)擊其中的TCP,查看RTSP的交互過程


問題以及解決方案

1)405 Method Not Allowed
主要是在進(jìn)行OPTIONS指令包封裝的時(shí)候,通過wireshark抓包進(jìn)行編寫,報(bào)文內(nèi)容如下:

Request: OPTIONS rtsp:://192.168.1.88 RTSP/1.0\r\n
Method: OPTIONS
URL: rtsp:://192.168.1.88
以為信息的開頭是Request,實(shí)際上這是解析的語句
錯(cuò)誤:
request_stream << "REQUEST: " <<"OPTIONS " << "rtsp://192.168.0.114 " << "RTSP/1.0\r\n";
request_stream << "CSeq: " << "2\r\n";
request_stream << "User-Agent: " << "LibVLC/2.1.5 (Live555 Streaming Media v2014.0)\r\n\r\n";

正確:
request_stream << "OPTIONS " << "rtsp://192.168.0.114 " << "RTSP/1.0\r\n";
request_stream << "CSeq: " << "2\r\n";
request_stream << "User-Agent: " << "LibVLC/2.1.5 (Live555 Streaming Media v2014.0)\r\n\r\n";

2)404 Stream Not Found
主要是在進(jìn)行DESCRIBE的時(shí)候沒有填寫獲取的視頻流信息
錯(cuò)誤:
request_stream << "DESCRIBE " << "rtsp://192.168.0.114 " << "RTSP/1.0\r\n";
正確:
request_stream << "DESCRIBE " << "rtsp://192.168.0.114/smoke.264 " << "RTSP/1.0\r\n";//error


3) 451 Parameter Not Understood

主要是url后面沒有指定trackid,例如指定/trackID=0

錯(cuò)誤:

SETUP rtsp://192.168.18.201:554/cam/realmonitor?channel=1&subtype=0 RTSP/1.0
CSeq: 4
User-Agent: LibVLC/2.2.8 (LIVE555 Streaming Media v2017.08.22)
Authorization: Digest username="admin", realm="Login to 4M01111PAJB50A1", nonce="3344152e2d9f717b3c3f29792f31e125", uri="rtsp://192.168.18.201:554/cam/realmonitor?channel=1&subtype=0", response="d69d677d06e9a5471327ff977cc09d9e"
Transport: RTP/AVP;unicast;client_port=45056-45057
RTSP/1.0 451 Parameter Not Understood
CSeq: 4
Session: 1029986489118


正確:

SETUP rtsp://192.168.18.201:554/cam/realmonitor?channel=1&subtype=0/trackID=0 RTSP/1.0
CSeq: 5
User-Agent: LibVLC/2.2.8 (LIVE555 Streaming Media v2017.08.22)
Authorization: Digest username="admin", realm="Login to 4M01111PAJB50A1", nonce="ba0a98388d61508258fc859081a62fb0", uri="rtsp://192.168.18.201:554/cam/realmonitor?channel=1&subtype=0", response="c72d514d419ee7383c4cc1f94a0b785d"
Session: 1039947334568
Transport: RTP/AVP;unicast;client_port=45058-45059



測(cè)試代碼
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <boost/asio.hpp>
#include "socket.h"

using namespace std;
using namespace boost::asio;

const char pszRtspServerIP[32] = "192.168.0.114";
short sRtspServerPort = 8554;

void WriteFile(char* buf);
{
ofstream ofs;
ofs.open("rtspoption.txt");
ofs << buf << endl;
ofs.close();
}


int HandleOptionCommand(ip::tcp::socket &sock)
{
boost::system::error_code ec;
boost::asio::streambuf request;
std::ostream request_stream(&request);
request_stream << "OPTIONS " << "rtsp://192.168.0.114 " << "RTSP/1.0\r\n";
request_stream << "CSeq: " << "2\r\n";
request_stream << "User-Agent: " << "LibVLC/2.1.5 (Live555 Streaming Media v2014.0)\r\n\r\n";

boost::asio::write(sock, request);

char buf[1024] = { 0 };
size_t len = sock.read_some(buffer(buf), ec);
return 0;
}

int HanleDescribeCommand(ip::tcp::socket &sock)
{
boost::system::error_code ec;
boost::asio::streambuf request;
std::ostream request_stream(&request);
request_stream << "DESCRIBE " << "rtsp://192.168.0.114/smoke.264 " << "RTSP/1.0\r\n";
request_stream << "CSeq: " << "3\r\n";
request_stream << "Accept: " << "application/sdp\r\n";
request_stream << "User-Agent: " << "LibVLC/2.1.5 (Live555 Streaming Media v2014.0)\r\n\r\n";

boost::asio::write(sock, request);

char buf[1024] = { 0 };
size_t len = sock.read_some(buffer(buf), ec);
//a=control:track1
return 0;
}

int HandleSetupCommand(ip::tcp::socket &sock)
{
boost::system::error_code ec;
boost::asio::streambuf request;
std::ostream request_stream(&request);
request_stream << "SETUP " << "rtsp://192.168.0.114/smoke.264 " << "RTSP/1.0\r\n";
request_stream << "CSeq: " << "3\r\n";
request_stream << "Transport: " << "RTP/AVP/TCP;unicast;interleaved=0-1\r\n";
request_stream << "User-Agent: " << "LibVLC/2.1.5 (Live555 Streaming Media v2014.0)\r\n\r\n";

boost::asio::write(sock, request);

char buf[1024] = { 0 };
size_t len = sock.read_some(buffer(buf), ec);
return 0;

}

int main(int argc, char* argv[])
{
io_service iosev;
ip::tcp::socket socket(iosev);
ip::tcp::endpoint ep(ip::address_v4::from_string(pszRtspServerIP), sRtspServerPort);
boost::system::error_code ec;
socket.connect(ep, ec);
if (ec) return -1;

HandleOptionCommand(socket);
HanleDescribeCommand(socket);
HandleSetupCommand(socket);

return 0;
}

????????????


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI