Newest 'x264' Questions - Stack Overflow
Les articles publiés sur le site
-
How to Compile FFmpeg with x264 and libfdk-aac for Android
12 novembre 2016, par CodeveloperEveryone.
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.. :-)
-
Python-Opencv Write x264 video on memory buffer
9 novembre 2016, par faxconI have a problem for writing x264 video(or single frame) on memory buffer. In opencv for images, imencode and imdecode do this task. But i want save x264 video frame for lower memory usage and sending on internet. I am able to with jpeg but jpeg size bigger than x264 video frame and quality much worser. I searched but i can't find how i write video frame on buffer.
Here is the example code to taking frames on webcam
import numpy as np import cv2 cap = cv2.VideoCapture(0) cap.set(3,320) cap.set(4,240) cap.set(5,30) # Define the codec and create VideoWriter object fourcc = cv2.VideoWriter_fourcc(*'x264') out = cv2.VideoWriter('.....sample.avi',fourcc, 30.0, (320,240)) while(cap.isOpened()): ret, frame = cap.read() if ret==True: cv2.imshow('frame',frame) out.write(frame) #I want to write memory not disk if cv2.waitKey(1) & 0xFF == ord('q'): break else: break # Release everything if job is finished cap.release() out.release() cv2.destroyAllWindows()
-
Python-Opencv Write x264 video on memory buffer
9 novembre 2016, par faxconI have a problem for writing x264 video(or single frame) on memory buffer. In opencv for images, imencode and imdecode do this task. But i want save x264 video frame for lower memory usage and sending on internet. I am able to with jpeg but jpeg size bigger than x264 video frame and quality much worser. I searched but i can't find how i write video frame on buffer.
Here is the example code to taking frames on webcam
import numpy as np import cv2 cap = cv2.VideoCapture(0) cap.set(3,320) cap.set(4,240) cap.set(5,30) # Define the codec and create VideoWriter object fourcc = cv2.VideoWriter_fourcc(*'x264') out = cv2.VideoWriter('.....sample.avi',fourcc, 30.0, (320,240)) while(cap.isOpened()): ret, frame = cap.read() if ret==True: cv2.imshow('frame',frame) out.write(frame) #I want to write memory not disk if cv2.waitKey(1) & 0xFF == ord('q'): break else: break # Release everything if job is finished cap.release() out.release() cv2.destroyAllWindows()
-
Encoding RGB frames using x264 and AVCodec in C
6 novembre 2016, par deepworkI have RGB24 frames streamed from camera and i want to encode them into h264 ,i found that AVCodec and x264 can do so, the problem is x264 as default accepts YUV420 as input so what i wrote was a program which convert RGB frames to YUV420 .that was by sws_scale function .this works well except that it does not satisfy the required FPS because the converting (RGB->YUV420) takes time.
This is how i setup my encoder context :
videoStream->id = 0; vCodecCtx = videoStream->codec; vCodecCtx->coder_type = AVMEDIA_TYPE_VIDEO; vCodecCtx->codec_id = AV_CODEC_ID_H264; vCodecCtx->bit_rate = 400000; vCodecCtx->width = Width; vCodecCtx->height = Height; vCodecCtx->time_base.den = FPS; vCodecCtx->time_base.num = 1; //vCodecCtx->time_base = (AVRational){1,}; vCodecCtx->gop_size = 12; vCodecCtx->max_b_frames = 1; vCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P; if(formatCtx->oformat->flags & AVFMT_GLOBALHEADER) vCodecCtx->flags |= CODEC_FLAG_GLOBAL_HEADER; av_opt_set(vCodecCtx->priv_data, "preset", "ultrafast", 0); av_opt_set(vCodecCtx->priv_data, "profile", "baseline", AV_OPT_SEARCH_CHILDREN); if (avcodec_open2(vCodecCtx, h264Codec, NULL) < 0){ return 0; }
when i changes AV_PIX_FMT_YUV420P to AV_PIX_FMT_RGB24 ,avcodec_open2 will fail. i read that there is a version of libx264 for RGB called libx264rgb but i even dont know whether i have to rebuild x264 with enabling this option or to download another source or i have to do it programmatically with the first x264 lib.
the question is how to enable RGB as input to libx264 to use with libavcodec in C .or how to make the encoding or sws_scale more fast .
Edit:
How i built ffmpeg :
NDK=D:/AndroidDev/android-ndk-r9 PLATFORM=$NDK/platforms/android-18/arch-arm/ PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64 GENERAL="\ --enable-small \ --enable-cross-compile \ --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 \ --extra-cflags="-I../x264/android/arm/include" \ --extra-ldflags="-L../x264/android/arm/lib" " MODULES="\ --enable-gpl \ --enable-libx264" function build_ARMv6 { ./configure \ --target-os=linux \ --prefix=./android/armeabi \ ${GENERAL} \ --sysroot=$PLATFORM \ --enable-shared \ --disable-static \ --extra-cflags=" -O3 -fpic -fasm -Wno-psabi -fno-short-enums -fno-strict-aliasing -finline-limit=300 -mfloat-abi=softfp -mfpu=vfp -marm -march=armv6" \ --extra-ldflags="-lx264 -Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" \ --enable-zlib \ ${MODULES} \ --disable-doc \ --enable-neon make clean make make install } build_ARMv6 echo Android ARMEABI builds finished
How i built x264 :
NDK=D:/AndroidDev/android-ndk-r9 PLATFORM=$NDK/platforms/android-18/arch-arm/ TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64 PREFIX=./android/arm function build_one { ./configure \ --prefix=$PREFIX \ --enable-static \ --enable-pic \ --host=arm-linux \ --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \ --sysroot=$PLATFORM make clean make make install } build_one echo Android ARM builds finished
-
Encoding RGB frames using x264 and AVCodec in C
6 novembre 2016, par deepworkI have RGB24 frames streamed from camera and i want to encode them into h264 ,i found that AVCodec and x264 can do so, the problem is x264 as default accepts YUV420 as input so what i wrote was a program which convert RGB frames to YUV420 .that was by sws_scale function .this works well except that it does not satisfy the required FPS because the converting (RGB->YUV420) takes time.
This is how i setup my encoder context :
videoStream->id = 0; vCodecCtx = videoStream->codec; vCodecCtx->coder_type = AVMEDIA_TYPE_VIDEO; vCodecCtx->codec_id = AV_CODEC_ID_H264; vCodecCtx->bit_rate = 400000; vCodecCtx->width = Width; vCodecCtx->height = Height; vCodecCtx->time_base.den = FPS; vCodecCtx->time_base.num = 1; //vCodecCtx->time_base = (AVRational){1,}; vCodecCtx->gop_size = 12; vCodecCtx->max_b_frames = 1; vCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P; if(formatCtx->oformat->flags & AVFMT_GLOBALHEADER) vCodecCtx->flags |= CODEC_FLAG_GLOBAL_HEADER; av_opt_set(vCodecCtx->priv_data, "preset", "ultrafast", 0); av_opt_set(vCodecCtx->priv_data, "profile", "baseline", AV_OPT_SEARCH_CHILDREN); if (avcodec_open2(vCodecCtx, h264Codec, NULL) < 0){ return 0; }
when i changes AV_PIX_FMT_YUV420P to AV_PIX_FMT_RGB24 ,avcodec_open2 will fail. i read that there is a version of libx264 for RGB called libx264rgb but i even dont know whether i have to rebuild x264 with enabling this option or to download another source or i have to do it programmatically with the first x264 lib.
the question is how to enable RGB as input to libx264 to use with libavcodec in C .or how to make the encoding or sws_scale more fast .
Edit:
How i built ffmpeg :
NDK=D:/AndroidDev/android-ndk-r9 PLATFORM=$NDK/platforms/android-18/arch-arm/ PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64 GENERAL="\ --enable-small \ --enable-cross-compile \ --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 \ --extra-cflags="-I../x264/android/arm/include" \ --extra-ldflags="-L../x264/android/arm/lib" " MODULES="\ --enable-gpl \ --enable-libx264" function build_ARMv6 { ./configure \ --target-os=linux \ --prefix=./android/armeabi \ ${GENERAL} \ --sysroot=$PLATFORM \ --enable-shared \ --disable-static \ --extra-cflags=" -O3 -fpic -fasm -Wno-psabi -fno-short-enums -fno-strict-aliasing -finline-limit=300 -mfloat-abi=softfp -mfpu=vfp -marm -march=armv6" \ --extra-ldflags="-lx264 -Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" \ --enable-zlib \ ${MODULES} \ --disable-doc \ --enable-neon make clean make make install } build_ARMv6 echo Android ARMEABI builds finished
How i built x264 :
NDK=D:/AndroidDev/android-ndk-r9 PLATFORM=$NDK/platforms/android-18/arch-arm/ TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64 PREFIX=./android/arm function build_one { ./configure \ --prefix=$PREFIX \ --enable-static \ --enable-pic \ --host=arm-linux \ --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \ --sysroot=$PLATFORM make clean make make install } build_one echo Android ARM builds finished