这里是我的问题, 我已经实现用Red5的服务器端应用程序,它发送H.264编码的直播流,客户端上的流被接收作为字节[]
为了它在Android客户端解码我按照Javacv-FFmpeg的库。用于解码的代码如下从服务器接收Javacv:解码H.264“活”流从RED5服务器未来的Android设备上
public Frame decodeVideo(byte[] data,long timestamp){
frame.image = null;
frame.samples = null;
avcodec.av_init_packet(pkt);
BytePointer video_data = new BytePointer(data);
avcodec.AVCodec codec = avcodec.avcodec_find_decoder(codec_id);
video_c = null;
video_c = avcodec.avcodec_alloc_context3(codec);
video_c.width(320);
video_c.height(240);
video_c.pix_fmt(0);
video_c.flags2(video_c.flags2()|avcodec.CODEC_FLAG2_CHUNKS);
avcodec.avcodec_open2(video_c, codec, null))
picture = avcodec.avcodec_alloc_frame()
pkt.data(video_data);
pkt.size(data.length);
int len = avcodec.avcodec_decode_video2(video_c, picture, got_frame, pkt);
if ((len >= 0) && (got_frame[0] != 0)) {
....
process the decoded frame into **IPLImage of Javacv** and render it with **Imageview** of Android
}
}
数据如下具有
几帧以下图案
17 01 00 00 00 00 00 00 02 09 10 00 00 00 0F 06 00 01 C0 01 07 09 08 04 9A 00 00 03 00 80 00 00 16 65 EF 88 80 07 00 05 6C 98 90 00 ...
许多帧具有以下图案
27 01 00 00 00 00 00 00 02 09 30 00 00 00 0C 06 01 07 09 08 05 9A 00 00 03 00 80 00 00 0D 77 41 9A 02 04 15 B5 06 20 E3 11 E2 3C 46 ....
对于解码器的H.264编解码器,解码器输出长度> 0,但got_frames = 0。
对于MPEG1编解码器,解码器输出长度> 0且got_frames> 0,但输出图像为绿色或失真。
然而以下javacv我可以解码的本地文件的FFmpegFrameGrabber代码(H.264编码)与类似的代码如上。
我不知道细节我很想念,又适合解码器头相关的数据操作或设定编解码器。
任何建议,帮助表示赞赏。
在此先感谢。