View Full Version : using libx264 with c++?
Selur
31st May 2008, 10:28
Any hint where to find some infos about how to use libx264 within c++ code.
backround: I'm wrote a small (qt4 based, cossplattform) gui for my personal encoding needs which calls x264 via commandline. So far so good. Now I wanted to to use libx264 instead of calling x264 via commandline and don't really know where to start. ;)
-> couldn't find any documentation via google and know hoping for some general direction hints where to find some documentation :)
thx
Selur
imcold
1st June 2008, 23:31
I doubt there is some more documentation than x264.c/h code, but the API is really simple and straightforward. To encode frames and save a raw h264 stream you have to:
- call x264_param_default to fill x264_param_t structure with defaults
- set basic encoding parameters: i_width, i_height (i_frame_total),
rc.i_rc_method and then some other encoding options, if you want to (probably yes...)
- create a new encoder handle with x264_encoder_open
- create a x264_picture_t with x264_picture_alloc( &pic, X264_CSP_I420, param.i_width, param.i_height );
- allocate buffer for bytestream data, that will be saved to file
encoding loop:
- set-up pic:
copy your yuv image to pic.img.plane[0]
pic.i_pts = param.i_fps_den * c; //timestamp
pic.i_type = X264_TYPE_AUTO; //frame type, let x264 decide
pic.i_qpplus1 = 0; //frame qp adjustment
- call x264_encoder_encode with your handle and pic,
you'll get (nal) pointers for x264_nal_encode and their count
- get all NAL data to buffer and then write it to file
for( i = 0; i < i_nal; i++ ) {
x264_nal_encode( buffer, &buf_size, 1, &nal[i] );
write buffer to file ...
}
loop until you feed all frames
and then call x264_encoder_encode with null pic until all delayed frames are encoded
- x264_encoder_close
- x264_picture_clean
That should be all, taken from x264.c and my own poorly tested tiny cli (I was translating x264.h to pascal and testing it...).
Selur
2nd June 2008, 05:47
thanks imcold for hinting how to do it :)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.