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

  • 大小: 4KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2023-12-22
  • 語言: 其他
  • 標簽: ffmpeg??rtmp??

資源簡介

內存中H264數據加原始PCM音頻數據封裝FLV格式發布出rtmp

資源截圖

代碼片段和文件信息

#include?“rtmpstream.h“

RtmpStream::RtmpStream()
{
have_video?=?0;
have_audio?=?0;
ptsInc?=?0;

oc?=?NULL;
opt?=?NULL;
video_st?=?{?0?};
audio_st?=?{?0?};

????iRawLineSize?=?0;
iRawBuffSize?=?0;
pRawBuff?=?NULL;

iConvertLineSize?=?0;
iConvertBuffSize?=?0;
pConvertBuff?=?NULL;

memset(pcmencodebuf?0?4096);
pcmencodesize?=?0;
}

RtmpStream::~RtmpStream()
{
/*?Write?the?stream?trailer?to?an?output?media?file?*/
av_write_trailer(oc);

/*?Close?each?codec.?*/
if?(have_video)
close_stream(&video_st);
if?(have_audio)?
close_stream(&audio_st);

/*?Close?the?output?file.?*/
if?(!(fmt->flags?&?AVFMT_NOFILE))
avio_closep(&oc->pb);

/*?free?the?stream?*/
if?(oc)
avformat_free_context(oc);

/*?free?the?audio?frame?*/
if?(pRawBuff)
av_free(pRawBuff);
if?(pConvertBuff)
av_free(pConvertBuff);
}

int?RtmpStream::init(const?char?*filename)
{
int?ret?=?0;

av_register_all();
avformat_network_init();

/*?allocate?the?output?media?context?*/
avformat_alloc_output_context2(&oc?NULL?“flv“?filename);
if?(!oc)?{
printf(“Could?not?deduce?output?format?from?file?extension.\n“);
return?-1;
}

fmt?=?oc->oformat;

/*?Add?the?audio?and?video?streams?using?the?default?format?codecs
*?and?initialize?the?codecs.?*/
if?(fmt->video_codec?!=?AV_CODEC_ID_NONE)?{
fmt->video_codec?=?AV_CODEC_ID_H264;
ret?=?add_stream(&video_st?&video_codec?fmt->video_codec);
if?(ret? printf(“Could?not?add?video?stream.\n“);
return?-1;
}
have_video?=?1;
}
if?(fmt->audio_codec?!=?AV_CODEC_ID_NONE)?{
fmt->audio_codec?=?AV_CODEC_ID_AAC;
ret?=?add_stream(&audio_st?&audio_codec?fmt->audio_codec);
if?(ret? printf(“Could?not?add?audio?stream.\n“);
return?-1;
}
have_audio?=?1;
}

/*?Now?that?all?the?parameters?are?set?we?can?open?the?audio?and
*?video?codecs?and?allocate?the?necessary?encode?buffers.?*/
if?(have_video)?{
ret?=?open_video(video_codec?&video_st?opt);
if?(ret? printf(“Could?not?open?video.\n“);
return?-1;
}
}

if?(have_audio)?{
ret?=?open_audio(audio_codec?&audio_st?opt);
if?(ret? printf(“Could?not?open?audio.\n“);
return?-1;
}
}

av_dump_format(oc?0?filename?1);

/*?open?the?output?file?if?needed?*/
if?(!(fmt->flags?&?AVFMT_NOFILE))?{
ret?=?avio_open(&oc->pb?filename?AVIO_FLAG_WRITE);
if?(ret? printf(“Could?not?open?‘%s‘\n“?filename);
return?-1;
}
}

/*?Write?the?stream?header?if?any.?*/
ret?=?avformat_write_header(oc?&opt);
if?(ret? printf(“Error?occurred?when?opening?output?file\n“);
return?-1;
}

return?0;
}
/*?
*?If?the?data?is?video?the?input?is?H264;?
*?If?the?data?is?audio?the?input?is?PCM;
*/
int?RtmpStream::writedata(AVMediaType?datatype?char?*data?int?datalen)
{
int?ret?=?0;

if?(AVMEDIA_TYPE_VIDEO?==?datatype)?{
ret?=?write_video_frame(&video_s

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件??????11900??2019-08-20?15:36??rtmpstream.cpp

?????文件???????1474??2019-08-20?16:22??rtmpstream.h

?????文件????????438??2019-08-20?16:50??yffmpeg.h

?????文件????????475??2019-08-23?17:07??readme

-----------?---------??----------?-----??----

????????????????14287????????????????????4


評論

共有 條評論