我試圖建立一個實時流媒體應用程序,從網絡攝像頭捕捉編碼視頻它H264視頻流和使用RTSP將其發送到設備, 我查閱了一些例子並發現這個: FFMPEG to send RTSP encoded stream C++H264編碼視頻流的ffmpeg C++
我一直在使用它作爲我的程序的參考。
但是我不斷收到avcodec中鍵入「MPEG」,我一直在試圖改變名延伸和嘗試不同的方法與avformat_alloc_output_context2
這是相關代碼:
const char *filename = "rtsp://127.0.0.1:7003/live.sdp";
AVOutputFormat *fmt;
AVFormatContext *oc;
AVStream *video_st;
AVCodec *video_codec;
video_st = NULL;
av_register_all();
avformat_network_init();
// format context:
avformat_alloc_output_context2(&oc,NULL,"rtsp",filename);
在調用之後avformat_alloc_output_context2 oc-> oformat-> video_codec被生成爲MPEG編解碼器。 我試圖改變文件擴展名:
const char *filename = "rtsp://127.0.0.1:7003/live.264";
const char *filename = "rtsp://127.0.0.1:7003/live.h264";
和一堆其他的擴展功能。
如何生成H264流?
AVOutputFormat是在調用avformat_alloc_output_context2時在(AVFormatContext)oc中生成的,這就是爲什麼當傳遞NULL作爲第二個參數時,方法應該「猜測」什麼是合適的格式。 – Hahn
@Hahn嘗試手動設置它,只是爲了確保。此外,你應該嘗試另一個編解碼器,看看問題是否孤立到RTSP(直接嘗試H264?) – OMGtechy
感謝OMGtrchy,設置h264,而不是rtsp工作,但是我仍然想用rtsp協議流式傳輸視頻,這是否行得通? – Hahn