Newest 'x264' Questions - Stack Overflow
Les articles publiés sur le site
-
Incorrect length of video produced with ffmpeg libraries [closed]
28 mars, par ivan.ukrI'm writing a C program that takes series of PNG images and converts them into a video. Video consists of the initial black screen and then each of those images, shown for the same constant amount of time, say 200 ms. I'm using
libx264
as codec andmp4
as output format. I'm compiling my program with GCC 12 on Ubuntu 22.04 LTS. I'm using ffmpeg version from Ubuntu repositories. In order to achieve above behavior I've set time base to 1/5 in the both stream and codec.// assume imageDuration = 200 AVRational timeBase; av_reduce(&timeBase.num, &timeBase.den, imageDuration, 1000, INT_MAX); const AVCodec *c = avcodec_find_encoder(codecId); AVStream *s = avformat_new_stream(fc, c); s->time_base = timeBase; s->nb_frames = numImages + 1; // inital black screen + images s->duration = numImages + 1; AVCodecContext *cc = avcodec_alloc_context3(c); cc->width = width; cc->height = height; cc->pix_fmt = pixelFormat; cc->time_base = timeBase; // ffmpeg headers suggest: Set to time_base ticks per frame. // Default 1, e.g., H.264/MPEG-2 set it to 2. cc->ticks_per_frame = 2; cc->framerate = av_inv_q(timeBase); if (fc->oformat->flags & AVFMT_GLOBALHEADER) { cc->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; }
Then I'm encoding 11 frames.
Finally, I'm getting video with the following characteristics:
$ ffprobe v.mp4 .... Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'v.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf58.76.100 Duration: 00:00:00.01, start: 0.000000, bitrate: 68414 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 69073 kb/s, 10333.94 fps, 10240 tbr, 10240 tbn, 10 tbc (default) Metadata: handler_name : VideoHandler vendor_id : [0][0][0][0]
Please pay attention to:
Duration: 00:00:00.01
and
10333.94 fps
That's totally NOT what I've expected (2.2s video length and 5 fps frame rate).
Note: The content of video is correct, this can be verified by looking into the generated video file frame-by-frame in some program like Avidemux. But video length and frame rate are incorrect.
Please advise, how to fix this?
-
How to initialize video decoder with a already decoded frame ?
27 mars, par Ragdoll CarLet's say I have an FFmpeg video decoder x264 initially initialized with some parameters. I am using C++ in my scenario. In normal conditions we push an encoded I-frame into such decoder and then referencing encoded P-frames.
I have a special case where my I-frame is already decoded. So in my case I want to:
- push already decoded I-frame into my decoder
- push referencing encoded P-frames into my decoder
How can I initialize the decoder state with already decoded I-frame? Currently to bypass these limitations I have to:
- create a new temporary encoder
- encode already decoded I-frame
- decode encoded I-frame
- and then I am able to push referencing encoded P-frames
-
FFMPEG compile with x264 support for Android
10 mars, par PecanaI am trying to build ffmpeg extensions for media3 (ExoPlayer) for Android
https://github.com/androidx/media/tree/release/libraries/decoder_ffmpeg
Using the default settings everything is fine but if I try to add support to libx264 the build failed. I compiled x264 for Android locally and it worked so the .so file for arm64 is present, I added it to the pkg-config with :
export PKG_CONFIG_PATH=/build/x264/arm64/lib/pkgconfig:$PKG_CONFIG_PATH
but when I try to build ffmpeg with the following command it fails :
./configure \ --prefix=/build/ffmpeg \ --enable-gpl \ --enable-libx264 \ --enable-static \ --enable-pic \ --arch=arm64 \ --target-os=android \ --cross-prefix=$TOOLCHAIN/bin/aarch64-linux-android21- \ --sysroot=$SYSROOT
Error : ERROR: x264 not found using pkg-config
But it is not due to pkg-config as the command:
pkg-config --cflags --libs x264
reports : -DX264_API_IMPORTS -I/build/x264/arm64/include -L/build/x264/arm64/lib -lx264
Any idea on how to fix it ?
Thank you :-)
-
avcodec_find_encoder(AV_CODEC_ID_H264) returns null
22 janvier, par Monjura RumiI am building an android application which will encode image captured from camera preview and later decode it. I am using ffmpeg library to encode and decode. To build static library with x264 I have used this tutorial. http://dl.dropbox.com/u/22605641/ffmpeg_android/main.html. As a source code of ffmpeg if I use the one downloaded from the link given in tutorial I can built it but can't build library if i use source code downloaded from here git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg. I have built library in ubuntu and using it in windows 7 in Eclipse. As I need only h264 encoder and decoder I have used following code for ffmpeg, slightly modified from tutorial.
#!/bin/bash NDK=~/Documents/android-ndk-r8e PLATFORM=$NDK/platforms/android-8/arch-arm PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86 PREFIX=/home/android-ffmpeg function build_one { ./configure --target-os=linux --prefix=$PREFIX \ --enable-cross-compile \ --enable-runtime-cpudetect \ --disable-asm \ --arch=arm \ --cc=$PREBUILT/bin/arm-linux-androideabi-gcc \ --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \ --disable-stripping \ --nm=$PREBUILT/bin/arm-linux-androideabi-nm \ --sysroot=$PLATFORM \ --enable-nonfree \ --enable-version3 \ --disable-everything \ --enable-gpl \ --disable-doc \ --enable-avresample \ --disable-ffplay \ --disable-ffserver \ --enable-ffmpeg \ --disable-ffprobe \ --enable-avcodec \ --enable-libx264 \ --enable-encoder=libx264 \ --enable-encoder=libx264rgb \ --enable-decoder=h263 \ --enable-decoder=h264 \ --enable-decoder=svq3 \ --enable-zlib \ --enable-gpl \ --enable-pic \ --disable-devices \ --disable-avdevice \ --extra-cflags="-I/home/android-ffmpeg/include -fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=armv7-a" \ --extra-ldflags="-L/home/android-ffmpeg/lib" 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 -L$PREFIX/lib -soname libffmpeg.so -shared -nostdlib -z,noexecstack -Bsymbolic --whole-archive --no-undefined -o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavfilter/libavfilter.a libavresample/libavresample.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog -lx264 --warn-once --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a } build_one
After building library I have been able to build android ndk. A little part of my JNI code is here.
JNIEXPORT jint JNICALL Java_com_example_testjava_TestjniActivity_initencoder(JNIEnv* env,jobject obj){ av_register_all(); avcodec_register_all(); codec = avcodec_find_encoder(AV_CODEC_ID_H264); if (!codec) { __android_log_write(ANDROID_LOG_INFO, "debug", "not found"); return -1; } . . . }
When I run my java source code that calls initencoder() I get -1 as return value and logcat prints "not found". That means avcodec_find_encoder() returns null and if condition is being ok. I don't know what's wrong. Why this function is returning null? I have searched a lot but did not find any solution that could guide me to right direction. some says to use avcodec_init(). But ndk-build command fails and shows error saying undefined reference to 'avcodec_init()'. I have started with library build because I thought may be I am doing wrong from the first stage. Did I make any mistake in library building like not enabling things that I should? Please help me here. This is kind of urgent for me.
-
Per macroblock encoding in libx264
12 janvier, par Wei.MI know that in x264 encoding, the process is going on with the unit of macroblock. However, is that possible to set the parameters for each macroblocks? For example, if I want to let the QP of some specific area to be smaller than others. Is that possible? If I need to modify the functions and Apis in libx264, where should I begin?