Newest 'x264' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Compiling x264 with ffms2 support under linux

    6 mai 2021, par El_Dorado

    I wonder how to compile x264 with ffms2 support under linux, specifically on CentOS 8. I'm able sucessfully compile ffmpeg with all available libraries under usual compilation (including x264), and even ffms2, but i want to compile x264 with ffms2 support.

    I know i can get it from rpmfusion, but actually after installing this package, CentOS wont boot. Also i need to compile it by myself for toilering to specific needs.

    I also know that i've to recompile x264 because ffmpeg needs x264, ffms2 needs ffmpeg, and so on.

    Thank You.

  • How to encode a video from several images generated in a C++ program without writing the separate frame images to disk ?

    5 mai 2021, par ksb496

    I am writing a C++ code where a sequence of N different frames is generated after performing some operations implemented therein. After each frame is completed, I write it on the disk as IMG_%d.png, and finally I encode them to a video through ffmpeg using the x264 codec.

    The summarized pseudocode of the main part of the program is the following one:

    std::vector B(width*height*3);
    for (i=0; i/ void generateframe(std::vector &, int)
      generateframe(B, i); // Returns different images for different i values.
      sprintf(s, "IMG_%d.png", i+1);
      WriteToDisk(B, s); // void WriteToDisk(std::vector, char[])
    }
    

    The problem of this implementation is that the number of desired frames, N, is usually high (N~100000) as well as the resolution of the pictures (1920x1080), resulting into an overload of the disk, producing write cycles of dozens of GB after each execution.

    In order to avoid this, I have been trying to find documentation about parsing directly each image stored in the vector B to an encoder such as x264 (without having to write the intermediate image files to the disk). Albeit some interesting topics were found, none of them solved specifically what I exactly want to, as many of them concern the execution of the encoder with existing images files on the disk, whilst others provide solutions for other programming languages such as Python (here you can find a fully satisfactory solution for that platform).

    The pseudocode of what I would like to obtain is something similar to this:

    std::vector B(width*height*3);
    video_file=open_video("Generated_Video.mp4", ...[encoder options]...);
    for (i=0; icode>

    According to what I have read on related topics, the x264 C++ API might be able to do this, but, as stated above, I did not find a satisfactory answer for my specific question. I tried learning and using directly the ffmpeg source code, but both its low ease of use and compilation issues forced me to discard this possibility as a mere non-professional programmer I am (I take it as just as a hobby and unluckily I cannot waste that many time learning something so demanding).

    Another possible solution that came to my mind is to find a way to call the ffmpeg binary file in the C++ code, and somehow manage to transfer the image data of each iteration (stored in B) to the encoder, letting the addition of each frame (that is, not "closing" the video file to write) until the last frame, so that more frames can be added until reaching the N-th one, where the video file will be "closed". In other words, call ffmpeg.exe through the C++ program to write the first frame to a video, but make the encoder "wait" for more frames. Then call again ffmpeg to add the second frame and make the encoder "wait" again for more frames, and so on until reaching the last frame, where the video will be finished. However, I do not know how to proceed or if it is actually possible.

    Edit 1:

    As suggested in the replies, I have been documenting about named pipes and tried to use them in my code. First of all, it should be remarked that I am working with Cygwin, so my named pipes are created as they would be created under Linux. The modified pseudocode I used (including the corresponding system libraries) is the following one:

    FILE *fd;
    mkfifo("myfifo", 0666);
    
    for (i=0; i/ void WriteToPipe(std::vector, FILE *&fd)
      fflush(fd);
      fd=fclose("myfifo");
    }
    unlink("myfifo");
    

    WriteToPipe is a slight modification of the previous WriteToFile function, where I made sure that the write buffer to send the image data is small enough to fit the pipe buffering limitations.

    Then I compile and write the following command in the Cygwin terminal:

    ./myprogram | ffmpeg -i pipe:myfifo -c:v libx264 -preset slow -crf 20 Video.mp4
    

    However, it remains stuck at the loop when i=0 at the "fopen" line (that is, the first fopen call). If I had not called ffmpeg it would be natural as the server (my program) would be waiting for a client program to connect to the "other side" of the pipe, but it is not the case. It looks like they cannot be connected through the pipe somehow, but I have not been able to find further documentation in order to overcome this issue. Any suggestion?

  • while configuring ffmpeg i get the error "x264 not found"

    27 avril 2021, par Shevach Riabtsev

    i use mingw32 to compile ffmpeg with libx264. i use the following configuration:

    ./configure --enable-gpl --enable-nonfree --enable-libx264

    and get the error

    ERROR: x264 not found

    i compiled x264 and x264 library (libx264.a) is located at /usr/lib/

    How to resolve this issue?

  • Why after rendering with ffmpeg, file size did not decrease ?

    15 avril 2021, par ptrra

    PROBLEM: After rendering a certain video with ffmpeg file size increased from 4GB to 6GB.
    ORIGINAL VIDEO: EE1.mkv
    FFMPEG COMMAND: ffmpeg -i EE1.mkv -c:a copy -c:v libx264 -crf 23 -preset medium -profile:v high out.mp4
    QUESTIONS: Why did the file size increase? What am I doing wrong?

    !DETAILS!
    After a few years I made about 30 gaming videos (130GB) and with the current covid-19 situation I started recording my online classes (about 40 videos or 150GB). Now because I'm lacking space on my 1TB external HDD I started getting into ffmpeg. Before I was only using obs-studio and not good parameters for recording.

    I was using CBR mode for recording, either 5000KB or 15000KB bit rate with varying x264 presets and profiles because I was also experimenting with them. Usually superfast preset with high profile. So I wanted to convert all those videos with ffmpeg using CRF 23, medium preset and high profile. A note that when I'm recording with obs-studio it's set to record in matroska format (.mkv).

    When I was rendering my online classes videos with these settings I managed to achieve 10x better compression with the same quality. And when rendering my gaming videos I managed to achieve up to 3x better compression with the same quality. However there is this one video that when rendered with the same parameters the file size increases.

    The EE1.mkv should be recorded with CBR 15000KB bit rate, with superfast preset and high profile. Also the game that is recorded in this video is Empire Earth which needs around 8000KB for it to look good. Everything more than 8000KB is not needed.

    Thank you all for your help.

  • How to get x264.pc windows ?

    30 mars 2021, par NO_GUI

    I am trying to build the pion mediadevices webrtc example utilizing x264 as my video encoder. I am building on a Windows 10 PC. The pion/mediadevices library utilizes pkg-config to locate x264 to build the program. I keep getting this error when building though:

    # pkg-config --cflags  -- x264
    Package x264 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `x264.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'x264' found
    pkg-config: exit status 1
    

    I downloaded the source code for x264, but there is no x264.pc included. And from my research, it appears x264.pc is only included with libx264. I can't find any way to get libx264 on Windows either. Lastly, what is x264.pc, and what is a .pc file? Thanks for the help!

    Edit: I think I have to build the x264 library first, and I almost got it to work. MinGW was able to compile x264 and give me the x264.pc. But it was all compiled in 32bit, how can I compile the x264 library for 64bit on windows?