简体   繁体   English

如何在 MediaCodec 中为 h264 创建编解码器特定数据 ( csd )?

[英]how to create Codec specific Data ( csd ) for h264 in MediaCodec?

Hi i have android project that i have to receive audio and video from server via socket, the audio part run perfect.嗨,我有 android 项目,我必须通过套接字从服务器接收音频和视频,音频部分运行完美。 but the video part is not working i do not know what the reason because the decoder did not show any error when decoding video packets .但是视频部分不起作用我不知道是什么原因,因为解码器在解码视频数据包时没有显示任何错误。 the video codec that i use is H.264/AVC from ffmepeg encoder with the following settings :-我使用的视频编解码器是来自 ffmepeg 编码器的 H.264/AVC,具有以下设置:-

tune = zerolatency调整 = 零延迟

profile = baseline配置文件 = 基线

level = 3等级 = 3

Width = 320宽度 = 320

Height = 240高度 = 240

frameRate = 30帧率 = 30

GOPSize = 30 GOPSize = 30

i found that i have to add CSD-0 and CSD-1 to MediaCodec config but i do not know how to add H.264 SPS/PPS data to the configurations我发现我必须将 CSD-0 和 CSD-1 添加到 MediaCodec 配置中,但我不知道如何将 H.264 SPS/PPS 数据添加到配置中

this is code i was found , but it's not wokring with me ,这是我找到的代码,但它不适合我,

byte[] header_sps = { 0, 0, 0, 1, 103, 100, 0, 40, -84, 52, -59, 1, -32, 17, 31, 120, 11, 80, 16, 16, 31, 0, 0, 3, 3, -23, 0, 0, -22, 96, -108 };
byte[] header_pps = { 0, 0, 0, 1, 104, -18, 60, -128 };

MediaFormat videoFormat = MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC , 320 , 240 );
videoFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE  , 100000);
videoFormat.setByteBuffer("csd-0", ByteBuffer.wrap(header_sps));
videoFormat.setByteBuffer("csd-1", ByteBuffer.wrap(header_pps));

MediaCodec videoDecoder = MediaCodec.createDecoderByType(MediaFormat.MIMETYPE_VIDEO_AVC);
videoDecoder.configure(videoFormat , surface , null , 0);
videoDecoder.start();

if some one know what the correct way to decode H.264 in this case this will be helpfull如果有人知道在这种情况下解码 H.264 的正确方法,这将有所帮助

You need to use the correct sps/pps from the video, not a random hard coded one.您需要使用视频中正确的 sps/pps,而不是随机的硬编码。 You can obtain it by parsing the bitstream.您可以通过解析比特流来获取它。 See this: Possible Locations for Sequence/Picture Parameter Set(s) for H.264 Stream请参阅: H.264 流的序列/图片参数集的可能位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM