Jerikc XIONG
Jerikc XIONG

Reputation: 3617

How to set the Android MediaCodec profile?

I am try to set the profile, such as:

MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline

The code snippet like this:

MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, config.getWidth(), config.getHeight());
format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
        MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_BIT_RATE, config.getBitrate());
format.setInteger(MediaFormat.KEY_FRAME_RATE, config.getHumanFPS());
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, config.getIFrameInterval());
format.setInteger(MediaFormat.KEY_PROFILE, MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline);

mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);

But I got the following error:

07-24 08:05:54.981 I/OMX-VENC(  298): Component_init : OMX.qcom.video.encoder.avc : return = 0x0
07-24 08:05:54.989 E/OMX-VENC(  298): set_parameter: metamode is valid for input port only
07-24 08:05:54.989 E/OMXNodeInstance(  298): OMX_SetParameter() failed for StoreMetaDataInBuffers: 0x8000101a
07-24 08:05:54.992 E/ACodec  ( 8612): [OMX.qcom.video.encoder.avc] storeMetaDataInBuffers (output) failed w/ err -2147483648
07-24 08:05:54.994 W/ACodec  ( 8612): do not know color format 0x7fa30c04 = 2141391876
07-24 08:05:54.994 W/ACodec  ( 8612): do not know color format 0x7f000789 = 2130708361
07-24 08:05:54.997 D/FFmpegMuxer( 8612): RECEIVED AUDIO DATA NOT ALL TRACKS ADDED
07-24 08:05:55.005 I/art     (  810): Explicit concurrent mark sweep GC freed 21609(1113KB) AllocSpace objects, 2(32KB) LOS objects, 39% free, 18MB/30MB, paused 2.045ms total 137.471ms
07-24 08:05:55.012 I/ACodec  ( 8612): [OMX.qcom.video.encoder.avc] setupVideoEncoder failed
07-24 08:05:55.012 E/ACodec  ( 8612): [OMX.qcom.video.encoder.avc] configureCodec returning error -38
07-24 08:05:55.012 E/ACodec  ( 8612): signalError(omxError 0x80001001, internalError -2147483648)
07-24 08:05:55.013 E/MediaCodec( 8612): Codec reported err 0x80001001, actionCode 0, while in state 3 
07-24 08:05:55.013 E/MediaCodec( 8612): configure failed with err 0x80001001, resetting...
07-24 08:05:55.014 I/OMX-VENC(  298): Component Deinit
07-24 08:05:55.016 I/OMXClient( 8612): Using client-side OMX mux. 
07-24 08:05:55.023 I/OMX-VENC(  298): Component_init : OMX.qcom.video.encoder.avc : return = 0x0
--------- beginning of crash
07-24 08:05:55.028 E/AndroidRuntime( 8612): FATAL EXCEPTION: TextureMovieEncoder
07-24 08:05:55.028 E/AndroidRuntime( 8612): Process: com.camera.demo, PID: 8612
07-24 08:05:55.028 E/AndroidRuntime( 8612): android.media.MediaCodec$CodecException: Error 0x80001001
07-24 08:05:55.028 E/AndroidRuntime( 8612):     at android.media.MediaCodec.native_configure(Native Method)
07-24 08:05:55.028 E/AndroidRuntime( 8612):     at android.media.MediaCodec.configure(MediaCodec.java:577)

Where did i miss?

Upvotes: 0

Views: 7338

Answers (1)

mstorsjo
mstorsjo

Reputation: 13317

If you set the profile, you may need to set the level as well - have a look at setupAVCEncoderParameters in https://android.googlesource.com/platform/frameworks/av/+/6ade04174/media/libstagefright/ACodec.cpp. See https://stackoverflow.com/a/26293422/3115956 for a similar answer and an explanation on how to pick a value to set as level.

Upvotes: 1

Related Questions