资源简介
内存中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版-杨卫东译-课后答案
相关资源
- ffmpeg-4.2.1-win32-dev.zip
- M3U8视频PC机64位辅助工具2.0 —&md
- librtmp 封装类 VS 2015
- ffmpeg-3.2.tar.bz2
- 适用于VC的FFMpeg静态库已编译)
- 使用ffmpeg api解码h264视频码流,并且能
- MP4v2录制rtsp流存为MP4文件
- rtsp摄像头推流上云使用浏览器播放
- 手机USB摄像头直播及服务器推流手机
- 搭建rtmp流媒体服务器的nginx
- 摄像头推流到rtmp
- [8] ffmpeg + SDL2 实现的视频播放器「快
- ffmpegexe文件
- RTMP 规范中英文对照阅读版[带书签]
- qt5.8实现rtsp流播放
- OpenCV 1.0.0 patch for ffmpeg errors
- ffmpeg将一个视频文件解码输出bmp和j
- 支持OpenCV3.2的opencv_ffmpeg.7z
-
Mpla
yer.exe 最新版 - nginx rtmp转发服务器
- ffmpeg 硬件加速
- FFmpeg解码MP4分别播放YUV视频和PCM音频
- rtmp+nginx实现rtmp直播
- 免部署的Windows 平台下的nginx-rtmp-win
- ffmpeg(amr转换mp3).exe.zip
- zw_csharp_ffmpeg_rtsp_demo.zip
- 比较新版本的ffmpeg.exe
-
ijkpla
yer-anddroid编译好的so库 已经非 - 编译FFmpeg3.2.2生成的库文件及头文件
- 流媒体服务器源码包nginx+rtmp
评论
共有 条评论