上下文:我有一个名为 libffmpeg.so 的文件,我从APK
一个Android
应用程序中获取该文件,该应用程序用于FFMPEG
在多个Codecs
. 因此,我认为这是使用编码选项启用编译的,并且这个 .so 文件在某处包含所有编解码器。ARM
这个文件是为(我们称之为ARMEABI
profile on 的)编译的Android
。
我也有一个非常完整的类,其中包含可以调用API
的互操作ffmpeg
。无论 this 的起源是什么static library
,所有呼叫响应都很好,并且大多数端点都存在。如果不是,我添加它们或修复已弃用的一个。
当我想创建一个ffmpeg
Encoder
时,返回的编码器是正确的。
var thisIsSuccessful = avcodec_find_encoder(myAVCodec.id);
现在,我有一个问题Codecs
。问题是——假设出于好奇——我遍历所有编解码器的列表,看看我可以使用 avcodec_open 调用打开哪个编解码器......
AVCodec codec;
var res = FFmpeg.av_codec_next(&codec);
while((res = FFmpeg.av_codec_next(res)) != null)
{
var name = res->longname;
AVCodec* encoder = FFmpeg.avcodec_find_encoder(res->id);
if (encoder != null) {
AVCodecContext c = new AVCodecContext ();
/* put sample parameters */
c.bit_rate = 64000;
c.sample_rate = 22050;
c.channels = 1;
if (FFmpeg.avcodec_open (ref c, encoder) >= 0) {
System.Diagnostics.Debug.WriteLine ("[YES] - " + name);
}
} else {
System.Diagnostics.Debug.WriteLine ("[NO ] - " + name);
}
}
...然后只有未压缩的编解码器在工作。(YUV、FFmpeg 视频 1 等)
我的假设是:
- 编译为 .so 文件时缺少的选项
- av_open_codec 调用取决于我在调用中引用的 AVCodecContext 的属性。
我真的很好奇为什么只返回一组最小的未压缩编解码器?
[编辑]
@ronald-s-bultje 的回答让我阅读了 AVCodecContext API 描述,当在编码器上使用时,有很多带有“必须由用户设置”的补充文件。为这些参数设置一个值可以AVCodecContext
使大多数漂亮的编解码器可用:
c.time_base = new AVRational (); // Output framerate. Here, 30fps
c.time_base.num = 1;
c.time_base.den = 30;
c.me_method = 1; // Motion-estimation mode on compression -> 1 is none
c.width = 640; // Source width
c.height = 480; // Source height
c.gop_size = 30; // Used by h264. Just here for test purposes.
c.bit_rate = c.width * c.height * 4; // Randomly set to that...
c.pix_fmt = FFmpegSharp.Interop.Util.PixelFormat.PIX_FMT_YUV420P; // Source pixel format