PDA

View Full Version : Buffer with encode frame in x264


Fe++
24th August 2009, 15:59
Hi dear community,
I'm studying on the code of x264.c for implementing an encoder that take an YUV420 picture and encode an h264 frame.

In particular, I observe this function

static int Encode_frame( x264_t *h, hnd_t hout, x264_picture_t *pic )
{
x264_picture_t pic_out;
x264_nal_t *nal;
int i_nal, i;
int i_file = 0;

if( x264_encoder_encode( h, &nal, &i_nal, pic, &pic_out ) < 0 )
{
fprintf( stderr, "x264 [error]: x264_encoder_encode failed\n" );
}

for( i = 0; i < i_nal; i++ )
{
int i_size;

if( mux_buffer_size < nal[i].i_payload * 3/2 + 4 )
{
mux_buffer_size = nal[i].i_payload * 2 + 4;
x264_free( mux_buffer );
mux_buffer = x264_malloc( mux_buffer_size );
}

i_size = mux_buffer_size;
x264_nal_encode( mux_buffer, &i_size, 1, &nal[i] );
i_file += p_write_nalu( hout, mux_buffer, i_size );
}
if (i_nal)
p_set_eop( hout, &pic_out );

return i_file;
}

In this function, where I can extract the complete encoded frame? is mux_buffer the frame that i can save in file? i don't find any comment that suggest where is store the encoded frame, please help me. Thanks in advance.
Best regards

Fe++
26th August 2009, 11:34
The frame is contained in the various nal unit referenced by nal pointer. Storing the various nal unit we obtain the complete h264 frame.

TheGuitArsenal
31st August 2009, 04:12
Hey,

I am attempting to write a piece of code that will take images coming in and write them to an AVI stream with the x264 codec. All goes well with the encoder installed on the machine and using the avifil32.dll interface, but the problem is that I am unable to ensure that the codec can be installed on the computer that will do the processing. I'm trying to re-use the code that I have already written for the avifil32 dll (I'm working in C# and going to other languages is not the easiest/fastest solution. As I see it, as the functions are not the same, there has to be a map (whether it be a register map or dll) that points a function from the avifil32.dll to the x264vfw.dll. Does anyone know if there is a dll that points the avifil dll to the codec?

Thanks, Guitarsenal

LoRd_MuldeR
31st August 2009, 04:31
It is highly recommended to NOT use x264 through the antiquated VFW interface! You also shouldn't store H.264 streams in an AVI container ;)

Why do you want to go the ugly way through VFW and x264vfw, if you could call libx264 directly through its native interface ???