Newest 'libx264' Questions - Stack Overflow

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

Les articles publiés sur le site

  • very low latency streaminig with ffmpeg using a webcam

    5 avril, par userDtrm

    I'm trying to configure ffmpeg to do a real-time video streaming using a webcam. The ffmpeg encoder command I use is as follows.

    ffmpeg -f v4l2 -input_format yuyv422 -s 640x480 -i /dev/video0 -c:v libx264 -profile:v baseline -trellis 0 -subq 1 -level 32 -preset superfast -tune zerolatency -me_method epzs -crf 30 -threads 0 -bufsize 1 -refs 4 -coder 0 -b_strategy 0 -bf 0 -sc_threshold 0 -x264-params vbv-maxrate=2000:slice-max-size=1500:keyint=30:min-keyint=10: -pix_fmt yuv420p -an -f mpegts udp://192.168.1.8:5001
    

    The ffplay command used to display the video feed is,

    ffplay -analyzeduration 1 -fflags -nobuffer -i udp://192.168.1.8:5001
    

    However, I'm experiencing a latency of 0.5 - 1.0s latency in the video stream. Is there a way to reduce this to a number less than 100ms. Also, when I replace the v4l2 camera capture with a screen capture using x11grab, the stream is almost real-time and I experience no noticeable delays. Moreover, changing the encoder from x264 to mpeg2 had no effect on the latency. In addition, the statistics from the ffmpeg shows that the encoder is performing at a 30fps rate, which I believe indicates that the encoding is real-time. This leaves me with only one reason for the experienced delay.

    • Is there a significant delay in buffers when using v4l2 during video capturing in a webcam?
    • I don't think the transmission delay is in effect in this case as I see no latencies when screen capture is used under the same conditions.
    • Can this latency be further reduced?. Can someone think of a different encoder configuration to be used instead of the one that I've been using?
  • 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.