Newest 'libx264' Questions - Stack Overflow

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

Les articles publiés sur le site

  • What is this "fixing the build scripts" for compiling x264 ?

    29 mai 2020, par Blake Senftner

    I am trying to compile an all static build of source-customized ffmpeg libraries with the additional codecs from VideoLAN, such as their x264 codec. I am ultimately building for use in Windows with Visual Studio 2015 C++, so I am comparing a few compiling guides for my instructions.

    In the guide linked below (I located via Google searches) shows how to compile x264 with the VS2015 toolchain in MSYS2 without any special steps: https://gist.github.com/RangelReale/3e6392289d8ba1a52b6e70cdd7e10282

    While in this other guide, offered by the compiling guide pages from ffmpeg's web site, it includes steps for "fixing the build scripts" for x264: https://www.roxlu.com/2019/062/compiling-ffmpeg-with-x264-on-windows-10-using-msvc

    Problem being, when I "fix the build scripts" the configure script no longer finds a C compiler. Building with the first guide seems to work, but it was also written nearly 2 years ago, so perhaps the ffmpeg guide is doing some important fix? I don't know.

    I am:

    1. Running a "VS2015 x64 Native Tools Command Prompt"
    2. launching a pacman loaded msys2 shell via "msys2_shell.cmd -mingw64 -use-full-path"
    3. git cloning http://git.videolan.org/git/x264.git

    and at this point the two compiling guides vary, the first guide just cd's into x264 and runs configure while the other guide does some curl download of a config.guess file and then some sed manipulation of ./configure. Considering these instructions are "endorsed" by the ffmpeg site, I am left wondering what that is doing and how critical is it that these "special" steps cause my x264 configure to fail.

  • FFMPEG on cygwin failed to compile libx264 error : unknown type name ‘HMODULE’

    6 mai 2020, par Ivan Lee

    I am trying to compile libx264 in ffmpeg under cygwin environment.

    I have followed some directions from several sources from Koohiimaster's blog, FFMPEG compilation guide, SO post 1, SO post 2 but I always stuck at the same step which is the libx264 compilation (make) process.

    As mentioned in the FFMPEG compilation guide these steps should be followed in order to make libx264 works

    cd ~/ffmpeg_sources
    wget http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
    tar xjvf last_x264.tar.bz2
    cd x264-snapshot*
    PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" bindir="$HOME/bin" --enable-static --disable-opencl
    PATH="$HOME/bin:$PATH" make
    make install
    

    but when i enter this command PATH="$HOME/bin:$PATH" make the compiler always stop with the following errors:

    In file included from input/avs.c:49:0:
    ./extras/avisynth_c.h:825:3: error: unknown type name ‘HMODULE’
    HMODULE handle;
    ^
    

    I was wondering whether this is libx264 source's bug, but after I tried several earlier source version, it produce the same error. Any thoughts to solve this problem?

  • Matching a specific media format with ffmpeg/avconv

    5 mai 2020, par Markus A.

    I need to encode a video from static images in such a way that it format-matches another one so I can splice the video streams together.

    Here is the mediainfo of the file I'm trying to match:

    Video
    Format                                   : AVC
    Format/Info                              : Advanced Video Codec
    Format profile                           : Baseline@L3.1
    Format settings, CABAC                   : No
    Format settings, ReFrames                : 1 frame
    Codec ID                                 : 7
    Duration                                 : 2mn 46s
    Bit rate                                 : 1 614 Kbps
    Width                                    : 1 280 pixels
    Height                                   : 720 pixels
    Display aspect ratio                     : 16:9
    Frame rate mode                          : Variable
    Standard                                 : NTSC
    Color space                              : YUV
    Chroma subsampling                       : 4:2:0
    Bit depth                                : 8 bits
    Scan type                                : Progressive
    Stream size                              : 32.0 MiB (87%)
    Color primaries                          : BT.601 PAL
    Transfer characteristics                 : BT.601
    Matrix coefficients                      : BT.601
    

    So far, what I have been able to come up with is the following:

    avconv -f image2 -framerate 1.2 -i loop_%d.tif -c:v libx264 -preset veryslow -profile:v baseline -level:v 31 -b:v 1614K -refs 1 loop.flv
    

    This gets me to:

    Video
    Format                                   : AVC
    Format/Info                              : Advanced Video Codec
    Format profile                           : Baseline@L3.1
    Format settings, CABAC                   : No
    Format settings, ReFrames                : 1 frame
    Codec ID                                 : 7
    Duration                                 : 2s 917ms
    Bit rate                                 : 1 614 Kbps
    Width                                    : 1 280 pixels
    Height                                   : 720 pixels
    Display aspect ratio                     : 16:9
    Frame rate mode                          : Constant
    Frame rate                               : 1.200 fps
    Color space                              : YUV
    Chroma subsampling                       : 4:2:0
    Bit depth                                : 8 bits
    Scan type                                : Progressive
    Bits/(Pixel*Frame)                       : 1.459
    Stream size                              : 575 KiB
    Writing library                          : x264 core 142 r2431 a5831aa
    Encoding settings                        : cabac=0 / ref=1 / deblock=1:0:0 / analyse=0x1:0x131 / me=umh / subme=10 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=24 / chroma_me=1 / trellis=2 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=6 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=0 / weightp=0 / keyint=250 / keyint_min=1 / scenecut=40 / intra_refresh=0 / rc_lookahead=60 / rc=abr / mbtree=1 / bitrate=1614 / ratetol=1.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
    

    Which, unfortunately, still isn't good enough as VLC Media Player crashes hard (just closes), logging main error: Failed to compensate for the format changes, removing all filters; main error: Failed to create video converter as soon as the stream splice occurs. I tried splicing another stream in that does have the exact same encoding, and it works fine. I'm also making sure to only splice on key-frames and I am including the NALU containing the AVCDecoderConfigRecord, so I'm pretty sure I'm not doing anything else wrong, especially since a couple other programs are fine with the splice. It's just VLC that expects an even closer match.

    Here are things I've tried:

    • Adding -vsync 2 to get variable frame rate mode. Doesn't change anything.
    • Adding -color_primaries bt470bg -color_trc gamma28 -colorspace bt470bg to try to get BT.601 PAL settings (several websites mentioned this). Doesn't change anything.
    • Adding -s ntsc to set the standard to NTSC. This also changes the resolution to 720x480 (not OK), and specifying -s 1280x720 in addition gets rid of the NTSC tag again.

    If anyone knows what flags I need to supply to get closer, that would be super-helpful! The stream I'm trying to match is encoded on an Android device (it's a live-stream), so I'm assuming it is built using the standard Android MediaCoder framework, in case that helps.

  • Unable to encode H264 video using FFMPEG example

    4 mai 2020, par Basit Anwer

    FFMPEG encode example fails to create a H264 video. MPEG1 works fine though.

    Pasting the code here as well

    
         * @file
         * video encoding with libavcodec API example
         *
         * @example encode_video.c
         */
        #include 
        #include 
        #include 
        #include avcodec.h>
        #include opt.h>
        #include imgutils.h>
        static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,
                           FILE *outfile)
        {
            int ret;
            /* send the frame to the encoder */
            if (frame)
                printf("Send frame %3"PRId64"\n", frame->pts);
            ret = avcodec_send_frame(enc_ctx, frame);
            if (ret < 0) {
                fprintf(stderr, "Error sending a frame for encoding\n");
                exit(1);
            }
            while (ret >= 0) {
                ret = avcodec_receive_packet(enc_ctx, pkt);
                if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
                    return;
                else if (ret < 0) {
                    fprintf(stderr, "Error during encoding\n");
                    exit(1);
                }
                printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size);
                fwrite(pkt->data, 1, pkt->size, outfile);
                av_packet_unref(pkt);
            }
        }
    
        int main(int argc, char **argv)
        {
            const char *filename, *codec_name;
            const AVCodec *codec;
            AVCodecContext *c= NULL;
            int i, ret, x, y;
            FILE *f;
            AVFrame *frame;
            AVPacket *pkt;
            uint8_t endcode[] = { 0, 0, 1, 0xb7 };
            if (argc <= 2) {
                fprintf(stderr, "Usage: %s  \n", argv[0]);
                exit(0);
            }
            filename = argv[1];
            codec_name = argv[2];
            /* find the mpeg1video encoder */
            codec = avcodec_find_encoder_by_name(codec_name);
            if (!codec) {
                fprintf(stderr, "Codec '%s' not found\n", codec_name);
                exit(1);
            }
            c = avcodec_alloc_context3(codec);
            if (!c) {
                fprintf(stderr, "Could not allocate video codec context\n");
                exit(1);
            }
            pkt = av_packet_alloc();
            if (!pkt)
                exit(1);
            /* put sample parameters */
            c->bit_rate = 400000;
            /* resolution must be a multiple of two */
            c->width = 352;
            c->height = 288;
            /* frames per second */
            c->time_base = (AVRational){1, 25};
            c->framerate = (AVRational){25, 1};
            /* emit one intra frame every ten frames
             * check frame pict_type before passing frame
             * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I
             * then gop_size is ignored and the output of encoder
             * will always be I frame irrespective to gop_size
             */
            c->gop_size = 10;
            c->max_b_frames = 1;
            c->pix_fmt = AV_PIX_FMT_YUV420P;
            if (codec->id == AV_CODEC_ID_H264)
                av_opt_set(c->priv_data, "preset", "slow", 0);
            /* open it */
            ret = avcodec_open2(c, codec, NULL);
            if (ret < 0) {
                fprintf(stderr, "Could not open codec: %s\n", av_err2str(ret));
                exit(1);
            }
            f = fopen(filename, "wb");
            if (!f) {
                fprintf(stderr, "Could not open %s\n", filename);
                exit(1);
            }
            frame = av_frame_alloc();
            if (!frame) {
                fprintf(stderr, "Could not allocate video frame\n");
                exit(1);
            }
            frame->format = c->pix_fmt;
            frame->width  = c->width;
            frame->height = c->height;
            ret = av_frame_get_buffer(frame, 32);
            if (ret < 0) {
                fprintf(stderr, "Could not allocate the video frame data\n");
                exit(1);
            }
            /* encode 1 second of video */
            for (i = 0; i < 25; i++) {
                fflush(stdout);
                /* make sure the frame data is writable */
                ret = av_frame_make_writable(frame);
                if (ret < 0)
                    exit(1);
                /* prepare a dummy image */
                /* Y */
                for (y = 0; y < c->height; y++) {
                    for (x = 0; x < c->width; x++) {
                        frame->data[0][y * frame->linesize[0] + x] = x + y + i * 3;
                    }
                }
                /* Cb and Cr */
                for (y = 0; y < c->height/2; y++) {
                    for (x = 0; x < c->width/2; x++) {
                        frame->data[1][y * frame->linesize[1] + x] = 128 + y + i * 2;
                        frame->data[2][y * frame->linesize[2] + x] = 64 + x + i * 5;
                    }
                }
                frame->pts = i;
                /* encode the image */
                encode(c, frame, pkt, f);
            }
            /* flush the encoder */
            encode(c, NULL, pkt, f);
            /* add sequence end code to have a real MPEG file */
            if (codec->id == AV_CODEC_ID_MPEG1VIDEO || codec->id == AV_CODEC_ID_MPEG2VIDEO)
                fwrite(endcode, 1, sizeof(endcode), f);
            fclose(f);
            avcodec_free_context(&c);
            av_frame_free(&frame);
            av_packet_free(&pkt);
            return 0;
        }
    

    The code fails at encode call and every avcodec_receive_packet call returns AVERROR(EAGAIN)

    What am i missing here?

  • ffmpeg libx264 encoder different machines different output

    29 avril 2020, par yfu

    I'm new to development with ffmpeg and I was wondering if it is possible to get the same bit exact output by running ffmpeg with the libx264 encoder on different machines (compiled using different compilers) with the same input file and same configuration options?

    If it is possible, are there additional configuration options that need to be set when compiling libx264/ffmpeg? If it is not possible, why?

    Below is the output from my running two versions off ffmpeg with libx264 that yield different MD5 hashes of the outputs.

    ffmpeg installed via homebrew on OSX

    ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
      built with Apple LLVM version 9.0.0 (clang-900.0.38)
      configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --disable-lzma --enable-nonfree
    

    ffmpeg on Alpine Linux (in a Docker container based on https://github.com/jrottenberg/ffmpeg/blob/master/docker-images/3.4/alpine/Dockerfile)

    ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
      built with gcc 6.2.1 (Alpine 6.2.1) 20160822
      configuration: --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --disable-lzma --enable-nonfree --prefix=/opt/ffmpeg
    

    Test run with ffmpeg on OSX

    ffmpeg -i seg.ts -c:v libx264 -s 1280x720 -minrate 6000k -maxrate 6000k -bufsize 6000k -r 60 -threads 1 -f md5 -
    

    Output

    MD5=b7c84c0bae5da6749e389a5b69d88582

    Test run with ffmpeg on Alpine Linux (in a Docker container based on https://github.com/jrottenberg/ffmpeg/blob/master/docker-images/3.4/alpine/Dockerfile)

    docker run --rm -v /code/:/tmp/workdir -w=/tmp/workdir ffmpeg -i seg.ts -c:v libx264 -s 1280x720 -minrate 6000k -maxrate 6000k -bufsize 6000k -r 60 -threads 1 -f md5 -
    

    Output

    MD5=c46af8fbdbbb2bfbb9f7042ab28accfc