[x264-devel] Problem on using x264_encoder_encode
Alessandro Ferrari
alessandroferrari87 at gmail.com
Tue Aug 25 11:57:55 CEST 2009
Hi dear community,
I have a problem with the encoding using x264.
After I call x264_encoder_encode( h, &nal, &i_nal, pic, &pic_out) function
I have nal= NULL, i_nal=0 and the function return 0. I'm sure that pic
contain the correct image. The x264_t h is open using the default
parameters, i only change width and length of the video. The function don't
give me any error, it seems that it not encode any data. I include the code
of encoding function that I implement watching x264.c.
void MyFunction()
{
x264_param_t param;
x264_t *h;
x264_picture_t pic;
//Set the default parameters
x264_param_default( ¶m );
//Video settings
param->i_width = WIDTH;
param->i_height = HEIGHT;
//Open the encoder
if( ( h = x264_encoder_open( ¶m ) ) == NULL )
{
fprintf( stderr, "x264 [error]: x264_encoder_open failed\n" );
return -1;
}
/* Create a new pic */
x264_picture_alloc( &pic, X264_CSP_I420, param.i_width, param.i_height
);
//Launch the encode routine
Encode_frame( h , &pic );
//Release resoirce
x264_picture_clean( &pic );
x264_encoder_close(h);
}
int Encode_frame( x264_t *h , x264_picture_t *pic)
{
x264_nal_t *nal;
int i_nal, i;
x264_picture_t pic_out;
static int mux_buffer_size = 0;
uint8_t *mux_buffer = NULL;
int size;
//Set YUV420
pic->img.i_csp = X264_CSP_I420;
pic->img.i_plane = 3;
//I take the YUV image from a decoded image decode with ffmpeg
if (picture) {
for(i = 0; i < 3; i++){
pic->img.plane[i] = picture->data[i];
pic->img.i_stride[i] = picture->linesize[i];
}
pic->i_pts = picture->pts;
pic->i_type = X264_TYPE_AUTO;
}
//pic contains the correct image.
if( (i = x264_encoder_encode( h, &nal, &i_nal, pic, &pic_out)) <0)
return -1;
/*
* In this point nal is null, i_nal is 0. There isn't any error
message in the routine.
* As consequence the next loop don't execute any step.
*/
//packetize the encoded information in nal unit
for( i = 0; i < i_nal; i++ )
{
int i_size;
printf("\nNal unit n° %d",i);
if( mux_buffer_size < nal[i].i_payload * 3/2 + 4 )
{
mux_buffer_size = nal[i].i_payload * 2 + 4;
free( (void*) mux_buffer );
mux_buffer = (uint8_t*) malloc( mux_buffer_size );
}
size = size + mux_buffer_size;
i_size = mux_buffer_size;
x264_nal_encode( mux_buffer, &i_size, 1, &nal[i] );
write_nal_unit( mux_buffer , i_size ,"outframe.mpeg4" );
}
return size;
}
I'm excuse in advance. I'm not sure that is the correct mailing list (if not
is very appreciated if suggest me what mailing list is the right).
Many thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x264-devel/attachments/20090825/f63f9459/attachment-0001.htm>
More information about the x264-devel
mailing list