ffmpeg实现摄像头拉流_ffmpeg处理rtmp/文件/rtsp的推流和拉流

//ffmpeg.cpp

#include "ffmpeg.h"

int nRet = 0;

AVFormatContext* icodec = NULL;

AVInputFormat* ifmt = NULL;

char szError[256];

AVFormatContext* oc = NULL;

AVOutputFormat* ofmt = NULL;

AVStream * video_st = NULL;

AVStream * audio_st = NULL;

AVCodec *audio_codec;

AVCodec *video_codec;

double audio_pts = 0.0;

double video_pts = 0.0;

int video_stream_idx = -1;

int audio_stream_idx = -1;

AVPacket pkt;

AVBitStreamFilterContext * vbsf_aac_adtstoasc = NULL;

//video param

int m_dwWidth = 0;

int m_dwHeight = 0;

double m_dbFrameRate = 25.0;  //帧率

AVCodecID video_codecID = AV_CODEC_ID_H264;

AVPixelFormat video_pixelfromat = AV_PIX_FMT_YUV420P;

char spspps[100];

int spspps_size = 0;

//audio param

int m_dwChannelCount = 2;      //声道

int m_dwBitsPerSample = 16;    //样本

int m_dwFrequency = 44100;     //采样率

AVCodecID audio_codecID = AV_CODEC_ID_AAC;

int audio_frame_size  = 1024;

int InitInput(char * Filename,AVFormatContext ** iframe_c,AVInputFormat** iinputframe)

{

int i = 0;

nRet = avformat_open_input(iframe_c, Filename,(*iinputframe), NULL);

if (nRet != 0)

{

av_strerror(nRet, szError, 256);

printf(szError);

printf("\n");

printf("Call avformat_open_input function failed!\n");

return 0;

}

if (av_find_stream_info(*iframe_c) 

{

printf("Call av_find_stream_info function failed!\n");

return 0;

}

//输出视频信息

av_dump_format(*iframe_c, -1, Filename, 0);

//添加音频信息到输出context

for (i = 0; i nb_streams; i++)

{

if ((*iframe_c)->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)

{

video_stream_idx = i;

m_dwWidth = (*iframe_c)->streams[i]->codec->width;

m_dwHeight = (*iframe_c)->streams[i]->codec->height;

m_dbFrameRate = av_q2d((*iframe_c)->streams[i]->r_frame_rate);

video_codecID = (*iframe_c)->streams[i]->codec->codec_id;

video_pixelfromat = (*iframe_c)->streams[i]->codec->pix_fmt;

spspps_size = (*iframe_c)->streams[i]->codec->extradata_size;

memcpy(spspps,(*iframe_c)->streams[i]->codec->extradata,spspps_size);

}

else if ((*iframe_c)->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)

{

audio_stream_idx = i;

m_dwChannelCount = (*iframe_c)->streams[i]->codec->channels;

switch ((*iframe_c)->streams[i]->codec->sample_fmt)

{

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值