Newest 'x264' Questions - Stack Overflow

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

Les articles publiés sur le site

  • How to create IDR I-slice frame for H264 bytestream ?

    19 mars, par galuk

    I depacketize the H264 video fragments from an IP.RTP stream and save them to video.ivf file. After depacketizing i have only [SPS] ,[PPS] and [non-IDR slice]. I try to create IDR slice by using x264 lib. x264 lib creates IDR frame which consists of 0x000001[SPS] 0x000001[PPS] 0x0001[SE slice] and 0x0001[I slice]. i insert it in the beginning of my file. But when i try to play this with VLC player it doesn't plays well. if i convert it to video.mp4 by ffmpeg i get playablr file. I think the problem is that after creating IDR frame with x264 lib I get SPS and PPS frames different from those that I get from the stream. My question is how to set parameters for x264 if i have real SPS and PPS frames to get the same SPS and PPS frames.

    Here is my code:

    x264_param_t param;

    `x264_param_t param`;
    `/* Get default params for preset/tuning */
    x264_param_default_preset(&param, "medium", NULL);`
    
    `/* Configure non-default params */
    param.i_csp = X264_CSP_I420;
    param.i_width = width;//640 GET FROM SPS  !!!!!!!!!! 
    param.i_height = height;//360; GET FROM SPS  !!!!!!!!!!!!!!
    param.b_vfr_input = 0; //frame rate
    param.b_repeat_headers = 1;
    param.b_annexb = 1;
    `x264_t *encoder = x264_encoder_open(&param);`
    if (encoder)
    {
            // These are the two picture structs.  Input must be alloc()
        //  Output will be created by the encode process
        x264_picture_t pic, pic_out;
        int r = x264_picture_alloc(&pic, X264_CSP_I420, width, height);
        if (r == 0)
        {
            pic.i_type = X264_TYPE_IDR;
            int y_bytes = width * height;
            int uv_bytes = width * height / 4;
            UCHAR* result = pic.img.plane[0];
            // luma
            for (unsigned int y = 0; y < height; y++)
            {
                for (unsigned int x = 0; x < width; x++)
                    pic.img.plane[0][y * width + x] = 0x16;
            }
    
            // chroma
            for (unsigned int y = 0; y < height / 2; y++)
            {
                for (unsigned int x = 0; x < width / 2; x++)
                {
                    pic.img.plane[1][y * width / 2 + x] = 0x16;
                    pic.img.plane[2][y * width / 2 + x] = 0x80;
                }
            }
            int i_frame_size = x264_encoder_encode(encoder, &nal, &i_nal, &pic, &pic_out);
        }
    }`
    

    Maybe i should set another parameters for x264_param_t param which i can get from SPS and PPS

    can someone help me with this issue

  • ffmpeg not working after update to Mavericks

    24 février, par Hudson Buddy

    After recently updating to Mavericks 10.9.5, my installation of ffmpeg has been bugging out

    Error:

    dyld: Library not loaded: /usr/local/lib/libx264.142.dylib
      Referenced from: /usr/local/bin/ffmpeg
      Reason: image not found
    Trace/BPT trap: 5
    

    Any thoughts? I'm not very familar with manual compiling and I installed ffmpeg through Homebrew.

    I tried uninstalling and doing:

    brew install ffmpeg --HEAD
    brew install ffmpeg --build-from-source
    

    but it spits back a ./configure error

    ==> ./configure --prefix=/usr/local/Cellar/ffmpeg/2.4.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample
    If you think configure made a mistake, make sure you are using the latest
    version from Git.  If the latest version fails, report the problem to the
    ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
    Include the log file "config.log" produced by configure as this will help
    solve the problem.
    
    READ THIS: https://github.com/Homebrew/homebrew/wiki/troubleshooting
    
    These open issues may also help:
    gpac 0.5.0 doesn't build against ffmpeg 2.4.1 (https://github.com/Homebrew/homebrew/issues/32978)
    
  • Error Linking FFmpeg with libx264 : Undefined Reference to __imp_x264_encoder_open_163

    23 février, par zeyu

    I'm attempting to compile FFmpeg with libx264 support on Windows using MinGW-w64, but I'm encountering a linking error when building . The error points to an undefined reference to in . Here are the details of the error message:libavcodec/avcodec-57.dll__imp_x264_encoder_open_163libx264.o

    In fact, I want to run the AccMPEG branch from https://github.com/Alex-q-z/myh264.git, and I am looking to obtain an executable (exe) to run on Windows.

    LD      libavcodec/avcodec-57.dll
    E:/MSY/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libavcodec/libx264.o: in function `X264_init':
    E:\MSY\home\myh264\ffmpeg-3.4.8/libavcodec/libx264.c:818: undefined reference to `__imp_x264_encoder_open_163'
    collect2.exe: error: ld returned 1 exit status
    make: *** [ffbuild/library.mak:103: libavcodec/avcodec-57.dll] Error 1
    
    

    Here's what I've tried so far:

    Ensuring libx264 is compiled with shared library support using .--enable-shared Verifying that the libx264 version is compatible with the version of FFmpeg I'm compiling. Adding the path to libx264 binaries to my PATH environment variable. Environment Details:

    OS: Windows 11 MSYS2 MinGW-w64 version: 13.2.0 FFmpeg version: 3.4.8 libx264 version: unknown Questions:

    What could be causing this undefined reference error? Is there a specific version of libx264 that's known to work with FFmpeg 3.4.8? Are there additional flags or configurations I should use when compiling libx264 or FFmpeg to avoid this issue? Any guidance or suggestions would be greatly appreciated. Thank you in advance!

    In fact, I want to run the AccMPEG branch from https://github.com/Alex-q-z/myh264.git, and I am looking to obtain an executable (exe) to run on Windows.

  • Why is a file unplayable in Windows Media Player ?

    21 février, par zhang

    I have written some code to generate a MP4 video. This is a simplified version of the code:

    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    extern "C"
    {
    #include "libavformat/avformat.h"
    #include "libavutil/frame.h"
    #include "libavcodec/avcodec.h"
    #include "libavutil/imgutils.h"
    }
    using namespace std;
    
    const int output_width = 180;
    const int output_height = 320;
    
    int main(int argc, char **argv)
    {
        AVCodec *output_avc = avcodec_find_encoder_by_name("libx264");
        if (!output_avc)
            abort();
        AVCodecContext *output_cc = avcodec_alloc_context3(output_avc);
        if (!output_cc)
            abort();
    
        output_cc->time_base.num = output_cc->time_base.den = 1;
        output_cc->pix_fmt = AV_PIX_FMT_YUV420P;
    
        output_cc->width = output_width;
        output_cc->height = output_height;
    
        if (avcodec_is_open(output_cc) == 0)
        {
            if (avcodec_open2(output_cc, output_avc, 0) < 0)
                abort();
        }
    
        string outf = "res.mp4";
        AVFormatContext *output_ctx;
        avformat_alloc_output_context2(&output_ctx, NULL, NULL, outf.c_str());
        AVStream *out_stream = avformat_new_stream(output_ctx, 0);
        out_stream->codecpar->codec_id = AV_CODEC_ID_H264;
        out_stream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
        out_stream->codecpar->codec_tag = 0;
        out_stream->codecpar->width = output_width;
        out_stream->codecpar->height = output_height;
        out_stream->codecpar->format = AV_PIX_FMT_YUV420P;
        av_dump_format(output_ctx, 0, outf.c_str(), 1);
        if (!(output_ctx->oformat->flags & AVFMT_NOFILE))
        {
            if (avio_open(&output_ctx->pb, outf.c_str(), AVIO_FLAG_WRITE) < 0)
                abort();
        }
        if (avformat_write_header(output_ctx, NULL) < 0)
            abort();
    
        AVPacket packet;
        AVFrame *frame;
        int fileCount = 0;
    
        for (int i = 0; i < 100; i++)
        {
            frame = av_frame_alloc();
            frame->width = output_width;
            frame->height = output_height;
            frame->format = AV_PIX_FMT_YUV420P;
            if (av_image_alloc(frame->data, frame->linesize, frame->width, frame->height, AV_PIX_FMT_YUV420P, 32) < 0)
                abort();
            frame->pts = 60000 * i;
            frame->pkt_dts = 60000 * i;
            if (avcodec_send_frame(output_cc, frame) < 0)
                abort();
            av_frame_free(&frame);
    
            av_new_packet(&packet, 0);
            while (avcodec_receive_packet(output_cc, &packet) >= 0)
            {
                packet.pos = -1;
                packet.dts = 4500 * fileCount;
                packet.pts = 4500 * fileCount;
                packet.duration = 4500;
                av_write_frame(output_ctx, &packet);
                av_packet_unref(&packet);
                av_new_packet(&packet, 0);
                fileCount++;
            }
            av_packet_unref(&packet);
        }
        avcodec_free_context(&output_cc);
    
        av_write_trailer(output_ctx);
        if (output_ctx && !(output_ctx->oformat->flags & AVFMT_NOFILE))
            avio_close(output_ctx->pb);
        avformat_free_context(output_ctx);
    }
    

    Then, I compiled it (with g++ encode.cpp -lavcodec -lavformat -lavutil -g and libraries are installed via Ubuntu 20.04 apt) and run it. This is the MP4 file I get (2872 bytes, base64 encoded):

    AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAAB39tZGF0AAAAAWdkAAys
    2UMCnn4QAAADABAAAAMAIPFCmWAAAAABaOvjyy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AAAAABAAAAAAAAAAAAAAAAAAAAAAC0AUAASAAAAEgAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAABj//wAAAAhhdmNDAAAAGHN0dHMAAAAAAAAAAQAAAC4AABGUAAAAFHN0
    c3MAAAAAAAAAAQAAAAEAAAAcc3RzYwAAAAAAAAABAAAAAQAAAC4AAAABAAAAzHN0c3oAAAAAAAAA
    AAAAAC4AAAMzAAAAFAAAABIAAAARAAAADgAAABcAAAARAAAADgAAAA4AAAAsAAAAHgAAABIAAAAS
    AAAASwAAAB0AAAATAAAAEwAAACAAAAAPAAAAEwAAABMAAAAeAAAAHQAAABMAAAATAAAALQAAAA8A
    AAATAAAAFAAAACcAAAAdAAAAFAAAABMAAAAfAAAADwAAABMAAAAUAAAAHwAAAB0AAAAUAAAAEwAA
    AB8AAAAPAAAAEwAAABQAAAAuAAAAFHN0Y28AAAAAAAAAAQAAADAAAABidWR0YQAAAFptZXRhAAAA
    AAAAACFoZGxyAAAAAAAAAABtZGlyYXBwbAAAAAAAAAAAAAAAAC1pbHN0AAAAJal0b28AAAAdZGF0
    YQAAAAEAAAAATGF2ZjU4LjI5LjEwMA==
    

    And I try to play it in Media Player in Windows 11. It can not play at all and fails with a 0xC00D36C4 error.

    Later I compiled and run the same code in Ubuntu 22.04. This time I got a 3161 byte file (base64 encoded) which can be correctly played in Media Player:

    AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAACF5tZGF0AAAAGWdkAAys
    2UMCnn4QAAADABAAAAMAIPFCmWAAAAAGaOvjyyLAAAACrgYF//+q3EXpvebZSLeWLNgg2SPu73gy
    NjQgLSBjb3JlIDE2MyByMzA2MCA1ZGI2YWE2IC0gSC4yNjQvTVBFRy00IEFWQyBjb2RlYyAtIENv
    cHlsZWZ0IDIwMDMtMjAyMSAtIGh0dHA6Ly93d3cudmlkZW9sYW4ub3JnL3gyNjQuaHRtbCAtIG9w
    dG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bmYAAAAcZHJlZgAA
    AAAAAAABAAAADHVybCAAAAABAAAB4HN0YmwAAACwc3RzZAAAAAAAAAABAAAAoGF2YzEAAAAAAAAA
    AQAAAAAAAAAAAAAAAAAAAAAAtAFAAEgAAABIAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAY//8AAAA2YXZjQwFkAAz/4QAZZ2QADKzZQwKefhAAAAMAEAAAAwAg8UKZYAEA
    Bmjr48siwP34+AAAAAAUYnRydAAAAAAAABz+AAAc/gAAABhzdHRzAAAAAAAAAAEAAAAuAAARlAAA
    ABRzdHNzAAAAAAAAAAEAAAABAAAAHHN0c2MAAAAAAAAAAQAAAAEAAAAuAAAAAQAAAMxzdHN6AAAA
    AAAAAAAAAAAuAAADNwAAAEcAAAAPAAAADwAAAA0AAACoAAAAEQAAAA0AAAAPAAAASQAAAA4AAAAP
    AAAADwAAACcAAAAqAAAADwAAAA0AAAAmAAAADgAAAA8AAAAPAAAAKQAAABsAAAANAAAADwAAACoA
    AAAbAAAADwAAAA0AAAAqAAAADgAAAA8AAAAPAAAAJwAAABoAAAANAAAADwAAACkAAAAaAAAADwAA
    AA0AAABLAAAAGQAAACYAAAAPAAAAOAAAABRzdGNvAAAAAAAAAAEAAAAwAAAAYnVkdGEAAABabWV0
    YQAAAAAAAAAhaGRscgAAAAAAAAAAbWRpcmFwcGwAAAAAAAAAAAAAAAAtaWxzdAAAACWpdG9vAAAA
    HWRhdGEAAAABAAAAAExhdmY1OC43Ni4xMDA=
    
  • h264 ffmpeg : How to initialize ffmpeg to decode NALs created with x264

    19 février, par Raul Calvo

    I encoded some frames using x264, using x264_encoder_encode() and after that I created AVPackets using a function like this:

    bool PacketizeNals( uint8_t* a_pNalBuffer, int a_nNalBufferSize, AVPacket* a_pPacket )
    {
        if ( !a_pPacket )
    return false;
        a_pPacket->data = a_pNalBuffer;
        a_pPacket->size = a_nNalBufferSize;
        a_pPacket->stream_index = 0;
        a_pPacket->flags = AV_PKT_FLAG_KEY;
    
        a_pPacket->pts = int64_t(0x8000000000000000);
        a_pPacket->dts = int64_t(0x8000000000000000);
    }
    

    I call this function like this:

    x264_nal_t* nals;
    int num_nals = encode_frame(pic, &nals);
    for (int i = 0; i < num_nals; i++)
    {
        AVPacket* pPacket = ( AVPacket* )av_malloc( sizeof( AVPacket ) );
        av_init_packet( pPacket );
        if ( PacketizeNals( nals[i].p_payload, nals[i].i_payload, pPacket ) )
        {
            packets.push_back( pPacket );
        }
    }
    

    Now what I want to do is to decode these AVPackets using avcodec_decode_video2. I think the problem is that I haven't properly initialized the decoder because to encode I used "ultrafast" profile and "zerolatency" tune (x264) and to decode I don't know how to specify these options to ffmpeg.

    In some examples I have read people initialize the decoder using the file where the video is stored, but in this case I have the AVPackets directly.

    What I'm doing to try to decode is:

    avcodec_init();  
    avcodec_register_all();  
    AVCodec* pCodec;  
    pCodec=avcodec_find_decoder(CODEC_ID_H264);  
    AVCodecContext* pCodecContext;  
    pCodecContext=avcodec_alloc_context();  
    avcodec_open(pCodecContext,pCodec);  
    pCodecContext->width = 320;
    pCodecContext->height = 200;
    pCodecContext->extradata = NULL;
    unsigned int nNumPackets = packets.size();
    int frameFinished = 0;
    for ( auto it = packets.begin(); it != packets.end(); it++ )
    {
        AVFrame* pFrame;
        pFrame = avcodec_alloc_frame();
        AVPacket* pPacket = *it;
        int iReturn = avcodec_decode_video2( pCodecContext, pFrame, &frameFinished, pPacket );
    }
    

    But iReturn is always -1.

    Can anyone help me? Sorry if my knowledge in this area is low, I'm new.