Newest 'x264' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Optimizing x264 based remote desktop by dirty regions

    17 novembre 2016, par useprxf

    I was using x264 to achieve remote desktop, but had some problems on handling P_SKIP detection.

    Dirty regions indicate changed areas. For those 16x16 macroblocks which don't intersect any dirty region, I would like to encode them as P_SKIP macroblocks.

    I tried to add the following code into x264_macroblock_prob_skip_internal function:

    if (! h->isdirty[h->mb.i_mb_x][h->mb.i_mb_y])       // isdirty is a 2-dim array indicating dirty macroblocks
        return 1;
    

    but there is almost no speed-up. I think it may be the information preparation for the macroblock analysis that take influence.

    How to speed up x264 by considering dirty regions?

  • Send H.264 encoded stream through RTMP using FFmpeg

    15 novembre 2016, par Galaxy

    I followed this to encode a sequences images to h.264 video.

    Here is outputting part of my code:

    int srcstride = outwidth*4;
    sws_scale(convertCtx, src_data, &srcstride, 0, outheight, pic_in.img.plane, pic_in.img.i_stride);
    x264_nal_t* nals;
    int i_nals;
    int frame_size = x264_encoder_encode(encoder, &nals, &i_nals, &pic_in, &pic_out);
    if (frame_size) {
        fwrite(nals[0].p_payload, frame_size, 1, fp);
    }
    

    This is in a loop to process frames and write them into a file.

    Now, I'm trying to stream these encoded frames through RTMP. As I know, the container for the RTMP is FLV. So I used command line as a trial:

    ffmpeg -i test.h264 -vcodec copy -f flv rtmp://localhost:1935/hls/test
    

    This one works well as streaming a h.264 encoded video file.

    But how can I implement it as C++ code and stream the frames at the same time when they are generated, just like what I did to stream my Facetime camera.

    ffmpeg -f avfoundation -pix_fmt uyvy422  -video_size 1280x720 -framerate 30 -i "1:0" -pix_fmt yuv420p -vcodec libx264 -preset veryfast -acodec libvo_aacenc -f flv -framerate 30 rtmp://localhost:1935/hls/test
    

    This may be a common and practical topic. But I'm stuck here for days, really need some relevant exprience. Thank you!

  • Send H.264 encoded stream through RTMP using FFmpeg

    15 novembre 2016, par Galaxy

    I followed this to encode a sequences images to h.264 video.

    Here is outputting part of my code:

    int srcstride = outwidth*4;
    sws_scale(convertCtx, src_data, &srcstride, 0, outheight, pic_in.img.plane, pic_in.img.i_stride);
    x264_nal_t* nals;
    int i_nals;
    int frame_size = x264_encoder_encode(encoder, &nals, &i_nals, &pic_in, &pic_out);
    if (frame_size) {
        fwrite(nals[0].p_payload, frame_size, 1, fp);
    }
    

    This is in a loop to process frames and write them into a file.

    Now, I'm trying to stream these encoded frames through RTMP. As I know, the container for the RTMP is FLV. So I used command line as a trial:

    ffmpeg -i test.h264 -vcodec copy -f flv rtmp://localhost:1935/hls/test
    

    This one works well as streaming a h.264 encoded video file.

    But how can I implement it as C++ code and stream the frames at the same time when they are generated, just like what I did to stream my Facetime camera.

    ffmpeg -f avfoundation -pix_fmt uyvy422  -video_size 1280x720 -framerate 30 -i "1:0" -pix_fmt yuv420p -vcodec libx264 -preset veryfast -acodec libvo_aacenc -f flv -framerate 30 rtmp://localhost:1935/hls/test
    

    This may be a common and practical topic. But I'm stuck here for days, really need some relevant exprience. Thank you!

  • Build FFMPEG with x264 for Android

    12 novembre 2016, par Kage

    I am trying to build FFMPEG with libx264 for Android.

    I can successfully build and use FFMPEG for Android but I realized that I need the ability to encode, therefore I am trying to build FFMPEG with x264.

    I am using this tutorial to build FFmpeg for Android http://www.roman10.net/how-to-build-ffmpeg-for-android/

    When trying to build FFMPEG I get an error:

    "ERROR: libx264 not found"

    And in my log it says:

    "/usr/local/lib/libx264.a: could not read symbols: Archive has no index; run ranlib to add one..."

    I have the latest versions of both FFMPEG and x264. I understand that FFMPEG looks for the header and libraries in usr/lib and usr/include, so in order to make it find x264 I use the cflags and ldflags:

    • --extra-cflags = " -I/usr/local/include "
    • --extra-ldflags = " -L/usr/local/lib "

    I have tried building x264 with many different options that other people on the internet have said that i need. eg. --enable-shared, --enable-static, --disable-pthreads etc. Some forums say enable this, others say no disable that.

    Any help would be much appreciated, Thanks

    EDIT:

    If I build FFmpeg with the simplest commands to include libx264 then it works. ie.

    ./configure --enable-gpl --enable-libx264 --extra-cflags="-I/usr/local/include" --extra-ldflags="-L/usr/local/lib" --enable-static --enable-shared
    

    However I need it to work for Android. The script I am using is:

    NDK=~/Desktop/android-ndk-r7
    PLATFORM=$NDK/platforms/android-8/arch-arm/
    PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86
    function build_one
    {
    ./configure --target-os=linux \
        --prefix=$PREFIX \
        --enable-cross-compile \
        --enable-shared \
        --enable-static \
        --extra-libs="-lgcc" \
        --arch=arm \
        --cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
        --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
        --nm=$PREBUILT/bin/arm-linux-androideabi-nm \
        --sysroot=$PLATFORM \
        --extra-cflags=" -O3 -fpic -DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm -Wno-psabi -fno-short-enums -fno-strict-aliasing -finline-limit=300 $OPTIMIZE_CFLAGS -I/usr/local/include" \
        --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L $PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog -L/usr/local/lib " \
        --enable-gpl \
        --enable-libx264 \
        --disable-everything \
        --enable-demuxer=mov \
        --enable-demuxer=h264 \
        --disable-ffplay \
        --enable-protocol=file \
        --enable-avformat \
        --enable-avcodec \
        --enable-decoder=rawvideo \
        --enable-decoder=mjpeg \
        --enable-decoder=h263 \
        --enable-decoder=mpeg4 \
        --enable-decoder=h264 \
        --enable-encoder=mjpeg \
        --enable-encoder=h263 \
        --enable-encoder=mpeg4 \
        --enable-encoder=h264 \
        --enable-parser=h264 \
        --disable-network \
        --enable-zlib \
        --disable-avfilter \
        --disable-avdevice \
        $ADDITIONAL_CONFIGURE_FLAG
    
    make clean
    make  -j4 install
    $PREBUILT/bin/arm-linux-androideabi-ar d libavcodec/libavcodec.a inverse.o
    $PREBUILT/bin/arm-linux-androideabi-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib  -soname libffmpeg.so -shared -nostdlib  -z,noexecstack -Bsymbolic --whole-archive --no-undefined -o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog  --warn-once  --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a
    }
    
    CPU=armv7-a
    OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "
    PREFIX=./android/$CPU
    ADDITIONAL_CONFIGURE_FLAG=
    build_one
    

    I am guessing that some option in my configure command is conflicting with enabling libx264

    NOTE: If I remove --enable-libx264 then it works

  • How to Compile FFmpeg with x264 and libfdk-aac for Android

    12 novembre 2016, par Codeveloper

    Everyone.

    Please understand that i use the wrong english.

    I want to make encoding application using FFmpeg.

    I was successfully building NDK with FFmpeg.

    However, to encode H.264 video made had failed( Codec not found.. ).

    I was learned that libx264 is need encode H.264 and libfdk-aac is need encode AAC.

    so I tried to build the libx264 and libfdk-aac, But does not easily cross-compile.

    Please tell me what I did wrong.

    My Development Environment

    OS : ubuntu 13.10 64bit

    NDK : android-ndk-r9

    FFmpeg : ffmpeg-2.0.2

    x264 build : build_x264_android.sh

    NDK=$ANDROID_NDK_HOME
    
    TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64
    PLATFORM=$NDK/platforms/android-9/arch-arm
    CPU=arm
    PREFIX=$NDK/sources/ffmpeg-2.0.2/android/$CPU
    
    ./configure --prefix=$PREFIX \
        --enable-shared \
        --enable-pic \
        --disable-asm \
        --disable-cli \
        --host=arm-linux \
        --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
        --sysroot=$PLATFORM
    
    make
    make install
    ldconfig
    

    fdk-aac build : build_aac_android.sh

    NDK=$ANDROID_NDK_HOME
    CROSS_PREFIX=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
    PLATFORM=$NDK/platforms/android-9/arch-arm
    CPU=arm
    PREFIX=$NDK/sources/ffmpeg-2.0.2/android/$CPU
    OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=armv7-a -mthumb -D__thumb__"
    
    ./configure --prefix=$PREFIX \
        --with-sysroot=$PLATFORM \
        --host=arm-linux \
        --enable-shared \
        --with-pic=no \
        CC="${CROSS_PREFIX}gcc --sysroot=$PLATFORM" \
        CXX="${CROSS_PREFIX}g++ --sysroot=$PLATFORM" \
        RANLIB="${CROSS_PREFIX}ranlib" \
        AR="${CROSS_PREFIX}ar" \
        STRIP="${CROSS_PREFIX}strip" \
        NM="${CROSS_PREFIX}nm" \
        CFLAGS="-O3 $OPTIMIZE_CFLAGS --sysroot=$PLATFORM" \
        CXXFLAGS="-O3 $OPTIMIZE_CFLAGS --sysroot=$PLATFORM"
    
    make
    make install
    

    When I run 'build_aac_android.sh', shown error.

    log in config.log

    configure:2907: checking for arm-linux-gcc
    configure:2934: result: /toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/platforms/android-9/arch-arm
    configure:3203: checking for C compiler version
    configure:3212: /toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/platforms/android-9/arch-arm --version >&5
    ./configure: line 3214: /toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc: No such file or directory
    configure:3223: $? = 127
    configure:3212: /toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/platforms/android-9/arch-arm -v >&5
    ./configure: line 3214: /toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc: No such file or directory
    configure:3223: $? = 127
    configure:3212: /toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/platforms/android-9/arch-arm -V >&5
    ./configure: line 3214: /toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc: No such file or directory
    configure:3223: $? = 127
    configure:3212: /toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/platforms/android-9/arch-arm -qversion >&5
    ./configure: line 3214: /toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc: No such file or directory
    configure:3223: $? = 127
    configure:3243: checking whether the C compiler works
    configure:3265: /toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/platforms/android-9/arch-arm -O3 -mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=armv7-a -mthumb -D__thumb__ --sysroot=/platforms/android-9/arch-arm   conftest.c  >&5
    ./configure: line 3267: /toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc: No such file or directory
    
    configure:3312: error: in `/home/nel/android-ndk-r9/sources/ffmpeg-2.0.2/libfdk-aac':
        configure:3314: error: C compiler cannot create executables
        See `config.log' for more details
    

    I cannot understand that error!! I was confirmed that arm-linux-androideabi-gcc is found in the directory..

    I want to borrow you wisdom. Please tell me how to 'ffmpeg+x264+fdk-aac' build for android.

    Thanks.. :-)