How to decode VP8 streams packed with RTP ?

520 views
Skip to first unread message

AgateLee

unread,
Apr 16, 2015, 5:44:54 AM4/16/15
to webm-d...@webmproject.org
Hello everyone!

I'm a college student and nowadays I'm trying to decode VP8 streams packed with RTP. The problem is that I'm asked to just decode the received RTP packets and transcode them to H264 frame by frame. I use ffmpeg to do that but examples I can find are almost about directly transcoding the rtp packets.

Here is the task :
We start with a file recording rtp packets. Each packet is added a 4-byte head discribing its length.For example :
b501 0000 80e0 00d4 784b 5158 b44e 8270
9080 0090 2300 9d01 2a60 0120 0100 ... ...
The first 4 bytes b501 0000 means the first packet's length is b501 0000 in hex ( 437 in dec), then 80e0 and the next 10 bytes are RTP head , and 9080  is the head of VP8 RTP stream, 9d01 is the real start of VP8 stream. 
I need to read this file and decode the VP8 streams.

I'm not familiar with media and just start learning ffmpeg. So the following steps are on my guess and I'm not sure if they are right.

When I get a RTP packet from the file:
(1)rtp_ctx = ff_rtp_parse_open( if_ctx, in_stream, 96,10 )
 First I use rtp_ctx = ff_rtp_parse_open( if_ctx, in_stream, 96,10 ) to init a RTPDemuxContext. Because the packet is from a file ,not normal RTP's way, the if_ctx is created manually. I use avformat_alloc_context() to init if_ctx and set the input code AV_CODEC_ID_VP8.
The in_stream is also manually added. Payload is set as 96.

(2)vp8_init_dynamic_handler(&ff_dynamic_handler);
     ff_rtp_parse_set_dynamic_protocol(rtp_ctx, payload,&ff_dynamic_handler);
     ret = ff_rtp_parse_packet(  rtp_ctx, &ipkt,&cur_ptr, len);
     I changed ffmpeg's code to let RTPDemuxContext rtp_ctx match VP8, and use it to decode the RTP packet.Then I guess I get the VP8 streams in ipkt.data.

(3)av_parser_parse2(pCodecParserCtx, ic_ctx, & mpkt.data, & mpkt.size, cur_ptr, cur_size,
AV_NOPTS_VALUE, AV_NOPTS_VALUE,AV_NOPTS_VALUE);
     I use av_parser_parse2 to receive enough packets to decode a frame.Then use avcodec_decode_video2(ic_ctx, iframe, &got_frame, & mpkt) and avcodec_encode_video2(oc_ctx, &opkt, mframe, &got_out) to transcode it to H264.
    But when I play the encoded H264 file, it seems not good.Pictures are mixed. ( Before this I tried to use H264 RTP packets as input file and decode it to H264 ,too. And the output file is as good as input file.)
    I guess there may be something wrong with pts and bts in step (3). In fact I don't know how to fill the last 3 parameters of av_parser_parser2(). In step (2) I find the ipkt has pts and dts but no pos(always -1 and nowhere change pos), and even I let mpkt.pts = ipkt.pts, mpkt.dts = ipkt.dts, the result seems the same.
     
    I guess the problem is not set right pts,bts and other parameters, but I don't know how to deal with it. Or there is somewhere else wrong ? Thanks for your help.

Ps: the attachment material.mp4 is the original movie and the out_enc.h264 is after my transcoding.



material.mp4
out_enc.h264

wma...@gmail.com

unread,
Oct 8, 2015, 1:31:03 PM10/8/15
to WebM Discussion
Hi agate, 
Did you succeed ? If so can you describe the process or past a bit of code ? 
Thanks a lot !! 
Will

AgateLee

unread,
Dec 22, 2015, 9:29:55 PM12/22/15
to WebM Discussion, wma...@gmail.com

I read ffmpeg‘s source code, especially rtpdec.c, rtpdec_vp8.c  in libavformat and read_frame.c,then pick some functions from them, do some change to get out of ffmpeg's limit. Then initial params manually to use function ff_rtp_parse_packet, then get VP8 data without RTP header.


在 2015年10月9日星期五 UTC+8上午1:31:03,wma...@gmail.com写道:

Dane Toh

unread,
Jul 11, 2024, 1:10:10 PM (9 days ago) Jul 11
to WebM Discussion, AgateLee, wma...@gmail.com
Hi,

I have the same problem. Can you advise how to solve it? Do you have a ready solution i can use?
Would appreciate if you can share with me and send to daned...@yahoo.com.sg.
Many thanks.

Dane
Reply all
Reply to author
Forward
0 new messages