在 ffmpeg 中优先考虑解码图像质量的 C 标志
C flags which gives priority to quality for decoded images in ffmpeg
我正在尝试在 Android NDK 上使用 ffmpeg(最新版本)解码 h.264 流。
我成功得到一个解码帧。但是,即使禁用低延迟标志,获取的图像也很脏。
如果我想优先考虑质量而不是解码速度,我应该指定哪些标志?
bool initCodec(bool low_latency)
{
av_register_all();
codec = avcodec_find_decoder(AV_CODEC_ID_H264);
if(!codec) return false;
context = avcodec_alloc_context3(codec);
if(!context) return false;
if(codec->capabilities & CODEC_CAP_TRUNCATED) context->flags |= CODEC_FLAG_TRUNCATED;
if(low_latency == true) context->flags |= CODEC_FLAG_LOW_DELAY;
frame = av_frame_alloc();
int res = avcodec_open2(context, codec, NULL);
if (res < 0) {
qDebug() << "Coundn't open codec :" << res;
return false;
}
av_init_packet(&avpkt);
return true;
}
void sendBytes(unsigned char *buf, int buflen)
{
avpkt.size = buflen;
avpkt.data = buf;
int got_frame, len;
while (avpkt.size > 0) {
len = avcodec_decode_video2(context, frame, &got_frame, &avpkt);
if (len < 0) {
qDebug() << "Error while decoding : " << len;
break;
}
if (got_frame) {
onGotFrame(frame);
}
avpkt.size -= len;
avpkt.data += len;
}
}
Ex: 我听说它在编译库时出了问题。所以我在这里写了一个编译选项(我是在OpenSUSE上构建的Linux)。
#!/bin/bash
NDK=/home/ndk
SYSROOT=$NDK/platforms/android-9/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
function build_one
{
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-avdevice \
--disable-doc \
--disable-symver \
--disable-encoders \
--disable-decoders \
--enable-decoder=h264 \
--enable-decoder=aac \
--disable-protocols \
--disable-demuxers \
--disable-muxers \
--disable-filters \
--disable-network \
--disable-parsers \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=arm \
--enable-asm --enable-yasm \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -marm -march=armv7-a -mfloat-abi=softfp -mfpu=neon" \
--extra-ldflags="-Wl,--fix-cortex-a8" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
}
CPU=armv7-a
PREFIX=$(pwd)/android/$CPU
build_on
我正在尝试在 Android NDK 上使用 ffmpeg(最新版本)解码 h.264 流。
我成功得到一个解码帧。但是,即使禁用低延迟标志,获取的图像也很脏。
如果我想优先考虑质量而不是解码速度,我应该指定哪些标志?
bool initCodec(bool low_latency)
{
av_register_all();
codec = avcodec_find_decoder(AV_CODEC_ID_H264);
if(!codec) return false;
context = avcodec_alloc_context3(codec);
if(!context) return false;
if(codec->capabilities & CODEC_CAP_TRUNCATED) context->flags |= CODEC_FLAG_TRUNCATED;
if(low_latency == true) context->flags |= CODEC_FLAG_LOW_DELAY;
frame = av_frame_alloc();
int res = avcodec_open2(context, codec, NULL);
if (res < 0) {
qDebug() << "Coundn't open codec :" << res;
return false;
}
av_init_packet(&avpkt);
return true;
}
void sendBytes(unsigned char *buf, int buflen)
{
avpkt.size = buflen;
avpkt.data = buf;
int got_frame, len;
while (avpkt.size > 0) {
len = avcodec_decode_video2(context, frame, &got_frame, &avpkt);
if (len < 0) {
qDebug() << "Error while decoding : " << len;
break;
}
if (got_frame) {
onGotFrame(frame);
}
avpkt.size -= len;
avpkt.data += len;
}
}
Ex: 我听说它在编译库时出了问题。所以我在这里写了一个编译选项(我是在OpenSUSE上构建的Linux)。
#!/bin/bash
NDK=/home/ndk
SYSROOT=$NDK/platforms/android-9/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
function build_one
{
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-avdevice \
--disable-doc \
--disable-symver \
--disable-encoders \
--disable-decoders \
--enable-decoder=h264 \
--enable-decoder=aac \
--disable-protocols \
--disable-demuxers \
--disable-muxers \
--disable-filters \
--disable-network \
--disable-parsers \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=arm \
--enable-asm --enable-yasm \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -marm -march=armv7-a -mfloat-abi=softfp -mfpu=neon" \
--extra-ldflags="-Wl,--fix-cortex-a8" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
}
CPU=armv7-a
PREFIX=$(pwd)/android/$CPU
build_on