Anes wrote:
Reading msdn doc i could meke it work the ffencoder.dll
The thing is that ffencoder_init() throw me and exception. I don't know if anybody apart of rockcarry uses it, but im doing the following:
Code:
FFENCODER_PARAMS ffpar;
void * ffhandle;
ffpar.filename = szMovieDir; //this is the path to the .mp4 movie
// video params
ffpar.video_bitrate = 2000;
ffpar.video_width = 256;
ffpar.video_height = 240;
ffpar.frame_rate = 60;
ffpar.pixel_fmt = 32;
ffpar.scale_flags = 0; //i don't know what this member is for
ffpar.start_vpts = 0; //i don't know what this member is for
// audio params
ffpar.audio_bitrate = 128;
ffpar.sample_rate = 44100;
ffpar.channel_layout = 4; //taken by looking in ffmpeg doc, it is "mono" i think
ffpar.start_apts = 0; //i don't know what this member is for
ffpar.enable_log = 0; //i don't know what this member is for
ffhandle = ffencoder_init(&ffpar);
Any help??
I will explain more how to use ffencoder (also you could check test2.c of ffencode project):
1. first thing is call ffencoder_init to get a ffencoder context
you can call it like this:
Code:
void *encoder = NULL;
encoder = ffencoder_init(NULL);
if you pass NULL to ffencoder_init function, it will using the default encoding params:
Code:
static FFENCODER_PARAMS DEF_FFENCODER_PARAMS =
{
"test.mp4", // filename
128000, // audio_bitrate
48000, // sample_rate
AV_CH_LAYOUT_STEREO,// audio stereo
0, // start_apts
512000, // video_bitrate
256, // video_width
240, // video_height
30, // frame_rate
AV_PIX_FMT_BGRA, // pixel_fmt
SWS_FAST_BILINEAR, // scale_flags
0, // start_vpts
};
if you want use your own params, you can write code like this:
Code:
FFENCODER_PARAMS params = {0};
params.frame_rate = 60;
nes->encoder = ffencoder_init(¶ms);
this means you set video frame rate to 60Hz which is for NES NTSC. The other members of params are set to 0, ffencoder_init will treat then as default values as DEF_FFENCODER_PARAMS showing above.
2. explaintion of DEF_FFENCODER_PARAMS:
Code:
typedef struct
{
// output filename
char *filename;
// audio params
int audio_bitrate; // audio encoding bitrate
int sample_rate; // input audio simple rate, such as 44100 or 48000
int channel_layout; // audio channel layout, usually we use 16bit stereo, you should use constant defined in ffmpeg header files
int start_apts; // start_apts & start_vpts are used to make audio & video synchronous, usually set to 0
// if you find that after encoding to mp4 file audio or video is running fast than each other
// you could try to adjust these
// video params
int video_bitrate; // video encoding bitrate
int video_width; // width of video picture size
int video_height; // height of video picture size
int frame_rate; // frame rate of video
int pixel_fmt; // input pixel format, such as 16bit RGB565, 24bit RGB888, 32bit ARGB8888, please check ffmpeg header files
int scale_flags; // i think no need to care this
int start_vpts; // see above
// for debug
int enable_log; // don't care this, only for debug.
} FFENCODER_PARAMS;
3. when you meet a audio want to encode, you could write code like this:
Code:
//++ ffencoder encode audio
NES *nes = container_of(apu, NES, apu);
void *data[8] = { apu->audiobuf->lpdata };
ffencoder_audio(nes->encoder, data, apu->mixer_counter);
//-- ffencoder encode audio
first param of ffencoder_audio is context value which returned by ffencoder_init
second param type should like void *data[8];. but only data[0] is used to store audio buffer address.
third param is the byte length of audio buffer.
4. when you meet a video want to encoder, you could write code like this:
Code:
//++ ffencoder encode video
NES *nes = container_of(ppu, NES, ppu);
void *data [8] = { ppu->draw_buffer - 240 * ppu->draw_stride };
int linesize[8] = { ppu->draw_stride * 4 };
ffencoder_video(nes->encoder, data, linesize);
//-- ffencoder encode video
first param of ffencoder_video is context value which returned by ffencoder_init
second param type should like void *data[8];. most case only data[0] is used.
third param is the byte length of scanline stride.
5. after all things done, you could simply call:
Code:
// free ffencoder
ffencoder_free(nes->encoder);
ffencode is now work fine in my ffnes emulator. but for your project, you need debugging.
To analyze specific issues in specific ways.
I hope these could help you.