Question

I use libx264 on ubuntu, programming use C.

I want to set x264 encoder output 720P. The input image size is 1080P. How to set the params?

I don't know whether set the two parameters:

param->vui.i_sar_width = ?; 
param->vui.i_sar_height= ?;

or another parameter crop-rect?

Was it helpful?

Solution

if you want your output video to be of 720P, you have to downsample your each frame before giving it to libX264.initilize a SwsContext which is available in swsScale.h of ffmpeg and use it as a converter

SwsContext* convertContext = sws_getContext(parameters.i_width,parameters.i_height, PIX_FMT_BGR24, parameters.i_width,parameters.i_height,PIX_FMT_YUV420P, SWS_FAST_BILINEAR, NULL, NULL, NULL);

on each call of your encode frame convert your frame using the converter above. Here image.data is the pointer to your raw image data. Your downsampled image data will be copied into picture_in variable which is x264_picture_t type

int srcStride = parameters.i_width * 3;
x264_picture_alloc(&picture_in, X264_CSP_I420, parameters.i_width, parameters.i_height);
sws_scale(convertContext, &(image.data), &srcStride, 0, parameters.i_height, picture_in.img.plane, picture_in.img.i_stride);

Now you can pass the image data to encoder and you will get the video in 720P. also you need to initialize the converter only once and use it again and again. you can optimize it in your own way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top