gpt4 book ai didi

ios - 指定的样本格式 s16 无效或不受支持

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:46:24 31 4
gpt4 key购买 nike

我正在使用 ffmpeg 将 PCM 数据编码为 AAC 格式:以下是我设置上下文对象的代码:

-(id)encode:(short*)data{
AVCodecContext *audioCodec;
AVCodec *codec;

avcodec_register_all();

//Set up audio encoder
codec = avcodec_find_encoder(AV_CODEC_ID_AAC);
if (codec == NULL){
NSLog(@"no codec");
}
audioCodec = avcodec_alloc_context3(codec);
audioCodec->strict_std_compliance = -2;
audioCodec->bit_rate = 64000;
audioCodec->sample_fmt = AV_SAMPLE_FMT_S16;
audioCodec->sample_rate = 8000;
audioCodec->channels = 2;
audioCodec->profile = FF_PROFILE_AAC_MAIN;
audioCodec->time_base = (AVRational){1, 8000};
audioCodec->codec_type = 1;
if (avcodec_open2(audioCodec, codec, NULL)) {
NSLog(@"could not open codec");

}
return @"NO";
}

我总是收到如下错误日志: aac @ 0x151cda00]指定的样本格式s16无效或不支持

如果我不提供任何示例格式,我会得到相同的日志: aac @ 0x151cda00]指定的样本格式-1无效或不支持

这就是为什么 avcodec_open2() 给出了 could not open codec 的日志;

谁能告诉我这是什么问题?

ffmpeg编译脚本如下:

#!/bin/sh

# directories
SOURCE="ffmpeg"
FAT="fat"
VERSION="2.0.2"

SCRATCH="scratch"
# must be an absolute path
THIN=`pwd`/"thin"

# absolute path to x264 library
#X264=`pwd`/fat_x264

CONFIGURE_FLAGS="--enable-cross-compile \
--disable-network \
--disable-encoders \
--disable-decoders \
--disable-muxers \
--disable-demuxers \
--disable-protocols \
--disable-devices \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-avfilter \
--disable-iconv \
--disable-bzlib \
--disable-mmx \
--disable-mmxext \
--disable-amd3dnow \
--disable-amd3dnowext \
--disable-sse \
--disable-sse2 \
--disable-sse3 \
--disable-sse4 \
--disable-avx \
--disable-fma4 \
--disable-swresample \
--disable-postproc \
--disable-bsfs \
--disable-filters \
--disable-asm \
--disable-yasm \
--disable-debug \
--disable-doc \
--disable-armv5te \
--disable-armv6 \
--disable-armv6t2 \
--enable-protocol=file \
--enable-avformat \
--enable-avcodec \
--enable-swscale \
--enable-demuxer=mp3 \
--enable-demuxer=aac \
--enable-demuxer=image2 \
--enable-demuxer=mov \
--enable-decoder=rawvideo \
--enable-demuxer=h263 \
--enable-demuxer=h264 \
--enable-decoder=mp3 \
--enable-decoder=aac \
--enable-decoder=mjpeg \
--enable-decoder=h263 \
--enable-decoder=h264 \
--enable-decoder=mpeg4 \
--enable-encoder=mp3 \
--enable-encoder=aac \
--enable-encoder=mjpeg \
--enable-encoder=h263 \
--enable-encoder=h264 \
--enable-encoder=mpeg4 \
--enable-parser=mp3 \
--enable-parser=aac \
--enable-parser=h264 \
--enable-pic"

if [ "$X264" ]
then
CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-gpl --enable-libx264"
fi

# avresample
#CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-avresample"

ARCHS="arm64 armv7s armv7 x86_64 i386"

COMPILE="y"
LIPO="y"

DEPLOYMENT_TARGET="6.0"

if [ "$*" ]
then
if [ "$*" = "lipo" ]
then
# skip compile
COMPILE=
else
ARCHS="$*"
if [ $# -eq 1 ]
then
# skip lipo
LIPO=
fi
fi
fi

if [ "$COMPILE" ]
then
CWD=`pwd`
for ARCH in $ARCHS
do
echo "building $ARCH..."
mkdir -p "$SCRATCH/$ARCH"
cd "$SCRATCH/$ARCH"

CFLAGS="-arch $ARCH"
if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]
then
PLATFORM="iPhoneSimulator"
CFLAGS="$CFLAGS -mios-simulator-version-min=$DEPLOYMENT_TARGET"
else
PLATFORM="iPhoneOS"
CFLAGS="$CFLAGS -mios-version-min=$DEPLOYMENT_TARGET"
if [ "$ARCH" = "arm64" ]
then
EXPORT="GASPP_FIX_XCODE5=1"
fi
fi

XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
CC="xcrun -sdk $XCRUN_SDK clang"
CXXFLAGS="$CFLAGS"
LDFLAGS="$CFLAGS"
if [ "$X264" ]
then
CFLAGS="$CFLAGS -I$X264/include"
LDFLAGS="$LDFLAGS -L$X264/lib"
fi

$CWD/$SOURCE/configure \
--target-os=darwin \
--arch=$ARCH \
--cc="$CC" \
$CONFIGURE_FLAGS \
--extra-cflags="$CFLAGS" \
--extra-cxxflags="$CXXFLAGS" \
--extra-ldflags="$LDFLAGS" \
--prefix="$THIN/$ARCH"

make -j3 install $EXPORT
cd $CWD
done
fi

if [ "$LIPO" ]
then
echo "building fat binaries..."
mkdir -p $FAT/lib
set - $ARCHS
CWD=`pwd`
cd $THIN/$1/lib
for LIB in *.a
do
cd $CWD
lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB
done

cd $CWD
cp -rf $THIN/$1/include $FAT
fi

最佳答案

我遇到了类似的问题,因为我不知道我的 Windows Phone 支持什么格式。 (原来是 AV_SAMPLE_FMT_FLTP )

我最终查看了 avcodec_open2 源代码 ( https://www.ffmpeg.org/doxygen/2.1/libavcodec_2utils_8c_source.html )

并发现它正在引用编解码器以查看支持哪些样本。

考虑到这一点,您可以这样做:audioCodec->sample_fmt = audioCodec->codec->sample_fmts[0];

关于ios - 指定的样本格式 s16 无效或不受支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22989838/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com