Newest 'libx264' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Encoding problem with x264 and not divisible by 4 resolutions

    23 février, par Valentin Maschenko

    I'm encoding frames using H264 from BRGA to Yuv420p with high preset. It works fine with most resolutions, but images on 1366x768 are heavily distorted. So far, I've found that if width or height is not divisible by 4, there can be issues like this. Do you know how I can fix that?

    Distorted image

    Code:

    stride = this.width * 4;
    
    encoder = new CodecContext(Codec.FindEncoderById(AVCodecID.H264))
    {
        Width = this.width,
        Height = this.height,
        Framerate = new AVRational(1, framerate),
        TimeBase = new AVRational(1, framerate),
        PixelFormat = AVPixelFormat.Yuv420p,
        Profile = (int)FF_PROFILE.H264High,
        MaxBFrames = 0,
        GopSize = 10,
    };
    
    encoder.Open(null, new MediaDictionary
    {
        ["crf"] = "22",
        ["tune"] = "zerolatency",
        ["preset"] = "veryfast",
        ["subme"] = "5"
    });
    
    rgbFrame.Width = width;
    rgbFrame.Height = height;
    rgbFrame.Format = (int)AVPixelFormat.Bgra;
    unsafe
    {
        fixed (byte* ptr = frame)
        {
            rgbFrame.Data[0] = (nint)ptr;
        }
    }
    rgbFrame.Linesize[0] = stride;
    rgbFrame.Pts = pts++;
    
    yuvFrame.Width = width;
    yuvFrame.Height = height;
    yuvFrame.Format = (int)AVPixelFormat.Yuv420p;
    
    yuvFrame.EnsureBuffer();
    yuvFrame.MakeWritable();
    videoFrameConverter.ConvertFrame(rgbFrame, yuvFrame);
    yuvFrame.Pts = pts;
    
    var encodedFrames = encoder.EncodeFrame(yuvFrame, packetRef);
    var packet = encodedFrames.FirstOrDefault();
    var data = packet?.Data.ToArray() ?? [];
    
  • Per macroblock encoding in libx264

    12 janvier, par Wei.M

    I know that in x264 encoding, the process is going on with the unit of macroblock. However, is that possible to set the parameters for each macroblocks? For example, if I want to let the QP of some specific area to be smaller than others. Is that possible? If I need to modify the functions and Apis in libx264, where should I begin?

  • libx264 : which parameters can be changed on fly ?

    12 janvier, par Dan Tumaykin

    I know that it is possible to change some encoder parameters on fly, using x264_encoder_reconfig(). From this commit I can deduce that we can change ratecontrol parameters - but I was unable to find a clear list of parameters that may be changed.

    Question: which parameters of x264 encoder can be changed on fly?

  • encode x264(libx264) raw yuv frame data

    12 janvier, par Mohamed El-Sayed

    I am trying to encode an MP4 video using raw YUV frames data, but I am not sure how can I fill the plane data (preferably without using other libraries like ffmpeg)

    The frame data is already encoded in I420, and does not need conversion.

    Here is what I am trying to do:

    const char *frameData = /* Raw frame data */;
    
    x264_t *encoder = x264_encoder_open(&param);
    x264_picture_t imgInput, imgOutput;
    x264_picture_alloc(&imgInput, X264_CSP_I420, width, height);
    
    // how can I fill the struct data of imgInput
    
    x264_nal_t *nals;
    int i_nals;
    int frameSize = x264_encoder_encode(encoder, &nals, &i_nals, &imgInput, &imgOutput);
    

    The equivalent command line that I have found is :

     x264 --output video.mp4 --fps 15 --input-res 1280x800 imgdata_01.raw 
    

    But I could not figure out how the app does it.

    Thanks.

  • Create a deep copy of internal x264 encoder's state

    9 janvier, par Ragdoll Car

    I am using x264 library: https://github.com/mirror/x264

    We can create a new encoder handler this way:

    x264_param_t param{};  // fill with proper values
    x264_t* handler = x264_encoder_open(&param);
    

    But how can we create a deep copy of handler so we can have two the same encoders with exactly the same internal state?