91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 10.64MB
    文件類型: .7z
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2024-02-04
  • 語言: 其他
  • 標(biāo)簽: FFmpeg??推流??RTMP??

資源簡介

本例子實(shí)現(xiàn)了推送本地視頻至流媒體服務(wù)器(以RTMP為例)。 是使用FFmpeg進(jìn)行流媒體推送最簡單的教程。

資源截圖

代碼片段和文件信息

/**
?*?最簡單的基于FFmpeg的推流器(推送RTMP)
?*?Simplest?FFmpeg?Streamer?(Send?RTMP)
?*?
?*?雷霄驊?Lei?Xiaohua
?*?leixiaohua1020@126.com
?*?中國傳媒大學(xué)/數(shù)字電視技術(shù)
?*?Communication?University?of?China?/?Digital?TV?Technology
?*?http://blog.csdn.net/leixiaohua1020
?*?
?*?本例子實(shí)現(xiàn)了推送本地視頻至流媒體服務(wù)器(以RTMP為例)。
?*?是使用FFmpeg進(jìn)行流媒體推送最簡單的教程。
?*
?*?This?example?stream?local?media?files?to?streaming?media?
?*?server?(Use?RTMP?as?example).?
?*?It‘s?the?simplest?FFmpeg?streamer.
?*?
?*/

#include?

extern?“C“
{
#include?“l(fā)ibavformat/avformat.h“
#include?“l(fā)ibavutil/mathematics.h“
#include?“l(fā)ibavutil/time.h“
};


int?main(int?argc?char*?argv[])
{
AVOutputFormat?*ofmt?=?NULL;
//輸入對(duì)應(yīng)一個(gè)AVFormatContext,輸出對(duì)應(yīng)一個(gè)AVFormatContext
//(Input?AVFormatContext?and?Output?AVFormatContext)
AVFormatContext?*ifmt_ctx?=?NULL?*ofmt_ctx?=?NULL;
AVPacket?pkt;
const?char?*in_filename?*out_filename;
int?ret?i;

//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“;//輸入U(xiǎn)RL(Input?file?URL)
out_filename?=?“rtmp://localhost/publishlive/livestream“;//輸出?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))? printf(?“Could?not?open?input?file.“);
goto?end;
}
if?((ret?=?avformat_find_stream_info(ifmt_ctx?0))? printf(?“Failed?to?retrieve?input?stream?information“);
goto?end;
}

int?videoindex=-1;
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++)?{
//根據(jù)輸入流創(chuàng)建輸出流(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;
}
//復(fù)制AVCodecContext的設(shè)置(Copy?the?settings?of?AVCodecContext)
ret?=?avcodec_copy_context(out_stream->codec?in_stream->codec);
if?(ret? printf(?“Failed?to?copy?context?from?input?to?output?stream?codec?context\n“);
goto?end;
}
out_stream->codec->codec_tag?=?0;
if?(ofmt_ctx->oformat->flags?&?AVFMT_GLOBALHEADER)
out_stream->codec->flags?|=?CODEC_FLAG_GLOBAL_HEADER;
}
//Dump?Format----------------

評(píng)論

共有 條評(píng)論