Newest 'x264' Questions - Stack Overflow

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

Les articles publiés sur le site

  • x264 : Optimal settings to have i-frames coincide with shot boundaries ?

    16 juin 2020, par kindoflike

    I would like to encode a video using x264 in such a way, that the keyframes (a.k.a. i-frames) are coinciding with shot boundaries (a.k.a. cuts).

    for testing, I used the following encoder settings (reference: http://www.chaneru.com/Roku/HLS/X264_Settings.htm):

    keyint=500:min-keyint=10:scenecut:40
    

    but from the looks of it scene changes are ignored entirely, and keyframes simply inserted every 500 frames.

    enter image description here

    scenecut:40 being the default value, is my result expected behavior? or is it an indication, that something is not quite right?

    thanks a lot in advance


    edit:

    the complete encoder settings look like this (in handbrake):

    enter image description here


    TL;DR:

    it was a typo :|

  • Compiling ijkplayer x264 for android x86 & x86_64 Architecture , error : unknown type name 'v4si'

    4 juin 2020, par Lins Louis

    I'm trying to build this project https://github.com/simplepeng/ijkplayer-x264 but building x264 failing for x86 and x86_64 architectures . Link of the issue : https://github.com/simplepeng/ijkplayer-x264/issues/1

  • ffmpeg libx264 encoder different machines different output

    29 avril 2020, par yfu

    I'm new to development with ffmpeg and I was wondering if it is possible to get the same bit exact output by running ffmpeg with the libx264 encoder on different machines (compiled using different compilers) with the same input file and same configuration options?

    If it is possible, are there additional configuration options that need to be set when compiling libx264/ffmpeg? If it is not possible, why?

    Below is the output from my running two versions off ffmpeg with libx264 that yield different MD5 hashes of the outputs.

    ffmpeg installed via homebrew on OSX

    ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
      built with Apple LLVM version 9.0.0 (clang-900.0.38)
      configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --disable-lzma --enable-nonfree
    

    ffmpeg on Alpine Linux (in a Docker container based on https://github.com/jrottenberg/ffmpeg/blob/master/docker-images/3.4/alpine/Dockerfile)

    ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
      built with gcc 6.2.1 (Alpine 6.2.1) 20160822
      configuration: --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --disable-lzma --enable-nonfree --prefix=/opt/ffmpeg
    

    Test run with ffmpeg on OSX

    ffmpeg -i seg.ts -c:v libx264 -s 1280x720 -minrate 6000k -maxrate 6000k -bufsize 6000k -r 60 -threads 1 -f md5 -
    

    Output

    MD5=b7c84c0bae5da6749e389a5b69d88582

    Test run with ffmpeg on Alpine Linux (in a Docker container based on https://github.com/jrottenberg/ffmpeg/blob/master/docker-images/3.4/alpine/Dockerfile)

    docker run --rm -v /code/:/tmp/workdir -w=/tmp/workdir ffmpeg -i seg.ts -c:v libx264 -s 1280x720 -minrate 6000k -maxrate 6000k -bufsize 6000k -r 60 -threads 1 -f md5 -
    

    Output

    MD5=c46af8fbdbbb2bfbb9f7042ab28accfc

  • When I build x264 with android-ndk it not done

    8 avril 2020, par Pradeep Simba

    When I build x264 with android-ndk it not done.

    enter image description here

    Unknown option file/x264/android/armeabi, ignored
    Unknown option --target-os=android, ignored
    Unknown option --enable-cross-compile, ignored
    Unknown option --arch=arm, ignored
    Unknown option --cpu=armv5te, ignored
    Unknown option --enable-armv5te, ignored
    Unknown option --disable-stripping, ignored
    No working C compiler found.
    Makefile:3: config.mak: No such file or directory
    ./configure
    platform:      X86_64
    byte order:    little-endian
    system:        LINUX
    cli:           yes
    libx264:       internal
    shared:        no
    static:        no
    asm:           yes
    interlaced:    yes
    avs:           avxsynth
    lavf:          no
    ffms:          no
    mp4:           no
    gpl:           yes
    thread:        posix
    opencl:        yes
    filters:       crop select_every
    lto:           no
    debug:         no
    gprof:         no
    strip:         no 
    PIC:           no
    bit depth:     all
    chroma format: all
    

    My build file

    #!/bin/bash
    
    TOOLCHAIN=/home/s/my_toolchains/arm
    CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-
    rm -f $(pwd)/compat/strtod.o
    function build_one
    {
    ./configure --prefix=$PREFIX --enable-static  --enable-pic   --target-os=android --enable-cross- compile --cross-prefix=$CROSS_PREFIX --extra-cflags="-Os -fpic $ADDI_CFLAGS" --extra-ldflags="$ADDI_LDFLAGS" --sysroot=$TOOLCHAIN/sysroot $ADDITIONAL_CONFIG_FLAG
    make clean
    make 
    make install
    }
    
    CPU=armeabi
    mkdir -p $(pwd)/android/$CPU
    PREFIX=$(pwd)/android/$CPU 
    ADDI_CFLAGS="-marm -march=armv5te -mtune=arm9tdmi -msoft-float"
    ADDI_LDFLAGS=""
    ADDITIONAL_CONFIG_FLAG="--arch=arm --cpu=armv5te --enable-armv5te --disable-asm --disable-stripping"
    build_one
    

    How can I solve this?

    why this is not done? I made the build file properly but this is not done?

    I use ubuntu os to build this file.

    It comes Unknown option --target-os=android, ignored.

  • How would I send x264 encoded frames correctly over a network using UDP ?

    5 avril 2020, par Eoin McBennett

    I'm trying to send the encoded h264 frames I have over a network as I get them, currently I'm only streaming the nal units I get from each frame as it is encoded, is this the correct approach?

    I wrote a receiver application on a different computer to get the nals and wrote them all to a file sequentially, when played with vlc I didn't get any video and instead just got a screeching noise. I'm not sure exactly where the problem would lie here. I have included the result of the FFmpeg -I command on the file created.

    Encoder and sender code

    
        //Udp initialisation
        struct sockaddr_in broadcastAddr;
        int sock;
        int yes = 1;
        int addr_len;
        int count;
        fd_set readfd;
        char buffer[1024];
        int i;
    
        sock = socket(AF_INET, SOCK_DGRAM,0);
    
        if(sock < 0){
            std::cout << "Failed to initialise socket!" << std::endl;
        }
    
        int ret = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char*)&yes, sizeof(yes));
        if(ret < 0){
            std::cout << "setsockopt error!" </ the size of the address
    
        memset((void*)&broadcastAddr,0,addr_len); //0 out the address bits
    
        broadcastAddr.sin_family = AF_INET;
        broadcastAddr.sin_addr.s_addr = INADDR_BROADCAST;
        broadcastAddr.sin_port = PORT;
    
    
    
        //Set the encoder parameters
        x264_param_t param;
        x264_param_default_preset(&param,"veryfast","zerolatency");
        param.i_threads = 1;
        param.i_width = camera.getWidth();
        param.i_height = camera.getHeight();
        param.i_fps_num = 30;
        param.i_fps_den = 1;
    // Intra refres:
        param.i_keyint_max = 30;
        param.b_intra_refresh = 1;
    //Rate control:
        param.rc.i_rc_method = X264_RC_CRF;
        param.rc.f_rf_constant = 25;
        param.rc.f_rf_constant_max = 35;
    //For streaming:
        param.b_repeat_headers = 1;
        param.b_annexb = 1;
        x264_param_apply_profile(&param, "baseline");
    
        x264_t *encoder = x264_encoder_open(&param); //H.264 encoder object
        x264_picture_t pic_in, pic_out;
        x264_picture_alloc(&pic_in, X264_CSP_I420,camera.getWidth(), camera.getHeight());
    
        //Network abstraction layer units for broadcast
        x264_nal_t *nals;
        int i_nals;
    
        while(true){
    
            //If there is valid data in the processing queue
            if(!encoderQueue.empty()){
    
                //File the x264 input data structure with the file data
                fillImage(encoderQueue.front(),camera.getWidth(),camera.getHeight(),&pic_in);
    
                //Encode and send
                int frame_size = x264_encoder_encode(encoder, &nals, &i_nals, &pic_in, &pic_out);
                if (frame_size >= 0) {
                    //The frame is ready to be sent over UDP!
                    for(int i = 0; i < i_nals; i++){
                        ret = sendto(sock, &nals[0].p_payload, frame_size,0,(struct sockaddr*)&broadcastAddr,addr_len);
                        if(ret > 0){
                            std::cout << "Streamed frame nal unit " << i  << std::endl;
                        } else{
                            std::cout << "Failed to stream nal unit " << i << std::endl;
                        }
                    }
                }
                else{
                    std::cout<<"Failed to encode h264 frame!" << std::endl;
                }
                //Finsihed with the current frame, pop it off the queue and remove any nals to do with it
                encoderQueue.pop();
                frame_size = 0;
                nals = nullptr;
                i_nals = 0;
            }
    
    
        }
    

    Receiver application

    #include 
    #include 
    #include Network.h>
    #include in.h>
    #include inet.h>
    #include types.h>
    #include socket.h>
    #include 
    
    
    #define BUFFER_LEN 10000
    #define PORT_NO 3879
    
    
    
    int main(int argc, const char * argv[]) {
    
    
        FILE *file; //File to write the h264 nals too
    
        //Declare the address memory space
        struct sockaddr_in sockAddr , bcAddr;
        socklen_t bcAddr_len = sizeof(&bcAddr); //Store the length of the broadcast address structure
        //0 out the assigned memory
        memset(&sockAddr, 0, sizeof(sockAddr));
        memset(&bcAddr, 0 ,sizeof(bcAddr));
    
        //Set the address parameters to look for incoming IpV4/UDP data
        sockAddr.sin_family = AF_INET;
        sockAddr.sin_port = htons(PORT_NO);
        sockAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    
        bcAddr.sin_family = AF_INET;
        bcAddr.sin_port = PORT_NO;
        inet_aton("255.255.255.255",&bcAddr.sin_addr);
    
        //Initialise a udp socket to read broadcast bytes
        int soc = socket(AF_INET, SOCK_DGRAM,0);
    
        //Check socket init
        if(soc < 0){
            std::cout << "Failed to initialise UDP socket!" << std::endl;
            return -1;
        }
    
        //Bind the address details to the socket, check for errors
        if(bind(soc, (struct sockaddr*)&sockAddr, sizeof(sockAddr)) < 0){
            std::cout << "Failed to bind address structure to socket!" << std::endl;
            return -2;
        }
    
        file = fopen("stream.h264","wb"); // Open the file for writing
    
        unsigned char buffer[BUFFER_LEN];
    
        while(true){
    
    
            memset(&buffer, 0, sizeof(unsigned char) * BUFFER_LEN);
    
            int recv_len = recvfrom(soc, buffer, BUFFER_LEN, 0, (struct sockaddr *)&bcAddr, &bcAddr_len);
    
            std::cout<< "Received " << recv_len << "bytes on broadcast address" << std::endl;
    
            fwrite(&buffer, sizeof(unsigned char), recv_len, file);
        }
    
        return 0;
    }
    

    FFMPEG -I output

    FFMPEG -I output

    Any help would be greatly appreciated.