資源簡介
一個簡單的基于ffmpeg推流的demo,從雷神博客所得,要學習ffmpeg推流的伙伴可以下載學習
代碼片段和文件信息
/**
?*?最簡單的基于FFmpeg的推流器(推送RTMP)
?*?Simplest?FFmpeg?Streamer?(Send?RTMP)
?*?
?*?雷霄驊?Lei?Xiaohua
?*?leixiaohua1020@126.com
?*?中國傳媒大學/數字電視技術
?*?Communication?University?of?China?/?Digital?TV?Technology
?*?http://blog.csdn.net/leixiaohua1020
?*?
?*?本例子實現了推送本地視頻至流媒體服務器(以RTMP為例)。
?*?是使用FFmpeg進行流媒體推送最簡單的教程。
?*
?*?This?example?stream?local?media?files?to?streaming?media?
?*?server?(Use?RTMP?as?example).?
?*?It‘s?the?simplest?FFmpeg?streamer.
?*?
?*/
#include?
#define?__STDC_CONSTANT_MACROS
#ifdef?_WIN32
//Windows
extern?“C“
{
#include?“libavformat/avformat.h“
#include?“libavutil/mathematics.h“
#include?“libavutil/time.h“
};
#else
//Linux...
#ifdef?__cplusplus
extern?“C“
{
#endif
#include?
#include?
#include?
#ifdef?__cplusplus
};
#endif
#endif
int?main(int?argc?char*?argv[])
{
AVOutputFormat?*ofmt?=?NULL;
//輸入對應一個AVFormatContext,輸出對應一個AVFormatContext
//(Input?AVFormatContext?and?Output?AVFormatContext)
AVFormatContext?*ifmt_ctx?=?NULL?*ofmt_ctx?=?NULL;
AVPacket?pkt;
const?char?*in_filename?*out_filename;
int?ret?i;
int?videoindex=-1;
int?frame_index=0;
int64_t?start_time=0;
//in_filename??=?“cuc_ieschool.mov“;
//in_filename??=?“cuc_ieschool.mkv“;
//in_filename??=?“cuc_ieschool.ts“;
//in_filename??=?“cuc_ieschool.mp4“;
//in_filename??=?“cuc_ieschool.h264“;
in_filename??=?“cuc_ieschool.flv“;//輸入URL(Input?file?URL)
//in_filename??=?“shanghai03_p.h264“;
out_filename?=?“rtmp://live.butel.com/live/dbf4“;//輸出?URL(Output?URL)[RTMP]
//out_filename?=?“rtp://233.233.233.233:6666“;//輸出?URL(Output?URL)[UDP]
av_register_all();
//Network
avformat_network_init();
//輸入(Input)
if?((ret?=?avformat_open_input(&ifmt_ctx?in_filename?0?0))?0)?{
printf(?“Could?not?open?input?file.“);
goto?end;
}
if?((ret?=?avformat_find_stream_info(ifmt_ctx?0))?0)?{
printf(?“Failed?to?retrieve?input?stream?information“);
goto?end;
}
for(i=0;?inb_streams;?i++)?
if(ifmt_ctx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
videoindex=i;
break;
}
av_dump_format(ifmt_ctx?0?in_filename?0);
//輸出(Output)
avformat_alloc_output_context2(&ofmt_ctx?NULL?“flv“?out_filename);?//RTMP
//avformat_alloc_output_context2(&ofmt_ctx?NULL?“mpegts“?out_filename);//UDP
if?(!ofmt_ctx)?{
printf(?“Could?not?create?output?context\n“);
ret?=?AVERROR_UNKNOWN;
goto?end;
}
ofmt?=?ofmt_ctx->oformat;
for?(i?=?0;?i?nb_streams;?i++)?{
//根據輸入流創建輸出流(Create?output?AVStream?according?to?input?AVStream)
AVStream?*in_stream?=?ifmt_ctx->streams[i];
AVStream?*out_stream?=?avformat_new_stream(ofmt_ctx?in_stream->codec->codec);
if?(!out_stream)?{
printf(?“Failed?allocating?output?stream\n“);
ret?=?AVERROR_UNKNOWN;
goto?end;
}
//復制AVCodecContext的設置(Copy?the?settings?of?AVCodecContext)
ret?=?avcodec_copy_context(out_s
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???18936320??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\Debug\avcodec-55.dll
?????文件????1340928??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\Debug\avdevice-55.dll
?????文件????2034688??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\Debug\avfilter-4.dll
?????文件????5342720??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\Debug\avformat-55.dll
?????文件?????418304??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\Debug\avutil-52.dll
?????文件????????644??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\Debug\compile_cl.bat
?????文件????????444??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\Debug\compile_gcc.sh
?????文件????????464??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\Debug\compile_mingw.sh
?????文件????1688360??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\Debug\cuc_ieschool.flv
?????文件?????121344??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\Debug\postproc-52.dll
?????文件??????40960??2018-07-27?17:53??simplest_ffmpeg_streamer_1.1\Debug\simplest_ffmpeg_streamer.exe
?????文件?????264724??2018-07-27?17:53??simplest_ffmpeg_streamer_1.1\Debug\simplest_ffmpeg_streamer.ilk
?????文件?????551936??2018-07-27?17:53??simplest_ffmpeg_streamer_1.1\Debug\simplest_ffmpeg_streamer.pdb
?????文件?????275968??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\Debug\swresample-0.dll
?????文件?????434176??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\Debug\swscale-2.dll
?????文件????????534??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\ReadMe.txt
?????文件?????????61??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\simplest_ffmpeg_streamer\.gitignore
?????文件???18936320??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\simplest_ffmpeg_streamer\avcodec-55.dll
?????文件????1340928??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\simplest_ffmpeg_streamer\avdevice-55.dll
?????文件????2034688??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\simplest_ffmpeg_streamer\avfilter-4.dll
?????文件????5342720??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\simplest_ffmpeg_streamer\avformat-55.dll
?????文件?????418304??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\simplest_ffmpeg_streamer\avutil-52.dll
?????文件????????644??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\simplest_ffmpeg_streamer\compile_cl.bat
?????文件????????444??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\simplest_ffmpeg_streamer\compile_gcc.sh
?????文件????????464??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\simplest_ffmpeg_streamer\compile_mingw.sh
?????文件????1688360??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\simplest_ffmpeg_streamer\cuc_ieschool.flv
?????文件???????5721??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\simplest_ffmpeg_streamer\include\inttypes.h
?????文件?????175612??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\simplest_ffmpeg_streamer\include\libavcodec\avcodec.h
?????文件???????3111??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\simplest_ffmpeg_streamer\include\libavcodec\avfft.h
?????文件???????2392??2015-02-13?01:38??simplest_ffmpeg_streamer_1.1\simplest_ffmpeg_streamer\include\libavcodec\dxva2.h
............此處省略120個文件信息
- 上一篇:麻省理工:深度學習介紹PPT-1
- 下一篇:GJB150-2009.zip
評論
共有 條評論