Newest 'libx264' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/libx264

Les articles publiés sur le site

  • FFmpeg - generate x264 CBR video transport stream with C-API

    6 juillet 2020, par ZeroDefect

    Using various posts sprinkled around the Internet, including this one here on SO, I've been able to understand how to use the FFmpeg cli to generate a CBR video bitrate using the x264 codec (wrapped in an MPEG-2 transport stream). Note: I'm concerned with the video bitrate - nothing else.

    ffmpeg -i cbr_test_file_input.mp4 -c:v libx264 -pix_fmt yuv420p -b:v 6000000 -preset fast -tune film -g 25 -x264-params vbv-maxrate=6000:vbv-bufsize=6000:force-cfr=1:nal-hrd=cbr -flags +ildct+ilme x264_cbr_test_output.ts
    

    However, I'm trying to approach this from an FFmpeg C-API point of view. I'm having issues. I've knocked together some code to try do something very similar to what is being done in the FFmpeg CLI. I can generate a transport stream of what I think should be CBR, but the profile of the video bitrate is very different from what I thought was the FFmpeg cli equivalent:

    The initialisation of the AVCodecContext looks something like:

          av_dict_set(&pDict, "preset", "faster", 0);
          av_dict_set(&pDict, "tune", "film", 0);
          av_dict_set_int(&pDict, "rc-lookahead", 25, 0);
    
          pCdcCtxOut->width = pCdcCtxIn->width;
          pCdcCtxOut->height = pCdcCtxIn->height;
          pCdcCtxOut->pix_fmt = AV_PIX_FMT_YUV420P;
          pCdcCtxOut->gop_size = 25;
    
          // Going for 6Mbit/s
          pCdcCtxOut->bit_rate = 6000000;
          //pCdcCtxOut->rc_min_rate = pCdcCtxOut->bit_rate;
          pCdcCtxOut->rc_max_rate = pCdcCtxOut->bit_rate;
          pCdcCtxOut->rc_buffer_size = pCdcCtxOut->bit_rate;
          pCdcCtxOut->rc_initial_buffer_occupancy = static_cast((pCdcCtxOut->bit_rate * 9) / 10);
    
          std::string strParams = "vbv-maxrate="
                                  + std::to_string(pCdcCtxOut->bit_rate / 1000)
                                  + ":vbv-bufsize="
                                  + std::to_string(pCdcCtxOut->bit_rate / 1000)
                                  + ":force-cfr=1:nal-hrd=cbr";
    
          av_dict_set(&pDict, "x264-params", strParams.c_str(), 0);
    
          pCdcCtxOut->field_order = AV_FIELD_TT;
          pCdcCtxOut->flags = (AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME | AV_CODEC_FLAG_CLOSED_GOP);
    
          // WARN: Make some assumptions here!
          pCdcCtxOut->time_base = AVRational{1,25};
          pCdcCtxOut->framerate = AVRational{25,1};
          pCdcCtxOut->sample_aspect_ratio = AVRational{64,45};
    

    The output graphs appear very different:

    FFmpeg CLI output

    Above is the FFmpeg CLI output - video bitrate holds fairly steady.

    enter image description here

    Above is the output of my sample application - some significant dips in the video bitrate.

    I've taken this a step further and created a git repo consisting of:

    • Code of sample application
    • Test input file (.mp4)
    • Outputs (.ts file) of tests
    • Graphs of output bitrates.
  • FFmpeg licence requirements when not distributing [closed]

    15 juin 2020, par Dodu

    I am making a website that uses FFmpeg, and by extension libx264. The website takes a video and adds filters etc to it, then serves that new video to the user.

    There are various answers about distributing libx264 (and others) as part of a commercial product such as:

    Can I use FFmpeg in a commercial product?

    Since I am generating content using the library, but not distributing the library itself, I'm not sure where this leaves me.

    Do I need a license to libraries? Or because there is no distribution, are licenses generally not needed?

    Any advice/links/other resources that may be helpful would be greatly appreciated.

  • FFMPEG licencing

    14 juin 2020, par Dodu

    I am making a website that uses FFMPEG, and by extention libx264. The website takes a video and adds filters etc to it, then serves that new video to the user.

    There are various answers about distributing libx264 (and others) as part of a comercial product such as:

    https://video.stackexchange.com/questions/14802/can-i-use-ffmpeg-in-a-commercial-product/14804#:~:text=Yes%2C%20you%20can%20use%20FFmpeg,LGPL)%20version%202.1%20or%20later.&text=So%2C%20yes%2C%20you%20can%20definitely,usage%2C%20distribution%2C%20and%20modification.

    Since I am generating content using the library, but not distributing the library itself, I'm not sure where this leaves me.

    Do I need a licence to libraries? Or because there is no distribution, are licences generally not needed?

    Any advice/links/other resources that may be helpful would be greatly appreciated.

    Thanks

    Dodu

  • Compiling ijkplayer x264 for android x86 & x86_64 Architecture , error : unknown type name 'v4si'

    4 juin 2020, par Lins Louis

    I'm trying to build this project https://github.com/simplepeng/ijkplayer-x264 but building x264 failing for x86 and x86_64 architectures . Link of the issue : https://github.com/simplepeng/ijkplayer-x264/issues/1

  • Compiling static libs of ffmpeg with x264 in Msys2 for Visual Studio, but libx264 is never found

    29 mai 2020, par Blake Senftner

    Having previously downloaded and compiled ffmpeg 4.2.2 to static libraries using MSYS2 and the Visual Studio 2015 x64 tool chain. I want to add the x264 codec from VLC/VideoLan, compiling that to a static library as well. However, running Configure for ffmpeg produces an error saying "libx264 not found."

    I built ffmpeg without VideoLAN's x264 at "/c/ThirdParty/opt/ffmpeg-4.2.2" with "make install" installing to "/c/ThirdParty/opt/ffmpeg-4.2.2/ffmpeg_build" .

    I am using the following steps to compile from source x264 and add it to the ffmpeg build using the same VS2015 tool chain:

    1. Launch an "VS2015 x64 Natice Tools Command Prompt"
    2. From that VS2015 command prompt, run "c:\msys64\msys2_shell.cmd -mingw64 -use-full-path"
    3. From inside the MSYS2 shell, run "cd /c/ThirdParty/opt"
    4. git clone http://git.videolan.org/git/x264.git
    5. cd x264
    6. CC=cl ./configure --enable-static --prefix=/c/ThirdParty/opt/ffmpeg-4.2.2/ffmpeg_build --disable-cli
    7. make
    8. make install
    9. cd ../ffmpeg-4.2.2
    10. PKG_CONFIG_PATH=/c/ThirdParty/opt/ffmpeg-4.2.2/ffmpeg_build/lib \ ./configure --prefix=./ffmpeg_build --toolchain=msvc --arch=x86_64 \ --target-os=win64 --extra-cflags=-MT --extra-cxxflags=-MT \ --extra-ldflags=-L/c/ThirdParty/opt/ffmpeg-4.2.2/ffmpeg_build/lib \ --enable-x86asm --enable-asm --enable-static --disable-shared \ --disable-debug --enable-gpl --enable-avresample --enable-libx264

    The steps work, compiling x264 fine, but the output for ffmpeg's Configure is "ERROR: libx264 not found".

    I have also tried the variation of using these two lines in place of steps 6 and 10 above:

    • CC=cl ./configure --enable-static --prefix=/usr/local --disable-cli
    • PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH ./configure --prefix=./ffmpeg_build --toolchain=msvc --arch=x86_64 --target-os=win64 --extra-cflags=-MT --extra-libs=/usr/local/lib/libx264.lib --extra-cxxflags=-MT --enable-x86asm --enable-asm --enable-static --disable-shared --disable-debug --enable-gpl --enable-avresample --enable-libx264

    This version will get past Configure, where I am able to run "make", but the make fails with a series of unresolved X264_* functions while linking ffmpeg_g.exe, 14 unresolved functions in total. The errors at shown at the bottom, but first:

    When I look in /c/ThirdParty/opt/ffmpeg-4.2.2/ffmpeg_build/lib I see:

    $ ls -l ./ffmpeg_build/lib
    total 50988
    -rw-r--r-- 1 blake blake 27184250 May 11 16:29 libavcodec.a
    -rw-r--r-- 1 blake blake   231304 May 11 16:29 libavdevice.a
    -rw-r--r-- 1 blake blake  8574628 May 11 16:29 libavfilter.a
    -rw-r--r-- 1 blake blake  8081930 May 11 16:29 libavformat.a
    -rw-r--r-- 1 blake blake  1300118 May 11 16:29 libavutil.a
    -rw-r--r-- 1 blake blake    61844 May 11 16:29 libpostproc.a
    -rw-r--r-- 1 blake blake   348732 May 11 16:29 libswresample.a
    -rw-r--r-- 1 blake blake  1316008 May 11 16:29 libswscale.a
    -rw-r--r-- 1 blake blake  5086976 May 28 18:08 libx264.lib
    drwxr-xr-x 1 blake blake        0 May 28 18:08 pkgconfig
    

    Likewise for /c/ThirdParty/opt/ffmpeg-4.2.2/ffmpeg_build/lib/pkgconfig:

    $ ls -l ./ffmpeg_build/lib/pkgconfig/
    total 9
    -rw-r--r-- 1 blake blake 353 May 11 16:29 libavcodec.pc
    -rw-r--r-- 1 blake blake 554 May 11 16:29 libavdevice.pc
    -rw-r--r-- 1 blake blake 449 May 11 16:29 libavfilter.pc
    -rw-r--r-- 1 blake blake 393 May 11 16:29 libavformat.pc
    -rw-r--r-- 1 blake blake 306 May 11 16:29 libavutil.pc
    -rw-r--r-- 1 blake blake 317 May 11 16:29 libpostproc.pc
    -rw-r--r-- 1 blake blake 322 May 11 16:29 libswresample.pc
    -rw-r--r-- 1 blake blake 315 May 11 16:29 libswscale.pc
    -rw-r--r-- 1 blake blake 300 May 28 18:08 x264.pc
    

    And looking in /usr/local/lib I see libx264.lib and the pkgconfig directory.

    The errors generated by my most recent attempts look like:

    LD      ffmpeg_g.exe
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_param_default referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_param_parse referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_param_default_preset referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_param_apply_fastfirstpass referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_param_apply_profile referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_picture_init referenced in function X264_frame
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_encoder_open_160 referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_encoder_reconfig referenced in function reconfig_encoder
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_encoder_headers referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_encoder_encode referenced in function X264_frame
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_encoder_close referenced in function X264_close
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_encoder_delayed_frames referenced in function X264_frame
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_encoder_maximum_delayed_frames referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_levels referenced in function X264_init
    ffmpeg_g.exe : fatal error LNK1120: 14 unresolved externals
    make: *** [Makefile:111: ffmpeg_g.exe] Error 96
    

    Maybe something wrong with the --extra-ldflags or --extra-libs options of ffmpeg's Configure, but after trying variations and google searching, I come asking you. Do you know what is wrong with this ffmpeg Configure line? Step 10, above.