資源簡介
這是我博客專欄文章《ONVIF協議網絡攝像機(IPC)客戶端程序開發》中附帶的示例代碼。
博客:http://blog.csdn.net/benkaoya
專欄:http://blog.csdn.net/benkaoya/article/details/72424335
代碼片段和文件信息
/************************************************************************
**
**?作者:許振坪
**?日期:2017-05-03
**?博客:http://blog.csdn.net/benkaoya
**?描述:讀取IPC音視頻流數據示例代碼
**
************************************************************************/
#include?
#include?
#include?
#include?“onvif_comm.h“
#include?“onvif_dump.h“
#include?“libavcodec/avcodec.h“
#include?“libavdevice/avdevice.h“
#include?“libavformat/avformat.h“
#include?“libavfilter/avfilter.h“
#include?“libavutil/avutil.h“
#include?“libswscale/swscale.h“
#include?“libavutil/pixdesc.h“
/************************************************************************
**函數:open_rtsp
**功能:從RTSP獲取音視頻流數據
**參數:
????????[in]??rtsp?-?RTSP地址
**返回:無
************************************************************************/
void?open_rtsp(char?*rtsp)
{
????unsigned?int????i;
????int?????????????ret;
????int?????????????video_st_index?=?-1;
????int?????????????audio_st_index?=?-1;
????AVFormatContext?*ifmt_ctx?=?NULL;
????AVPacket????????pkt;
????AVStream????????*st?=?NULL;
????char????????????errbuf[64];
????av_register_all();??????????????????????????????????????????????????????????//?Register?all?codecs?and?formats?so?that?they?can?be?used.
????avformat_network_init();????????????????????????????????????????????????????//?Initialization?of?network?components
????if?((ret?=?avformat_open_input(&ifmt_ctx?rtsp?0?NULL))?0)?{????????????//?Open?the?input?file?for?reading.
????????printf(“Could?not?open?input?file?‘%s‘?(error?‘%s‘)\n“?rtsp?av_make_error_string(errbuf?sizeof(errbuf)?ret));
????????goto?EXIT;
????}
????if?((ret?=?avformat_find_stream_info(ifmt_ctx?NULL))?0)?{????????????????//?Get?information?on?the?input?file?(number?of?streams?etc.).
????????printf(“Could?not?open?find?stream?info?(error?‘%s‘)\n“?av_make_error_string(errbuf?sizeof(errbuf)?ret));
????????goto?EXIT;
????}
????for?(i?=?0;?i?nb_streams;?i++)?{????????????????????????????????//?dump?information
????????av_dump_format(ifmt_ctx?i?rtsp?0);
????}
????for?(i?=?0;?i?nb_streams;?i++)?{????????????????????????????????//?find?video?stream?index
????????st?=?ifmt_ctx->streams[i];
????????switch(st->codec->codec_type)?{
????????case?AVMEDIA_TYPE_AUDIO:?audio_st_index?=?i;?break;
????????case?AVMEDIA_TYPE_VIDEO:?video_st_index?=?i;?break;
????????default:?break;
????????}
????}
????if?(-1?==?video_st_index)?{
????????printf(“No?H.264?video?stream?in?the?input?file\n“);
????????goto?EXIT;
????}
????av_init_packet(&pkt);???????????????????????????????????????????????????????//?initialize?packet.
????pkt.data?=?NULL;
????pkt.size?=?0;
????while?(1)
????{
????????do?{
????????????ret?=?av_read_frame(ifmt_ctx?&pkt);????????????????????????????????//?read?frames
????????}?while?(ret?==?AVERROR(EAGAIN));
????????if?(ret?0)?{
????????????printf(“Could?not?read?frame?(error?‘%s‘)\n“?av_make_error_
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3779??2017-05-19?10:57??snapshot\main.c
?????文件????????361??2017-05-19?10:57??snapshot\Makefile
?????文件???????5812??2017-05-19?10:57??systemtime\main.c
?????文件????????363??2017-05-19?10:57??systemtime\Makefile
?????文件????????880??2017-05-19?10:57??VS2010\project.sln
?????文件???????5596??2017-05-19?10:57??VS2010\project.vcxproj
?????文件????????482??2017-05-19?10:57??VS2010\project.vcxproj.user
?????文件????????564??2017-05-19?10:57??Makefile
?????文件???????3161??2017-05-19?10:57??Makefile.inc
?????文件????????464??2017-05-19?10:57??readme.txt
?????文件???????7398??2017-05-19?10:57??avstream\main.c
?????文件????????361??2017-05-19?10:57??avstream\Makefile
?????文件????????611??2017-05-19?10:57??capabilities\main.c
?????文件????????365??2017-05-19?10:57??capabilities\Makefile
?????文件??????14153??2017-05-19?10:57??comm\onvif_comm.c
?????文件???????3589??2017-05-19?10:57??comm\onvif_comm.h
?????文件??????43653??2017-05-19?10:57??comm\onvif_dump.c
?????文件???????2771??2017-05-19?10:57??comm\onvif_dump.h
?????文件???????1657??2017-05-19?10:57??deviceinfo\main.c
?????文件????????363??2017-05-19?10:57??deviceinfo\Makefile
?????文件????????463??2017-05-19?10:57??discovery\main.c
?????文件????????362??2017-05-19?10:57??discovery\Makefile
?????文件?????182538??2017-05-19?10:57??ffmpeg-linux-pc\include\libavcodec\avcodec.h
?????文件???????2654??2017-05-19?10:57??ffmpeg-linux-pc\include\libavcodec\avdct.h
?????文件???????3229??2017-05-19?10:57??ffmpeg-linux-pc\include\libavcodec\avfft.h
?????文件???????2965??2017-05-19?10:57??ffmpeg-linux-pc\include\libavcodec\d3d11va.h
?????文件???????4175??2017-05-19?10:57??ffmpeg-linux-pc\include\libavcodec\dirac.h
?????文件???????3798??2017-05-19?10:57??ffmpeg-linux-pc\include\libavcodec\dv_profile.h
?????文件???????2454??2017-05-19?10:57??ffmpeg-linux-pc\include\libavcodec\dxva2.h
?????文件???????3870??2017-05-19?10:57??ffmpeg-linux-pc\include\libavcodec\qsv.h
............此處省略448個文件信息
評論
共有 條評論