这个问题可能是由于 Apple M1 CPU 产生的 H264 流的配置参数不兼容于一些设备。为了解决这个问题,我们可以尝试在编码 H264 流之前设置一些参数,使其在更多设备上可播放。
以下是使用 FFmpeg 库来设置编码参数的示例代码:
AVCodec* codec = avcodec_find_encoder(AV_CODEC_ID_H264);
AVCodecContext* codecCtx = avcodec_alloc_context3(codec);
AVDictionary* dict = NULL;
// 设置一些编码参数
av_dict_set(&dict, "profile", "high", 0);
av_dict_set(&dict, "bf", "0", 0);
av_dict_set(&dict, "refs", "1", 0);
av_dict_set(&dict, "level", "41", 0);
// 打开编码器
avcodec_open2(codecCtx, codec, &dict);
// 编码 H264 流
// ...
在上述代码中,我们设置了一些编码参数,如 "profile"、"bf"、"refs" 和 "level",这些参数可以控制 H264 流的兼容性。在 avcodec_open2
函数中,使用这些参数打开编码器。
这个解决方法可能需要针对具体的编码需求进行调整。如果需要更详细的设置,请参考 FFmpeg 的文档。