//STMPEG.h
#include <stdlib.h>
#include <string.h>
#pragma once
extern "C" {
#endif
#include <libavcodec/avcodec.h>
#include<libavformat/avformat.h>
#include <libswscale/swscale.h>
#ifdef __cplusplus
}
#endif
class CSTMPEG
{
public:
private:
void InitMPEGData(MPEG_TYPE type);
//把图象颠倒过来
void RGBBuffer2RGBFrame(AVFrame *pRGBFrame, int width, int height,int bpp, uint8_t* pRGBBuffer);
AVFrame *alloc_picture(int pix_fmt, int width, int height);
bool open_video(AVFormatContext *pFormatContext, AVStream*pVideoStream);
AVStream *add_video_stream(AVFormatContext *pFormatContext, intcodec_id);
bool write_video_frame(AVFormatContext *pFormatcontext, AVStream*pAudioStream);
void close_video(AVFormatContext *pFormatcontext, AVStream*pVideoStream);
private:
MPEG_TYPE m_MPEGType;
int m_nWidth, m_nHeight;
float m_fFrameRate;
float m_fBitRate;
int
int srcWidth;
int srcHeight;
AVFrame
AVFrame
uint8_t*
const int
//使用流来读写文件
AVOutputFormat *m_pOutputFormat;
AVFormatContext *m_pFormatContext;
AVStream
AVStream
};
实现文件:
//STMPEG.cpp
#include "stmpeg.h"
#define LineWidthBytes(biWidth, biBitCount) ((biWidth * biBitCount+ 31) / 32 * 4)
CSTMPEG::CSTMPEG(): m_nOutBufSize(200000)
{
m_MPEGType
m_nWidth
m_nHeight
m_fFrameRate = 25;
m_fBitRate
m_nFrame
m_pRGBFrame
m_pYUVFrame
m_pFormatContext= NULL;
m_pVideoStream = NULL;
m_pAudioStream = NULL;
}
CSTMPEG::~CSTMPEG(void)
{
}
void CSTMPEG::InitMPEGData(MPEG_TYPE type)
{
switch(type) {
case VCD_PAL:
{
}
break;
case VCD_NTSC:
{
}
break;
case SVCD_PAL:
{