Newest 'libx264' Questions - Stack Overflow

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

Les articles publiés sur le site

  • 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.

  • how to use x264 dll in another project

    7 février, par Hadi Rasekh

    I want to use x264 in my project. There is some line in the code said:

    `/* Application developers planning to link against a shared library version of

    • libx264 from a Microsoft Visual Studio or similar development environment
    • will need to define X264_API_IMPORTS before including this header.
    • This clause does not apply to MinGW, similar development environments, or non
    • Windows platforms. */`

    But I don't get this line: define X264_API_IMPORTS before including this header

    We can create x264 dll by its configuration and make

        ./configure --enable-shared
        make
    

    but I can not use the dll in my Qt Project.

    I can make my own dll (in another code) and use it in the project. But when I start to use x264 dll in my project I get the following error:

        C:\DataHiding\SourceCode2\GUI\DataHiding\mainwindow.cpp:10: error:
        'pulldown_frame_duration' was not declared in this scope
        qDebug() << pulldown_frame_duration[1];
                 ^
    
  • GStreamer x264enc Buffered Frames are Sped-Up after EOS Event

    31 janvier, par user21956843

    After sending EOS, the encoder sends its buffered frames down the pipeline, but the playback of those last ~2s of footage is sped up.

    Pipeline:

    autovideosrc [avfvideosrc] ! clockoverlay ! videoconvert ! video/x-raw,format=I420 !
    x264enc bframes=0 bitrate=512 ! video/x-264,stream-format=avc,alignment=au,framerate=20/1 ! kvssink
    

    The application plays the pipeline for 10s, then sends an EOS event on the source element. The custom sink kvssink streams frames to cloud storage, the playback of this 10s of footage is fine except for the encoder's ~2s of buffered frames that were sent out after the EOS event being sped up. How can I correct this?

  • How to write a video file using FFmpeg

    15 janvier, par Summit

    I am trying to write a video file using FFMPEG but i get the following errors

    [libx264 @ 000002bdf90c3c00] broken ffmpeg default settings detected
    [libx264 @ 000002bdf90c3c00] use an encoding preset (e.g. -vpre medium)
    [libx264 @ 000002bdf90c3c00] preset usage: -vpre  -vpre 
    [libx264 @ 000002bdf90c3c00] speed presets are listed in x264 --help
    [libx264 @ 000002bdf90c3c00] profile is optional; x264 defaults to high
    

    This is my code

    #pragma warning(disable : 4996)
    
    extern "C" {
    #include avformat.h>
    #include opt.h>
    #include mathematics.h>
    #include swscale.h>
    }
    
    int main() {
        av_register_all();
        AVFormatContext* formatContext = nullptr;
        AVOutputFormat* outputFormat = nullptr;
        AVStream* videoStream = nullptr;
    
        const char* filename = "output.mp4";
    
        // Open the output file
        if (avformat_alloc_output_context2(&formatContext, nullptr, nullptr, filename) < 0) {
            fprintf(stderr, "Error allocating output format context\n");
            return -1;
        }
    
        outputFormat = formatContext->oformat;
    
        // Add a video stream
        videoStream = avformat_new_stream(formatContext, nullptr);
        if (!videoStream) {
            fprintf(stderr, "Error creating video stream\n");
            return -1;
        }
    
        // Set codec parameters, you may need to adjust these based on your needs
        AVCodecContext* codecContext = avcodec_alloc_context3(nullptr);
        codecContext->codec_id = outputFormat->video_codec;
        codecContext->codec_type = AVMEDIA_TYPE_VIDEO;
        codecContext->pix_fmt = AV_PIX_FMT_YUV420P;
        codecContext->width = 640;
        codecContext->height = 480;
        codecContext->time_base = { 1, 25 };
    
        // Open the video codec
        AVCodec* videoCodec = avcodec_find_encoder(codecContext->codec_id);
        if (!videoCodec) {
            fprintf(stderr, "Error finding video codec\n");
            return -1;
        }
    
        if (avcodec_open2(codecContext, videoCodec, nullptr) < 0) {
            fprintf(stderr, "Error opening video codec\n");
            return -1;
        }
    
        videoStream->codecpar->codec_id = codecContext->codec_id;
        videoStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
        videoStream->codecpar->format = codecContext->pix_fmt;
        videoStream->codecpar->width = codecContext->width;
        videoStream->codecpar->height = codecContext->height;
    
        if (avformat_write_header(formatContext, nullptr) < 0) {
            fprintf(stderr, "Error writing header\n");
            return -1;
        }
    
        // Create a frame
        AVFrame* frame = av_frame_alloc();
        frame->format = codecContext->pix_fmt;
        frame->width = codecContext->width;
        frame->height = codecContext->height;
        av_frame_get_buffer(frame, 32);
    
        // Fill the frame with red color
        for (int y = 0; y < codecContext->height; ++y) {
            for (int x = 0; x < codecContext->width; ++x) {
                frame->data[0][y * frame->linesize[0] + x * 3] = 255;     // Red component
                frame->data[0][y * frame->linesize[0] + x * 3 + 1] = 0;   // Green component
                frame->data[0][y * frame->linesize[0] + x * 3 + 2] = 0;   // Blue component
            }
        }
    
        // Write video frames
        AVPacket packet;
        for (int i = 0; i < 100; ++i) {
            // Send the frame for encoding
            if (avcodec_send_frame(codecContext, frame) < 0) {
                fprintf(stderr, "Error sending a frame for encoding\n");
                return -1;
            }
    
            // Receive the encoded packet
            while (avcodec_receive_packet(codecContext, &packet) == 0) {
                // Write the packet to the output file
                if (av_write_frame(formatContext, &packet) != 0) {
                    fprintf(stderr, "Error writing video frame\n");
                    return -1;
                }
                av_packet_unref(&packet);
            }
        }
    
        // Write the trailer
        if (av_write_trailer(formatContext) != 0) {
            fprintf(stderr, "Error writing trailer\n");
            return -1;
        }
    
        // Clean up resources
        av_frame_free(&frame);
        avcodec_free_context(&codecContext);
        avformat_free_context(formatContext);
    
        return 0;
    }
    
  • FFMPEG, want to encode 720x480 and automatically scale to 640x480 or 854x480 as necessary depending on the ratio

    2 décembre 2023, par boxylogan

    EDIT: See appended notes at the bottom of the post.

    Note: all MKVs are sourced from my original Farscape Starburst DVDs, MPEG2. I've been slowly re-encoding my old TV shows into a crisper format and I have for some shows, mainly extras (but also full episodes) MKVs that are a mix of 4:3 and 16:9. Usually I open the files up in Mediainfo and find out which ones are 4:3, stick them in one folder to encode in 640x480, then the same with 16:9. It's worked fine for the umpteen amount of times I've had to encode my shows. I would like to try to expedite the process with a single FFMPEG command that can automatically detect if the files are 4:3 or 16:9 and encode them properly to 640x480 or 854x480.

    My main FFMPEG commands have been these two, depending on which aspect ratio I'm using:

    854x480p

    `for i in *.mkv; do ffmpeg -i "$i" -c:v libx264 -profile:v main -level:v 4.0 -crf 20 -c:a copy -map 0 -vf scale=854:480,setdar=16/9 encoded/"${i%.mkv}.mkv"; done
    

    640x480p

    `for i in *.mkv; do ffmpeg -i "$i" -c:v libx264 -profile:v main -level:v 4.0 -crf 20 -c:a copy -map 0 -vf scale=640:480,setdar=4/3 encoded/"${i%.mkv}.mkv"; done
    

    These two have worked fine lately since I got away from the extraneous -x264-params nonsense I picked up years ago. Again, I'm trying to streamline. I found this command a day ago and it SEEMED to look PERFECT:

    `for i in *.mkv; do ffmpeg -i "$i" -c:v libx264 -profile:v main -level:v 4.0 -crf 20 -c:a copy -map 0 -vf scale=w='if(gt(dar,854/480),min(854,iw*sar),2*trunc(iw*sar*oh/ih/2))':h='if(gt(dar,854/480),2*trunc(ih*ow/iw/sar/2),min(480,ih))' encoded/"${i%.mkv}.mkv"; done
    

    Looks perfect and works great for 640x480. The only problem is that it returns 852x480, every time. I even tried a modification I found where you set the setsar=1 AFTER the scale filter, and it does nothing.

    These are the first warnings I get when I try to run the command, with a 16:9 video, but it still completes:

    `[Parsed_scale_0 @ 0x56299c22fcc0] Circular references detected for width 'if(gt(dar, 854/480), min(854,iw*sar), 2*trunc(iw*sar*oh/ih/2))' and height 'if(gt(dar, 854/480), 2*trunc(ih*ow/iw/sar/2), min(480,ih))' - possibly invalid.
    Stream mapping:
      Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (libx264))
      Stream #0:1 -> #0:1 (copy)
    Press [q] to stop, [?] for help
    [Parsed_scale_0 @ 0x56299c20e5c0] Circular references detected for width 'if(gt(dar, 854/480), min(854,iw*sar), 2*trunc(iw*sar*oh/ih/2))' and height 'if(gt(dar, 854/480), 2*trunc(ih*ow/iw/sar/2), min(480,ih))' - possibly invalid.
    

    It encodes and I can see the resolution it outputs to:

    `Stream #0:0(eng): Video: h264 (H264 / 0x34363248), yuv420p(tv, top coded first (swapped)), 852x480 [SAR 1:1 DAR 71:40], q=2-31, 29.97 fps, 1k tbn
    

    The next video is a 4:3 video and gives these warnings, however the video still completes, this time the video encodes properly to 640x480:your text

    `[Parsed_scale_0 @ 0x5623084d4140] Circular references detected for width 'if(gt(dar, 854/480), min(854,iw*sar), 2*trunc(iw*sar*oh/ih/2))' and height 'if(gt(dar, 854/480), 2*trunc(ih*ow/iw/sar/2), min(480,ih))' - possibly invalid.
    Stream mapping:
      Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (libx264))
      Stream #0:1 -> #0:1 (copy)`your text`
    Press [q] to stop, [?] for help
    [Parsed_scale_0 @ 0x5623084d7080] Circular references detected for width 'if(gt(dar, 854/480), min(854,iw*sar), 2*trunc(iw*sar*oh/ih/2))' and height 'if(gt(dar, 854/480), 2*trunc(ih*ow/iw/sar/2), min(480,ih))' - possibly invalid.
    

    The output details:

    `Stream #0:0(eng): Video: h264 (H264 / 0x34363248), yuv420p(tv, top coded first (swapped)), 640x48 [SAR 1:1 `your text`DAR 4:3], q=2-31, 29.97 fps, 1k tbn
    

    TL;DR

    EDIT: The actual problem is that the command is encoding the 16:9 aspect ratio files to 852x480 instead of 854x480. 854x480 is actually what I would like. 640x480 for the 4:3 is fine. Apologies, for the lack of clarification.

    Videos encode (from original Farscape Starburst DVDs MPEG2) properly to libx264 640x480 for 4:3 but not to 854x480 for 16:9. 16:9 instead encodes to 852x480, despite what command is telling it to do.

    Advice? Thanks in advance! Anything to make my re-encoding a little bit less tedious. I've been googling for hours and searching, but nothing seems to make it click. Thank you again!