Newest 'libx264' Questions - Stack Overflow
Les articles publiés sur le site
-
Confused about x264 and encoding video frames
26 février 2015, par spartygwI built a test driver for encoding a series of images I have captured. I am using libx264 and based my driver off of this guy's answer:
In my case I am starting out by reading in a JPG image and converting to YUV and passing that same frame over and over in a loop to the x264 encoder.
My expectation was that since the frame is the same that the output from the encoder would be very small and constant.
Instead I find that the NAL payload is varied from a few bytes to a few KB and also varies highly depending on the frame rate I specify in the encoder parameters.
Obviously I don't understand video encoding. Why does the output size vary so much?
int main() { Image image(WIDTH, HEIGHT); image.FromJpeg("frame-1.jpg"); unsigned char *data = image.GetRGB(); x264_param_t param; x264_param_default_preset(¶m, "fast", "zerolatency"); param.i_threads = 1; param.i_width = WIDTH; param.i_height = HEIGHT; param.i_fps_num = FPS; param.i_fps_den = 1; // Intra refres: param.i_keyint_max = FPS; param.b_intra_refresh = 1; //Rate control: param.rc.i_rc_method = X264_RC_CRF; param.rc.f_rf_constant = FPS-5; param.rc.f_rf_constant_max = FPS+5; //For streaming: param.b_repeat_headers = 1; param.b_annexb = 1; x264_param_apply_profile(¶m, "baseline"); // initialize the encoder x264_t* encoder = x264_encoder_open(¶m); x264_picture_t pic_in, pic_out; x264_picture_alloc(&pic_in, X264_CSP_I420, WIDTH, HEIGHT); // X264 expects YUV420P data use libswscale // (from ffmpeg) to convert images to the right format struct SwsContext* convertCtx = sws_getContext(WIDTH, HEIGHT, PIX_FMT_RGB24, WIDTH, HEIGHT, PIX_FMT_YUV420P, SWS_FAST_BILINEAR, NULL, NULL, NULL); // encoding is as simple as this then, for each frame do: // data is a pointer to your RGB structure int srcstride = WIDTH*3; //RGB stride is just 3*width sws_scale(convertCtx, &data, &srcstride, 0, HEIGHT, pic_in.img.plane, pic_in.img.i_stride); x264_nal_t* nals; int i_nals; int frame_size = x264_encoder_encode(encoder, &nals, &i_nals, &pic_in, &pic_out); int max_loop=15; int this_loop=1; while (frame_size >= 0 && --max_loop) { cout << "------------" << this_loop++ << "-----------------\n"; cout << "Frame size = " << frame_size << endl; cout << "output has " << pic_out.img.i_csp << " colorspace\n"; cout << "output has " << pic_out.img.i_plane << " # img planes\n"; cout << "i_nals = " << i_nals << endl; for (int n=0; n
-
Can't write .mp4 files - Could not open codec 'libx264' : Unspecified error
17 février 2015, par margaridagomesDays ago I installed the latest 2.4 branch withou ffmpeg. I'm using Ubuntu 14.04 and I don't have at all ffmpeg in my Virtual Machine.
I want to write .mp4 video files and the input files are also .mp4. The input codec is avc1.
I can't obtain any results, the errors can be seen below.
Error
[libx264 @ 0x9357bc0] broken ffmpeg default settings detected [libx264 @ 0x9357bc0] use an encoding preset (e.g. -vpre medium) [libx264 @ 0x9357bc0] preset usage: -vpre
-vpre [libx264 @ 0x9357bc0] speed presets are listed in x264 --help [libx264 @ 0x9357bc0] profile is optional; x264 defaults to high Could not open codec 'libx264': Unspecified error Could not open the output video for write: /home/margarida/exams_2014/Output.mp4 Simplified Code
int main(int argc, char *argv[]) { VideoWriter outputVideo; // Get Codec Type int ex = static_cast
(cap.get(CV_CAP_PROP_FOURCC)); // Transform from int to char via Bitwise operators char EXT[] = { (char) (ex & 0XFF), (char) ((ex & 0XFF00) >> 8), (char) ((ex & 0XFF0000) >> 16), (char) ((ex & 0XFF000000) >> 24), 0 }; // Acquire input size Size S = Size((int) cap.get(CV_CAP_PROP_FRAME_WIDTH), (int) cap.get(CV_CAP_PROP_FRAME_HEIGHT)); cout << "Input codec type: " << EXT << endl; // Open the output outputVideo.open(newname, ex, cap.get(CV_CAP_PROP_FPS), S, true); if (!outputVideo.isOpened()) { cout << "Could not open the output video for write " << endl; return -1; } while (true) { cap >> frame; if (frame.empty()) { cerr << "nao apanhou frame" << endl; break; } cinzento = acinzentar(frame); imshow("Cinzento", cinzento); outputVideo.write(cinzento); switch(waitKey(10)){ case 27: //'esc' has been pressed (ASCII value for 'esc' is 27) //exit program. return 0; } } return 0; } My cmake was this:
cmake -D WITH_TBB=ON -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_VTK=ON -D WITH_FFMPEG=OFF -D WITH_IPP=OFF ..
Can anyone help solving my problem?
Thanks in advance.
-
Using WebHDFS to play video over HTTP
3 février 2015, par Qin.YangI used ffmpeg + libx264 to convert file format as H264, then uploaded the file to Hadoop. I used WebHDFS to access the file by HTTP, but can not online play. If I download this file over HTTP, it can play by HTML5 video. My English is poor, hope you know what I mean.
-
how to output a H264 encoded video with ffmpeg in php exec() command
28 janvier 2015, par Harish KumarI have the following php command to generate a water marked video with a input video, which is working fine. but its not playing in the browser anymore. To do so i research a lot over web and i found that i need to upgrade the libx264 library on my ffmpeg extension on the server which i already did. now what modification do i do to make my command work to generate H264 encode video.
here is the command i am using
/usr/local/bin/ffmpeg -i baby.mp4 -i sos.png -filter_complex \"overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2\" -codec:a copy watermarked-video.mp4
-
x264 : Using NAL size limitation ruins the stream
21 janvier 2015, par Dan TumaykinI'm using x264 to compress a video stream from a webcam with this settings:
x264_param_default_preset(¶m, "veryfast", "zerolatency"); param.i_threads = 1; param.i_fps_den = 1; param.b_annexb = 1; param.i_keyint_max = 30; param.rc.i_rc_method = X264_RC_CRF; param.rc.f_rf_constant = 25; param.rc.f_rf_constant_max = 35; param.b_repeat_headers = 1; x264_param_apply_profile(¶m, "baseline"); param.i_slice_max_size = X264_NAL_MAX_SIZE;
I would like to fit NAL into MTU size, but if I set a small max size, the stream is ruined - it blinks randomly between black and white, with some clues of original image in background. The bigger is the max_size, less probable is for the stream to be ruined. So my question is - can we have small NALUs and a correct video stream?
UPD: I use FFmpeg as a decoder.