List Info

Thread: RFC2190 H.263 encoding




RFC2190 H.263 encoding
country flaguser name
United States
2007-02-14 14:52:39
Hello.

I have been using the patched version of FFMPEG
(0.4.7) to receive RFC2190 video from industry MCUs
and it works great!  I am now working on encoding and
sending an RFC2190 H.263 stream such that it can be
rendered properly by other MCUs or my working FFMPEG
RFC2190 decoder.  Since the MCUs don't render a
picture when sent with my current code, I figured I
should first get the encoder working with my good
decoder.

When my decoder receives the first video frame, I get
the following errors:

illegal ac vlc code at 0x3
Error at MB: 69
illegal ac vlc code at 16x10
Error at MB: 246
concealing errors
Decode GOB header at MB 66, DD6DE4Decode GOB header at
MB 594, DD6DE4Decode GOB header at MB 594, 239BCEGN 4
(0,4), GFID 1, Quant 25Decode GOB header at MB 132,
339BCEGN 6 (0,6), GFID 1, Quant 25Decode GOB header at
MB 198, 4B94F8GN 9 (0,9), GFID 1, Quant 25Decode GOB
header at MB 236, BA5348Decode GOB header at MB 506,
BA5348Decode GOB header at MB 506, BA5348Decode GOB
header at MB 506, 5B9BE9GN 11 (0,11), GFID 1, Quant
25Decode GOB header at MB 286, 6B9BB2GN 13 (0,13),
GFID 1, Quant 25Decode GOB header at MB 352, 839EEFGN
16 (0,16), GFID 1, Quant 25

I have limited debug output in the encoder on to show
what it is putting in the RFC2190 headers for each RTP
packet and it shows the following:

352 176 0 0  ->direct 0copy of input_picture, stride
352 ->352, data B7F6D008 ->B7EE4030newpict type 1hdr
4
(from 89c3210) data 752 (from b7f0b008, sbit 0, ebit
6)
RTP SEQ: 62820
Encode GOB header at MB 88, GN 4 (0,4), GFID 1, GQUANT
25q 25, gobn 3, mba 1, mv0 0:0 (0:0)hdr 8 (from
89c3214) data 754 (from b7f0b2f7, sbit 2, ebit 4)
RTP SEQ: 62821
Encode GOB header at MB 132, GN 6 (0,6), GFID 1,
GQUANT 25q 25, gobn 5, mba 20, mv0 0:0 (0:0)hdr 8
(from 89c321c) data 762 (from b7f0b5e8, sbit 4, ebit
2)
RTP SEQ: 62822
Encode GOB header at MB 198, GN 9 (0,9), GFID 1,
GQUANT 25q 25, gobn 8, mba 11, mv0 0:0 (0:0)hdr 8
(from 89c3224) data 763 (from b7f0b8e1, sbit 6, ebit
7)
RTP SEQ: 62823
Encode GOB header at MB 242, GN 11 (0,11), GFID 1,
GQUANT 25q 25, gobn 10, mba 17, mv0 0:0 (0:0)hdr 8
(from 89c322c) data 766 (from b7f0bbdb, sbit 1, ebit
7)
RTP SEQ: 62824
Encode GOB header at MB 286, GN 13 (0,13), GFID 1,
GQUANT 25hdr 4 (from 89c3234) data 753 (from b7f0bed8,
sbit 1, ebit 1)
RTP SEQ: 62825
Encode GOB header at MB 352, GN 16 (0,16), GFID 1,
GQUANT 25q 25, gobn 15, mba 16, mv0 0:0 (0:0)hdr 8
(from 89c3238) data 561 (from b7f0c1c8, sbit 7, ebit
0)

The RFC2190 header values match perfectly in
wireshark.  I did notice that the first and second to
last frame are both MODE A while the others are MODE
B.  My encoder code is as follows and is intended to
exactly mimic the equivalent code in OpenH323:

void Encoder::RFC2190RtpCallback(void *data, int
data_size, void *hdr, int hdr_size, void *priv_data)
{
	Encoder *me = (Encoder *)priv_data;
	int len = hdr_size + data_size;
	u_int8_t *payload = new u_int8_t[len];

	memcpy(payload, hdr, hdr_size);
	memcpy(payload + hdr_size, data, data_size);
	me->RtpSend(payload, len, len <
me->m_avctx->rtp_payload_size);
}

int main(int argc, char **argv)
{
	AVCodec *m_codec;
	AVCodecContext		*m_avctx;
	AVFrame *m_picture;
	u_int8_t*			m_vopBuffer;
	u_int32_t			m_vopBufferLength;
	int m_key_frame_count = 0;
	int bit_rate = 1472;
	int key_frame_interval;
	int max_vop_size = 128 * 1024;
	float frame_rate = 29.97;
        int width = 352, height = 288;
	int y_size = (width * height);
	int uv_size = (width / 2) * (height /2);
	int image_size = y_size + uv_size * 2;
	u_int8_t *image = new u_int8_t[image_size];
	int num_frames = 0;
        bool rfc2190 = true;

	avcodec_init();
	avcodec_register_all();

    m_codec = avcodec_find_encoder(CODEC_ID_H263);

	if (m_codec == NULL)
	{
		cerr << "Could not find codec" <<
endl;
		exit(1);
	}
  
	m_avctx = avcodec_alloc_context();
	m_picture = avcodec_alloc_frame();
	m_avctx->width = width;
	m_avctx->height = height;
	m_avctx->bit_rate = bit_rate * 1000;
	m_avctx->strict_std_compliance = -1;
	m_avctx->pix_fmt = PIX_FMT_YUV420P;

	m_avctx->rtp_mode = true;
	m_avctx->rtp_payload_size = 750;
    m_key_frame_count = m_avctx->gop_size = (int)
		((frame_rate + 0.5) * key_frame_interval);
    m_avctx->flags |= CODEC_FLAG_GLOBAL_HEADER;

	if (rfc2190)
	{
		m_avctx->flags |= CODEC_FLAG_INPUT_PRESERVED;
		m_avctx->flags |= CODEC_FLAG_EMU_EDGE; // don't draw
edges
		m_avctx->flags &= ~CODEC_FLAG_H263P_UMV;
		m_avctx->flags &= ~CODEC_FLAG_H263P_AIC;
		m_avctx->flags |= CODEC_FLAG_RFC2190;
		m_avctx->rtp_callback = RFC2190RtpCallback;
		m_avctx->opaque = this;
	}

	if (avcodec_open(m_avctx, m_codec) < 0) 
	{
		cerr << "Could not open codec" <<
endl;
		exit(2);
	}

	u_int8_t *pY = image;
	u_int8_t *pU = pY + y_size;
	u_int8_t *pV = pU + uv_size;

	m_picture->data[0] = (uint8_t *)pY;
	m_picture->data[1] = (uint8_t *)pU;
	m_picture->data[2] = (uint8_t *)pV;
	m_picture->linesize[0] = width;
	m_picture->linesize[1] = width / 2;
	m_picture->linesize[2] = width / 2;
	m_picture->pts = 0;

	m_vopBuffer = (u_int8_t*)malloc(max_vop_size);

        while (true)
        {
              // get YUV into m_picture->data

              int enc_size =
avcodec_encode_video(m_avctx, m_vopBuffer,
max_vop_size, m_picture);

                // write each H263 frame to file
		fwrite(m_vopBuffer, 1, enc_size, m_outfile);
		fflush(m_outfile);
         }

When I run the encoder to stop after one frame, I
always get the same errors on the decoder (as above). 
The H263 file I write has a good frame in it and the
sniff corresponds to what the encoder claims to be
putting in the headers so I am at a bit of a loss. 
I'm hoping someone might be able to shed some light on
this.  I have attached the raw H263 file the encoder
wrote as well as the single frame sniff.

Regards
  
  
Re: RFC2190 H.263 encoding
country flaguser name
Norway
2007-02-15 05:28:54
Hello,

It looks like the data at the packet boundaries isn't quite
correct.  
I did just a short lookup, however, so I may be wrong.

If you compare the raw H.263 data to the data contained in
the RTP  
packets, you can see that the encoder puts in some zero
bytes at the  
end of the payload. Sometimes, information from the raw
H.263 header  
is lost (between packet 1 and 2).
As you can see from the decoder output, the decoder
encounters  
problems inside the bitstream, not the header.

Hope this helps

Hannes

On 14. Feb 2007, at 21:52, Jon Burford wrote:

> Hello.
>
> I have been using the patched version of FFMPEG
> (0.4.7) to receive RFC2190 video from industry MCUs
> and it works great!  I am now working on encoding and
> sending an RFC2190 H.263 stream such that it can be
> rendered properly by other MCUs or my working FFMPEG
> RFC2190 decoder.  Since the MCUs don't render a
> picture when sent with my current code, I figured I
> should first get the encoder working with my good
> decoder.
>
> When my decoder receives the first video frame, I get
> the following errors:
>
> illegal ac vlc code at 0x3
> Error at MB: 69
> illegal ac vlc code at 16x10
> Error at MB: 246
> concealing errors
> Decode GOB header at MB 66, DD6DE4Decode GOB header at
> MB 594, DD6DE4Decode GOB header at MB 594, 239BCEGN 4
> (0,4), GFID 1, Quant 25Decode GOB header at MB 132,
> 339BCEGN 6 (0,6), GFID 1, Quant 25Decode GOB header at
> MB 198, 4B94F8GN 9 (0,9), GFID 1, Quant 25Decode GOB
> header at MB 236, BA5348Decode GOB header at MB 506,
> BA5348Decode GOB header at MB 506, BA5348Decode GOB
> header at MB 506, 5B9BE9GN 11 (0,11), GFID 1, Quant
> 25Decode GOB header at MB 286, 6B9BB2GN 13 (0,13),
> GFID 1, Quant 25Decode GOB header at MB 352, 839EEFGN
> 16 (0,16), GFID 1, Quant 25
>
> I have limited debug output in the encoder on to show
> what it is putting in the RFC2190 headers for each RTP
> packet and it shows the following:
>
> 352 176 0 0  ->direct 0copy of input_picture,
stride
> 352 ->352, data B7F6D008 ->B7EE4030newpict type
1hdr 4
> (from 89c3210) data 752 (from b7f0b008, sbit 0, ebit
> 6)
> RTP SEQ: 62820
> Encode GOB header at MB 88, GN 4 (0,4), GFID 1, GQUANT
> 25q 25, gobn 3, mba 1, mv0 0:0 (0:0)hdr 8 (from
> 89c3214) data 754 (from b7f0b2f7, sbit 2, ebit 4)
> RTP SEQ: 62821
> Encode GOB header at MB 132, GN 6 (0,6), GFID 1,
> GQUANT 25q 25, gobn 5, mba 20, mv0 0:0 (0:0)hdr 8
> (from 89c321c) data 762 (from b7f0b5e8, sbit 4, ebit
> 2)
> RTP SEQ: 62822
> Encode GOB header at MB 198, GN 9 (0,9), GFID 1,
> GQUANT 25q 25, gobn 8, mba 11, mv0 0:0 (0:0)hdr 8
> (from 89c3224) data 763 (from b7f0b8e1, sbit 6, ebit
> 7)
> RTP SEQ: 62823
> Encode GOB header at MB 242, GN 11 (0,11), GFID 1,
> GQUANT 25q 25, gobn 10, mba 17, mv0 0:0 (0:0)hdr 8
> (from 89c322c) data 766 (from b7f0bbdb, sbit 1, ebit
> 7)
> RTP SEQ: 62824
> Encode GOB header at MB 286, GN 13 (0,13), GFID 1,
> GQUANT 25hdr 4 (from 89c3234) data 753 (from b7f0bed8,
> sbit 1, ebit 1)
> RTP SEQ: 62825
> Encode GOB header at MB 352, GN 16 (0,16), GFID 1,
> GQUANT 25q 25, gobn 15, mba 16, mv0 0:0 (0:0)hdr 8
> (from 89c3238) data 561 (from b7f0c1c8, sbit 7, ebit
> 0)
>
> The RFC2190 header values match perfectly in
> wireshark.  I did notice that the first and second to
> last frame are both MODE A while the others are MODE
> B.  My encoder code is as follows and is intended to
> exactly mimic the equivalent code in OpenH323:
>
> void Encoder::RFC2190RtpCallback(void *data, int
> data_size, void *hdr, int hdr_size, void *priv_data)
> {
> 	Encoder *me = (Encoder *)priv_data;
> 	int len = hdr_size + data_size;
> 	u_int8_t *payload = new u_int8_t[len];
>
> 	memcpy(payload, hdr, hdr_size);
> 	memcpy(payload + hdr_size, data, data_size);
> 	me->RtpSend(payload, len, len <
> me->m_avctx->rtp_payload_size);
> }
>
> int main(int argc, char **argv)
> {
> 	AVCodec *m_codec;
> 	AVCodecContext		*m_avctx;
> 	AVFrame *m_picture;
> 	u_int8_t*			m_vopBuffer;
> 	u_int32_t			m_vopBufferLength;
> 	int m_key_frame_count = 0;
> 	int bit_rate = 1472;
> 	int key_frame_interval;
> 	int max_vop_size = 128 * 1024;
> 	float frame_rate = 29.97;
>         int width = 352, height = 288;
> 	int y_size = (width * height);
> 	int uv_size = (width / 2) * (height /2);
> 	int image_size = y_size + uv_size * 2;
> 	u_int8_t *image = new u_int8_t[image_size];
> 	int num_frames = 0;
>         bool rfc2190 = true;
>
> 	avcodec_init();
> 	avcodec_register_all();
>
>     m_codec = avcodec_find_encoder(CODEC_ID_H263);
>
> 	if (m_codec == NULL)
> 	{
> 		cerr << "Could not find codec"
<< endl;
> 		exit(1);
> 	}
>
> 	m_avctx = avcodec_alloc_context();
> 	m_picture = avcodec_alloc_frame();
> 	m_avctx->width = width;
> 	m_avctx->height = height;
> 	m_avctx->bit_rate = bit_rate * 1000;
> 	m_avctx->strict_std_compliance = -1;
> 	m_avctx->pix_fmt = PIX_FMT_YUV420P;
>
> 	m_avctx->rtp_mode = true;
> 	m_avctx->rtp_payload_size = 750;
>     m_key_frame_count = m_avctx->gop_size = (int)
> 		((frame_rate + 0.5) * key_frame_interval);
>     m_avctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
>
> 	if (rfc2190)
> 	{
> 		m_avctx->flags |= CODEC_FLAG_INPUT_PRESERVED;
> 		m_avctx->flags |= CODEC_FLAG_EMU_EDGE; // don't
draw
> edges
> 		m_avctx->flags &= ~CODEC_FLAG_H263P_UMV;
> 		m_avctx->flags &= ~CODEC_FLAG_H263P_AIC;
> 		m_avctx->flags |= CODEC_FLAG_RFC2190;
> 		m_avctx->rtp_callback = RFC2190RtpCallback;
> 		m_avctx->opaque = this;
> 	}
>
> 	if (avcodec_open(m_avctx, m_codec) < 0)
> 	{
> 		cerr << "Could not open codec"
<< endl;
> 		exit(2);
> 	}
>
> 	u_int8_t *pY = image;
> 	u_int8_t *pU = pY + y_size;
> 	u_int8_t *pV = pU + uv_size;
>
> 	m_picture->data[0] = (uint8_t *)pY;
> 	m_picture->data[1] = (uint8_t *)pU;
> 	m_picture->data[2] = (uint8_t *)pV;
> 	m_picture->linesize[0] = width;
> 	m_picture->linesize[1] = width / 2;
> 	m_picture->linesize[2] = width / 2;
> 	m_picture->pts = 0;
>
> 	m_vopBuffer = (u_int8_t*)malloc(max_vop_size);
>
>         while (true)
>         {
>               // get YUV into m_picture->data
>
>               int enc_size =
> avcodec_encode_video(m_avctx, m_vopBuffer,
> max_vop_size, m_picture);
>
>                 // write each H263 frame to file
> 		fwrite(m_vopBuffer, 1, enc_size, m_outfile);
> 		fflush(m_outfile);
>          }
>
> When I run the encoder to stop after one frame, I
> always get the same errors on the decoder (as above).
> The H263 file I write has a good frame in it and the
> sniff corresponds to what the encoder claims to be
> putting in the headers so I am at a bit of a loss.
> I'm hoping someone might be able to shed some light on
> this.  I have attached the raw H263 file the encoder
> wrote as well as the single frame sniff.
>
> Regards
> <raw.h263>
> <rfc2190.pcap>

------------------------------------------------------------
------------
Check the FAQ before asking! - http://www.
openh323.org/~openh323/fom.cgi
The OpenH323 Project mailing list, using Mailman. To
unsubscribe or
change your subscription options, goto
htt
p://www.openh323.org/mailman/listinfo/openh323
Maintained by Quicknet Technologies, Inc - http://www.quicknet.net
------------------------------------------------------------
------------

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )