?? ffmpeg_main_encoder.c.user
字號:
#include "../../libavcodec/avcodec.h"
#include <stdio.h>
#include <assert.h>
//#include "ftmcp_api.h"
//#include "portab.h"
//#include "xvid.h"
//#include "encoder.h"
//#include "motion.h"
//#include "map_driver.h"
#include "Mp4Venc.h"
#include "../faraday_mpeg4_common/dev_mem.h"
#include "./enc_test_mem.h"
typedef struct FmpegEncContext {
void * pEnc;
AVFrame picture;
int frame_count;
unsigned char *bitstream_phy_buffer;
unsigned char *bitstream_virt_buffer;
} FmpegEncContext;
// --------------------------------------------------------------------
// return
// 0 ==> failure
// other ==> encoder handle
// --------------------------------------------------------------------
int enc_init(AVCodecContext *avctx)
{
FmpegEncContext *s = avctx->priv_data;
FMP4_ENC_PARAM enc_param;
unsigned int * base;
//++ Foster
// base = (unsigned int *)ioremap(0x90910000, 0x100000);
base = (unsigned int *)ioremap(0x90700000, 0x100000);
//-- Foster
if (base == 0) { /// maping failure
printf("mpeg4 maping failure\n");
return -1;
}
// printf("mpeg4 virt addr = 0x%x\n", base);
// pass parameter from ffmpeg to this encoder
avctx->coded_frame = &s->picture;
// set the encoding parameters
enc_param.pu32BaseAddr = base;
enc_param.u32BitRate=avctx->bit_rate / 1000;
enc_param.u32FrameWidth=avctx->width;
enc_param.u32FrameHeight=avctx->height;
enc_param.fFrameRate=(float)avctx->frame_rate/(float)avctx->frame_rate_base;
enc_param.u32InitialQuant=4;
enc_param.u32IPInterval=15;
enc_param.bShortHeader=0;
//++ Foster
enc_param.bEnable4MV=0;
// enc_param.bEnable4MV=1;
enc_param.bH263Quant=1;
enc_param.bResyncMarker=0;
#if 0 //ivan
enc_param.u32MaxQuant=31;
enc_param.u32MinQuant=1;
#else
enc_param.u32MaxQuant=avctx->qmax;
enc_param.u32MinQuant=avctx->qmin;
#endif
//++ Foster
// enc_param.u32Quant=16;
if(avctx->bit_rate)
enc_param.u32Quant=0;
else
enc_param.u32Quant=2;
enc_param.pu8ReConFrameCur=NULL;
enc_param.pu8ReConFrameRef=NULL;
enc_param.p16ACDC=NULL;
// to install the DMA memory allocation function
enc_param.pfnDmaMalloc=Enc_TM_DmaMalloc;
enc_param.pfnDmaFree=Enc_TM_DmaFree;
if((s->bitstream_virt_buffer = (unsigned char *) Enc_TM_DmaMalloc(
enc_param.u32FrameWidth*enc_param.u32FrameHeight*3/2,
16,16,&s->bitstream_phy_buffer))==NULL){
return 0;
}
// set the encoded bitstream buffer for one single frame
enc_param.pu8BitstreamAddr=s->bitstream_phy_buffer;
//-- Foster
// to create the encoder object
s->pEnc=FMpeg4EncCreate(&enc_param);
s->frame_count = 0;
if(!s->pEnc){
printf("FMpeg4EncCreate return fail\n");
iounmap((unsigned char *)base, 0x100000);
return -1;
}
return 0;
}
int enc_close(AVCodecContext *avctx)
{
FmpegEncContext *s = avctx->priv_data;
// free the allocated bitstream buffer for one single frame
//++ Foster
Enc_TM_DmaFree(s->bitstream_virt_buffer,s->bitstream_phy_buffer);
//-- Foster
// release the encoder object
FMpeg4EncDestroy(s->pEnc);
return 0;
}
// --------------------------------------------------------------------
// input:
// y_phys = 0 ==> not coded
// other ==> coded,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -