Newest 'libx264' Questions - Stack Overflow

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

Les articles publiés sur le site

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

  • is it possible to compile x264 for webassembly using emscripten ?

    4 novembre 2024, par sunder kandasamy

    I am trying to build x264 code for webassembly. i use emconfigure to configure. like below

    emconfigure ./configure --prefix="$(pwd)/em" --enable-shared --enable-static  --disable-cli  --disable-gpl
    

    But this was throwing "No working C compiler found." error. i have gcc compiler 9.3.0 version and have tried reinstalling build-essentials and gcc but still same issue.

    config.log also doesn't help.

    If i provide --host cross compiler flag then it is generating libx264.so file, but i am not sure whether this is right as the wasm code should work in every browser in (windows/mac/linux)

    please tell me first whether compiling x264 using emscripten is possible? If yes, please tell me what is the correct steps to do it

  • How to set correct parameters for x264 lib

    29 octobre 2024, par galuk

    I depacketize the H264 video fragments from an IP.RTP stream and save them to video.ivf file. After depacketizing i have only [SPS] ,[PPS] and [non-IDR slice]. I try to create IDR slice by using x264 lib. x264 lib creates IDR frame which consists of 0x000001[SPS nal type 7] 0x000001[PPS nal type 8] 0x0001[SE slice nal type 6] and 0x0001[I slice nal type 5]. How to set correct parameters for x264 lib if i have real SPS and PPS frames to get the same SPS and PPS frames

    i parse SPS and PPS but i don't know which parameters of x264_param_t param i should set. can someone give me some examples.

  • Adding x264 and AAC encoding to a Telegram-based FFmpeg script

    1er octobre 2024, par Pooria Darvishi

    I'm trying to modify a Telegram script that utilizes static FFmpeg and VPX libraries to also include x264 and AAC encoding. I'm quite new to this and could use some guidance.

    Background:

    Telegram uses static .a files of FFmpeg and VPX, compiled using NDK. I have the script that builds these libraries. I want to modify this script to include x264 and AAC libraries as well.

    Problem:

    I'm unsure how to integrate x264 and AAC into the existing build process and how to configure FFmpeg to use these codecs.

    Code snippets:

    build_ffmpeg.sh:

    #!/bin/bash
    
    # instructions for build
    # used
    # ffmpeg 4.4.3
    # lib vpx 1.10.9
    # NDK for compile libvpx. Last successful build with 21.1.6352462
    # NDK r10e for compile ffmpeg
    #
    # 1) download ffmpeg
    # 2) set NDK_r10e and NDK variables
    # 3) download lib vpx
    # 4) copy libvpx to vpx-android folder and rename as libvpx
    # 5) copy build_ffmpeg foleder in ffmepg directory
    # 6) run build_ffmpeg.sh
    # 7) see compiled library in build_ffmpeg/adnroid folder
    
    NDK="/Users/macbookpro/Library/Android/sdk/ndk/21.1.6352462"
    NDK_r10e="/Users/macbookpro/Library/Android/sdk/ndk/android-ndk-r10e"
    
    #build vpx
    cd ./vpx-android
    export ANDROID_NDK=$NDK
    sh build-vpx.sh
    cd ..
    
    cd ./x264-android
    export ANDROID_NDK=$NDK
    sh build.sh
    cd ..
    
    NDK=$NDK_r10e
    
    function build_one {
    
    echo "Cleaning..."
    rm config.h
    make clean
    
    echo "Configuring..."
    
    INCLUDES=" -I${PREFIX}/include"
    LIBS=" -L${PREFIX}/lib"
    
    cd /Users/macbookpro/Downloads/ffmpeg-4.4.3
    ./configure \
    --cc=$CC \
    --nm=$NM \
    --enable-stripping \
    --arch=$ARCH \
    --target-os=linux \
    --enable-cross-compile \
    --yasmexe=$NDK/prebuilt/darwin-x86_64/bin/yasm \
    --prefix=$PREFIX \
    --enable-pic \
    --disable-shared \
    --enable-static \
    --enable-asm \
    --enable-inline-asm \
    --cross-prefix=$CROSS_PREFIX \
    --sysroot=$PLATFORM \
    --extra-cflags="${INCLUDES} -Wl,-Bsymbolic -Os -DCONFIG_LINUX_PERF=0 -DANDROID $OPTIMIZE_CFLAGS -fPIE -pie --static -fPIC" \
    --extra-ldflags="${LIBS} -Wl,-Bsymbolic -Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -fPIC" \
    --extra-libs="-lgcc" \
    \
    --enable-version3 \
    --enable-gpl \
    \
    --disable-doc \
    --disable-avx \
    \
    --disable-everything \
    --disable-network \
    --disable-zlib \
    --disable-avfilter \
    --disable-avdevice \
    --disable-postproc \
    --disable-debug \
    --disable-programs \
    --disable-network \
    \
    --enable-libvpx \
    --enable-decoder=libvpx_vp9 \
    --enable-libx264 \
    --enable-runtime-cpudetect \
    --enable-pthreads \
    --enable-avresample \
    --enable-swscale \
    --enable-protocol=file \
    --enable-decoder=h264 \
    --enable-decoder=mpeg4 \
    --enable-decoder=mjpeg \
    --enable-decoder=gif \
    --enable-decoder=alac \
    --enable-decoder=opus \
    --enable-demuxer=mov \
    --enable-demuxer=gif \
    --enable-demuxer=ogg \
    --enable-demuxer=matroska \
    --enable-hwaccels \
    --enable-runtime-cpudetect \
    $ADDITIONAL_CONFIGURE_FLAG
    
    #echo "continue?"
    #read
    make -j8 install
    
    }
    
    #x86_64
    PREBUILT=$NDK/toolchains/x86_64-4.9/prebuilt/darwin-x86_64
    PLATFORM=$NDK/platforms/android-21/arch-x86_64
    LD=$PREBUILT/bin/x86_64-linux-android-ld
    AR=$PREBUILT/bin/x86_64-linux-android-ar
    NM=$PREBUILT/bin/x86_64-linux-android-nm
    GCCLIB=$PREBUILT/lib/gcc/x86_64-linux-android/4.9/libgcc.a
    CC=$PREBUILT/bin/x86_64-linux-android-gcc
    CROSS_PREFIX=$PREBUILT/bin/x86_64-linux-android-
    ARCH=x86_64
    CPU=x86_64
    PREFIX=./android/x86_64
    ADDITIONAL_CONFIGURE_FLAG="--disable-mmx --disable-inline-asm"
    build_one
    
    #arm64-v8a
    PREBUILT=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64
    PLATFORM=$NDK/platforms/android-21/arch-arm64
    LD=$PREBUILT/bin/aarch64-linux-android-ld
    AR=$PREBUILT/bin/aarch64-linux-android-ar
    NM=$PREBUILT/bin/aarch64-linux-android-nm
    GCCLIB=$PREBUILT/lib/gcc/aarch64-linux-android/4.9/libgcc.a
    CC=$PREBUILT/bin/aarch64-linux-android-gcc
    CROSS_PREFIX=$PREBUILT/bin/aarch64-linux-android-
    ARCH=arm64
    CPU=arm64-v8a
    OPTIMIZE_CFLAGS=
    PREFIX=./android/arm64-v8a
    ADDITIONAL_CONFIGURE_FLAG="--enable-neon --enable-optimizations"
    build_one
    
    #arm v7n
    PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
    PLATFORM=$NDK/platforms/android-16/arch-arm
    LD=$PREBUILT/bin/arm-linux-androideabi-ld
    AR=$PREBUILT/bin/arm-linux-androideabi-ar
    NM=$PREBUILT/bin/arm-linux-androideabi-nm
    GCCLIB=$PREBUILT/lib/gcc/arm-linux-androideabi/4.9/libgcc.a
    CC=$PREBUILT/bin/arm-linux-androideabi-gcc
    CROSS_PREFIX=$PREBUILT/bin/arm-linux-androideabi-
    ARCH=arm
    CPU=armv7-a
    OPTIMIZE_CFLAGS="-marm -march=$CPU"
    PREFIX=./android/armeabi-v7a
    ADDITIONAL_CONFIGURE_FLAG=--enable-neon
    build_one
    
    #x86
    PREBUILT=$NDK/toolchains/x86-4.9/prebuilt/darwin-x86_64
    PLATFORM=$NDK/platforms/android-16/arch-x86
    LD=$PREBUILT/bin/i686-linux-android-ld
    AR=$PREBUILT/bin/i686-linux-android-ar
    NM=$PREBUILT/bin/i686-linux-android-nm
    GCCLIB=$PREBUILT/lib/gcc/i686-linux-android/4.9/libgcc.a
    CC=$PREBUILT/bin/i686-linux-android-gcc
    CROSS_PREFIX=$PREBUILT/bin/i686-linux-android-
    ARCH=x86
    CPU=i686
    OPTIMIZE_CFLAGS="-march=$CPU"
    PREFIX=./android/x86
    ADDITIONAL_CONFIGURE_FLAG="--disable-mmx --disable-yasm"
    build_one
    
      if [[ -e ./build_ffmpeg/android ]]; then
          rm -rf ./build_ffmpeg/android
      fi
    
    mv ./android ./build_ffmpeg/
    

    build-vpx.sh:

    #!/bin/bash
    
    set -u
    . _settings.sh
    
    LIB_VPX="libvpx"
    LIB_GIT=v1.10.0
    
    if [[ -f "${LIB_VPX}/build/make/version.sh" ]]; then
      version=`"${LIB_VPX}/build/make/version.sh" --bare "${LIB_VPX}"`
    fi
    
    configure_make() {
      pushd "${LIB_VPX}" || exit
      ABI=$1;
      echo -e "\n** BUILD STARTED: ${LIB_VPX} (${version}) for ${ABI} **"
    
      configure "$@"
      case ${ABI} in
        armeabi)
          TARGET="armv7-android-gcc --disable-neon --disable-neon-asm"
        ;;
        armeabi-v7a)
          TARGET="armv7-android-gcc --enable-neon --disable-neon-asm"
        ;;
        arm64-v8a)
          TARGET="arm64-android-gcc"
        ;;
        x86)
          TARGET="x86-android-gcc"
        ;;
        x86_64)
          TARGET="x86_64-android-gcc"
        ;;
        mips)
          TARGET="mips32-linux-gcc"
        ;;
        mips64)
          TARGET="mips64-linux-gcc"
        ;;
      esac
    
    make clean
    
    CPU_DETECT="--disable-runtime-cpu-detect"
    if [[ $1 =~ x86.* ]]; then
       CPU_DETECT="--enable-runtime-cpu-detect"
    fi
    
      ./configure \
        --extra-cflags="-isystem ${NDK_SYSROOT}/usr/include/${NDK_ABIARCH} -isystem ${NDK_SYSROOT}/usr/include" \
        --libc=${NDK_SYSROOT} \
        --prefix=${PREFIX} \
        --target=${TARGET} \
        ${CPU_DETECT} \
        --as=auto \
        --disable-docs \
        --enable-pic \
        --enable-libyuv \
        --enable-static \
        --enable-small \
        --enable-optimizations \
        --enable-better-hw-compatibility \
        --enable-realtime-only \
        --enable-vp8 \
        --enable-vp9 \
        --disable-webm-io \
        --disable-examples \
        --disable-tools \
        --disable-debug \
        --disable-unit-tests || exit 1
    
      make -j${HOST_NUM_CORES} install
      popd || true
    }
    
    for ((i=0; i < ${#ABIS[@]}; i++))
    do
      if [[ $# -eq 0 ]] || [[ "$1" == "${ABIS[i]}" ]]; then
        [[ ${ANDROID_API} -lt 21 ]] && ( echo "${ABIS[i]}" | grep 64 > /dev/null ) && continue;
        configure_make "${ABIS[i]}"
        echo -e "** BUILD COMPLETED: ${LIB_VPX} for ${ABIS[i]} **\n\n"
      fi
    done
    

    _settings.sh:

    #!/bin/bash
    
    if [[ -z $ANDROID_NDK ]] || [[ ! -d $ANDROID_NDK ]] ; then
        echo "You need to set ANDROID_NDK environment variable, exiting"
        echo "Use: export ANDROID_NDK=/your/path/to/android-ndk-rxx"
        echo "e.g.: export ANDROID_NDK=/opt/android/android-ndk-r18b"
        exit 1
    fi
    
    set -u
    
    ANDROID_API=21
    
    ABIS=("armeabi-v7a" "arm64-v8a" "x86" "x86_64")
    
    BASEDIR=`pwd`
    NDK=${ANDROID_NDK}
    HOST_NUM_CORES=$(nproc)
    
    CFLAGS_="-DANDROID -fpic -fpie"
    LDFLAGS_=""
    
    configure() {
      ABI=$1;
    
      case $ABI in
        armeabi)
          NDK_ARCH="arm"
          NDK_ABIARCH="arm-linux-androideabi"
          CFLAGS="-march=armv5 -marm -finline-limit=64"
          LDFLAGS=""
          ASFLAGS=""
        ;;
        armeabi-v7a)
          NDK_ARCH="arm"
          NDK_ABIARCH="arm-linux-androideabi"
          CFLAGS="${CFLAGS_} -Os -march=armv7-a -mfloat-abi=softfp -mfpu=neon -mtune=cortex-a8 -mthumb -D__thumb__"
          LDFLAGS="${LDFLAGS_} -march=armv7-a"
          ASFLAGS=""
        ;;
        arm64-v8a)
          NDK_ARCH="arm64"
          NDK_ABIARCH="aarch64-linux-android"
          CFLAGS="${CFLAGS_} -O3 -march=armv8-a"
          LDFLAGS="${LDFLAGS_}"
          ASFLAGS=""
        ;;
        x86)
          NDK_ARCH="x86"
          NDK_ABIARCH="i686-linux-android"
          CFLAGS="${CFLAGS_} -O3 -march=i686 -mtune=intel -msse3 -mfpmath=sse -m32 -fPIC"
          LDFLAGS="-m32"
          ASFLAGS="-D__ANDROID__"
        ;;
        x86_64)
          NDK_ARCH="x86_64"
          NDK_ABIARCH="x86_64-linux-android"
          CFLAGS="${CFLAGS_} -O3 -march=x86-64 -mtune=intel -msse4.2 -mpopcnt -m64 -fPIC"
          LDFLAGS=""
          ASFLAGS="-D__ANDROID__"
        ;;
      esac
    
      TOOLCHAIN_PREFIX=${BASEDIR}/android-toolchain
      NDK_SYSROOT=${TOOLCHAIN_PREFIX}/sysroot
    
      if [[ -e ${TOOLCHAIN_PREFIX} ]]; then
          rm -rf ${TOOLCHAIN_PREFIX}
      fi
    
      [[ -d ${TOOLCHAIN_PREFIX} ]] || python3 ${NDK}/build/tools/make_standalone_toolchain.py \
         --arch ${NDK_ARCH} \
         --api ${ANDROID_API} \
         --stl libc++ \
         --install-dir=${TOOLCHAIN_PREFIX}
    
      PREFIX=../../android/${ABI}
    
    
      export PATH=${TOOLCHAIN_PREFIX}/bin:$PATH
      export CROSS_PREFIX=${TOOLCHAIN_PREFIX}/bin/${NDK_ABIARCH}-
      export CFLAGS="${CFLAGS}"
      export CPPFLAGS="${CFLAGS}"
      export CXXFLAGS="${CFLAGS} -std=c++11"
      export ASFLAGS="${ASFLAGS}"
      export LDFLAGS="${LDFLAGS} -L${NDK_SYSROOT}/usr/lib"
    
      export AR="${CROSS_PREFIX}ar"
      export AS="${CROSS_PREFIX}clang"
      export CC="${CROSS_PREFIX}clang"
      export CXX="${CROSS_PREFIX}clang++"
      export LD="${CROSS_PREFIX}ld"
      export STRIP="${CROSS_PREFIX}strip"
      export RANLIB="${CROSS_PREFIX}ranlib"
      export CPP="${CROSS_PREFIX}cpp"
      export NM="${CROSS_PREFIX}nm"
    
      echo "**********************************************"
      echo "### Use NDK=${NDK}"
      echo "### Use ANDROID_API=${ANDROID_API}"
      echo "### Install directory: PREFIX=${PREFIX}"
      echo "**********************************************"
    }
    

    Any help would be greatly appreciated.

    I'm working on an Android app that requires custom video encoding using FFmpeg. I've tried to build a newer version of FFmpeg but couldn't integrate it into my project due to the older version requirement. I've also tried pre-built scripts that support a wide range of codecs, but they don't generate the necessary .a files for libraries like x264, VPX, and AAC.