笔记:ffmpeg使用实例:rgb + pcm --> flv(音频编码+视频编码+muxer)

郑重声明:以下代码是为了便于查找而做的笔记,并不完善,仅供参考。请知晓!#include "stdafx.h"extern "C"{#include "libavcodec/avcodec.h"#include "libavformat/avformat.h"#include "libswscale/swscale.h"#include "libswre
摘要由CSDN通过智能技术生成

郑重声明:以下代码是为了便于查找而做的笔记,并不完善,仅供参考。请知晓!


#include "stdafx.h"



extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libswresample/swresample.h"
#include "SDL2/SDL.h"
};


#pragma comment(lib, "avcodec.lib")
#pragma comment(lib, "avformat.lib")
#pragma comment(lib, "avutil.lib")
#pragma comment(lib, "swscale.lib")
#pragma comment(lib, "swresample.lib")
#pragma comment(lib, "SDL2.lib")
#pragma comment(lib, "SDL2main.lib")


#define MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48KHZ 32bit audio -> 32bit / 8 * 48000 * 1 = 192000 Byte


int main(int argc, char* argv[])
{
//AVFormatContext* ofmt_ctx_h264 = NULL;
//const char* output_filepath_h264 = NULL;


//AVFormatContext* ofmt_ctx_aac = NULL;
//const char* output_filepath_aac = NULL;


AVStream* ostream_video = NULL;
AVStream* ostream_audio = NULL;


AVCodecContext* codec_ctx_2h264 = NULL;
AVCodec* codec_2h264 = NULL;


AVCodecContext* codec_ctx_2aac = NULL;
AVCodec* codec_2aac = NULL;


uint8_t* video_buffer_in = NULL;
int video_buffer_size_in = -1;
uint8_t* video_buffer_out = NULL;
int video_buffer_size_out = -1;
struct SwsContext* video_convert_ctx = NULL;


uint8_t* audio_buffer_in = NULL;
int audio_buffer_size_in = -1;
uint8_t* audio_buffer_out = NULL;
int audio_buffer_size_out = -1;
struct SwrContext* audio_convert_ctx = NULL;


AVFrame  frame_video = { 0 };
AVFrame  frame_audio = { 0 };


av_register_all();
avformat_network_init();


//
AVFormatContext* ofmt_ctx = NULL;
const char* output_filepath = NULL;


output_filepath = "output0328.flv";
if (avformat_alloc_output_context2(&ofmt_ctx, NULL, "flv", output_filepath) < 0)
{
return -1;
}


if (avio_open(&ofmt_ctx->pb, output_filepath, AVIO_FLAG_READ_WRITE) < 0)
{
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值