资源简介
内存中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 < 0) {
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 < 0) {
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 < 0) {
printf(“Could not open video.\n“);
return -1;
}
}
if (have_audio) {
ret = open_audio(audio_codec &audio_st opt);
if (ret < 0) {
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 < 0) {
printf(“Could not open ‘%s‘\n“ filename);
return -1;
}
}
/* Write the stream header if any. */
ret = avformat_write_header(oc &opt);
if (ret < 0) {
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
- 上一篇:基于PLC的中央空空调
- 下一篇:软件工程答案-第4版-杨卫东译-课后答案
相关资源
- nginx-rtmp-win32-master.rar
- onvif协议视频转码推流网页播放
- FFMEPG实现h264解码
- ffmpegh265rtmp.zip
- RTMP_H265推流直播技术研讨
- 屏幕采集\\录屏\\rtmp推流的一体化工具
- ffserver(windows下编译32位)
- qt_ffmpeg_mp4_export_and_import.zip
- 最简单的基于FFmpeg的推流器 1.2
- 简单的ffmpeg推流demo
- FFmpeg和SDL,读内存中的视频流,进行
- ffmpeg之pcm转AAC
- ffmpeg-2.8.14.tar.gz
- 利用ffmpeg的filter混音
- vs2010 ffmpeg实时解码h264码流
- ffmpeg 音视频转码代码
- windows上自己编译的最新的ffmpeg库
- Qt基于FFmpeg播放本地 H.264H264文件
- 从ffmpeg中抽取的h264解码器,可用于
- ffplay源代码
- 最简单的基于FFmpeg的推流器以推送R
- DVD文件VOB的生成代码
- FFmpeg 采集摄像头输出rtmp直播流媒体,
- 基于ffmpeg将avi视频转换为mp4视频
- (补充)修改output-example,将H.264AAC帧
- ffmpeg-win64位库
- X264实时编码,FFmpeg实时解码
- FFmpeg API读取视音频文件信息的一个工
- 使用FFmpeg采集摄像头图像和麦克风音
- opencv_ffmpeg249.dll
评论
共有 条评论