gpt4 book ai didi

Android:使用 OMXCodec 作为 MediaSource 时 MPEG4Writer 无法启动

转载 作者:太空宇宙 更新时间:2023-11-03 12:56:46 24 4
gpt4 key购买 nike

我正在尝试对来自字节数组缓冲区的视频进行编码,为此我使用了来自 native 代码的 MPEG4Writer API。

我已经创建了我的自定义 MediaSource 类来提供数据,我用 OMXCodec 包装它以将其提供给 MPEG4Writer:

sp<MediaSource> mVideoEncoder = OMXCodec::Create(client.interface(), omxEncMeta, true, mVideoOutSource);
mVideoEncoder->start();

mVideoOutSource 是我自定义的 MediaSource 类,omxEncMeta 如下:

int32_t colorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
int32_t width = 480;
int32_t height = 360;
int32_t frameRate = 24;
int32_t bitRate = 500 * 1024;
int32_t iFrameInterval = 1;

sp<MetaData> omxEncMeta = new MetaData;
omxEncMeta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
omxEncMeta->setInt32(kKeyColorFormat, colorFormat);
omxEncMeta->setInt32(kKeyWidth, width);
omxEncMeta->setInt32(kKeyHeight, height);
omxEncMeta->setInt32(kKeyStride, width);
omxEncMeta->setInt32(kKeySliceHeight, height);
omxEncMeta->setInt32(kKeyFrameRate, frameRate);
omxEncMeta->setInt32(kKeySampleRate, frameRate);
omxEncMeta->setInt32(kKeyBitRate, bitRate);
omxEncMeta->setInt32(kKeyIFramesInterval, iFrameInterval);

但是当我调用 start() 方法时,它返回错误代码 UNKNOWN_ERROR

相反,如果我尝试直接将我的自定义 MediaSource 提供给 MPEG4Writer(不使用 OMXCodec 包装它,它会成功启动,但最终会停止记录错误 Missing codec specific data(大约 12 帧后),我认为这是因为我的自定义 MediaSource 仅提供有关实际帧的信息,但不提供有关编解码器格式。

我确定我在 OMXCodec 中遗漏了一些东西,但我不知道是什么...有没有人可以为我提供一个自定义 的工作示例MediaSource 用于编码?或者给我一些提示,说明为什么这根本不起作用?
如果您需要更多信息,请询问,谢谢!

编辑:我正在针对 API 14 开发此功能,因此请不要建议我使用 API 16 中的 MediaCodec :)

编辑:这就是我开始MPEG4Writer的方式:

int32_t outputFormat = OUTPUT_FORMAT_MPEG_4;
int64_t startTimeUs = systemTime() / 1000;
int32_t totalBitRate = bitRate;

sp<MetaData> meta = new MetaData;
meta->setInt64(kKeyTime, startTimeUs);
meta->setInt32(kKeyFileType, outputFormat);
meta->setInt32(kKeyBitRate, totalBitRate);

sp<MPEG4Writer> mWriter = new MPEG4Writer("/sdcard/encode_manual.mp4");
mWriter->addSource(mVideoEncoder);
status_t error = mWriter->start(meta.get());
if (error != OK) {
LOGE("Writer NOT started! %x", error);
} else {
LOGI("Writer started!");
}

这是 logcat 的输出(adb logcat OMXClient:V OMXCodec:V *:W):

W/ResourceType(  370): Skipping entry 0x7f04002f in package table 0 because it is not complex!
E/ ( 4127): Can't open file for reading
E/ ( 4127): Can't open file for reading
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): omx_video(): Inside Constructor()
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): omx_venc(): Inside component_init()
E/OMX-VENC-720p( 155): bool venc_dev::venc_validate_profile_level(OMX_U32*, OMX_U32*): Returning with eProfile = 1Level = 4
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): bool venc_dev::venc_open(OMX_U32)(): Init Profile/Level setting success
E/OMX-VENC-720p( 155): vidc.venc.debug.sliceinfo value is 0
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): Component_init return value = 0x0
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): WARNING: Requested i/p bufsize[40960],Driver's updated i/p bufsize = 262144
E/OMX-VENC-720p( 155): bool venc_dev::venc_validate_profile_level(OMX_U32*, OMX_U32*): Returning with eProfile = 1Level = 256
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): bool venc_dev::venc_set_param(void*, OMX_INDEXTYPE)(): Profile/Level setting success
E/OMX-VENC-720p( 155): bool venc_dev::venc_validate_profile_level(OMX_U32*, OMX_U32*): Returning with eProfile = 1Level = 64
E/OMX-VENC-720p( 155): Calling set level (Framerate) with 15
E/OMX-VENC-720p( 155): bool venc_dev::venc_validate_profile_level(OMX_U32*, OMX_U32*): Returning with eProfile = 1Level = 64
E/OMX-VENC-720p( 155): Calling set level (Bitrate) with 15
E/OMX-VENC-720p( 155): get_parameter: OMX_IndexParamVideoProfileLevelQuerySupported for Input port returned Profile:1, Level:2048
E/OMX-VENC-720p( 155): Profile/Level set equal to 1/64
E/OMX-VENC-720p( 155): bool venc_dev::venc_validate_profile_level(OMX_U32*, OMX_U32*): Returning with eProfile = 1Level = 64
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): venc_set_intra_period: nPFrames = 25 nBFrames = 0
E/OMX-VENC-720p( 155): bool venc_dev::venc_validate_profile_level(OMX_U32*, OMX_U32*): Returning with eProfile = 1Level = 64
E/OMX-VENC-720p( 155): Calling set level (Bitrate) with 15
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): allocate_input_buffer()::
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): allocate_input_buffer()::
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): allocate_input_buffer()::
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): allocate_output_buffer()::
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): actual cnt = 5
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): allocate_output_buffer()::
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): actual cnt = 5
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): allocate_output_buffer()::
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): actual cnt = 5
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): allocate_output_buffer()::
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): actual cnt = 5
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): allocate_output_buffer()::
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): actual cnt = 5
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): unsigned int venc_dev::venc_start()(): Check Profile/Level set in driver before start
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): unsigned int venc_dev::venc_start()(): Driver Profile[3]/Level[15] successfully SET
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): ENC_CONFIG: Codec: 2, Profile 3, level : 15
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): ENC_CONFIG: Width: 480, Height:360, Fps: 25
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): ENC_CONFIG: Bitrate: 512000, RC: 3, I-Period: 25
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): ENC_CONFIG: qpI: 0, qpP: 80, qpb: 0
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): ENC_CONFIG: VOP_Resolution: 4343391, Slice-Mode: 1, Slize_Size: 0
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): ENC_CONFIG: EntropyMode: 1, CabacModel: 0
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): ENC_CONFIG: DB-Mode: 2, alpha: 0, Beta: 0
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): ENC_CONFIG: IntraMB/Frame: 18, HEC: 843271745
E/OMX-VENC-720p( 155): Width 480, Height 360, w_round 480, h_round 368, yuv_size 294912 alignment 8192 count 2
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): Allocated virt:0x4432e000, FD: 145 of size 294912
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): Allocated virt:0x4432e000, FD: 145 of size 294912 at index: 0
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): Allocated virt:0x44895000, FD: 147 of size 294912
E/OMX-VENC-720p( 155):
E/OMX-VENC-720p( 155): Allocated virt:0x44895000, FD: 147 of size 294912 at index: 1
E/TestEnc-JNI( 4127): Writer NOT started! 80000000

最佳答案

我刚刚弄清楚我的(愚蠢)问题:我在 mVideoEncoder 上调用 start()(OMXCodec 实例)在 MPEG4Writer 上调用 start() 之前,这会导致 UNKNOWN_ERROR

我通过仅在 MPEG4Writer 实例上调用 start() 解决了问题。

关于Android:使用 OMXCodec 作为 MediaSource 时 MPEG4Writer 无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18744905/

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