Re: how can i decode vp8 stream

684 views
Skip to first unread message

Johann Koenig

unread,
May 10, 2013, 2:28:56 PM5/10/13
to webm-d...@webmproject.org
On Fri, May 10, 2013 at 12:48 AM, <heifr...@gmail.com> wrote:
> So when i want to decode a frame of video, i have to feed ffmpeg exactly a
> piece of frame,
> but i don't know how i can get the frame size according to the stream.i have
> also read CHAPTER 9 in rfc 6386 which is the rfc of vp8,
> but i still don't know how to parse it and get the frame size.

The frame size is typically given by the container. How is the data
being transported?

Yang Song

unread,
May 11, 2013, 2:48:13 AM5/11/13
to webm-d...@webmproject.org
Thank you very much for replying.
My task is to transform between vp8 live stream and h263 live stream, so i just make a test. I drew the video stream from a webm file in order to simulate vp8 stream. And i put the stream i get from file in a new file called mystream.vp8. I want to decode mystream.vp8. Now i get stuck because i don't know how to do.
Can't i get frame size just according to stream file(without container)?
Any advice will be helpful to me.Thank you. 

在 2013年5月11日星期六UTC+8上午2时28分56秒,Johann写道:

Johann Koenig

unread,
May 12, 2013, 11:11:40 PM5/12/13
to webm-d...@webmproject.org
On Fri, May 10, 2013 at 11:48 PM, Yang Song <heifr...@gmail.com> wrote:
> I drew the video stream from a webm file in order to simulate vp8 stream.
> And i put the stream i get from file in a new file called mystream.vp8. I
> want to decode mystream.vp8. Now i get stuck because i don't know how to do.
> Can't i get frame size just according to stream file(without container)?

No. The size is not encoded in the bitstream. Since you are creating a
custom "stream," you could put the size of each frame in the stream
yourself.

For example, we used to have "raw" files for testing which were
formatted as follows: 4 byte integer describing the size of the frame,
followed by the frame, followed by a 4 byte integer describing the
size of the next frame, followed by the next frame, etc.

Then your decoder would read the first 4 bytes of the stream and use
that to fill the buffer that it passes to libvpx.

Note that this still does not allow you to jump into the middle of the
stream and start decoding for a number of reasons. You need to marshal
the data somehow.

Yang Song

unread,
May 13, 2013, 6:57:04 AM5/13/13
to webm-d...@webmproject.org
Thanks for you answer.
But the data i got is just vp8 live stream, and i can't add anything at the sender side.
In this condition, how can i decode vp8? Here is the first bytes of vp8 stream that i got.
90 80 A6 B0 30 85 00 9D 01 2A 80 02 E0 01 09 C7
i read the part of vp8 frame header in rfc 6386, i know 9D 01 2A is the begin block of a key frame. And 30 85 00 is of course the frame tag.
but what does the first bytes 90 80 A6 B0 means? Can you give me suggestions?

Any advice can be very helpful to me.
Thank you very much.

在 2013年5月13日星期一UTC+8上午11时11分40秒,Johann写道:

John Koleszar

unread,
May 13, 2013, 11:35:13 AM5/13/13
to WebM Discussion
Those bytes aren't part of the VP8 bitstream. I don't recognize them
off hand. What software is generating this stream? Is it the RTP
encoding defined for VP8, or something custom? Is there other software
that is able to decode this stream?
> --
> You received this message because you are subscribed to the Google Groups
> "WebM Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to webm-discuss...@webmproject.org.
> To post to this group, send email to webm-d...@webmproject.org.
> Visit this group at
> http://groups.google.com/a/webmproject.org/group/webm-discuss/?hl=en.
> For more options, visit
> https://groups.google.com/a/webmproject.org/groups/opt_out.
>
>

Yang Song

unread,
May 14, 2013, 3:28:26 AM5/14/13
to webm-d...@webmproject.org
Sorry, i got the data from another person, he depacketed RTP packet but he forgot to drop the four bytes start code.Now the data seem to be right.
The data is generated by webrtc project. He called a native video api and get the video stream.  
So you mean i can't decode vp8 stream just according to the stream data? 

Thank you for helping me so much.


2013/5/13 John Koleszar <jkol...@google.com>

Yang Song

unread,
May 14, 2013, 3:29:32 AM5/14/13
to webm-d...@webmproject.org
By the way, can i use ffmpeg av_parser_parse2 to solve the problem? I've tryed but failed.


2013/5/13 John Koleszar <jkol...@google.com>

John Koleszar

unread,
May 14, 2013, 12:03:51 PM5/14/13
to WebM Discussion
You'll need to accumulate the length of each frame as part of
depacketization. There's code you can use from WebRTC as a reference.
I haven't traced it though all the way, but the EncodedImage that gets
passed to the decoder has the length in it, so maybe you can see how
that's populated. You can't decode a vp8 frame without its length with
any decoder I'm aware of.

Faraz Khan

unread,
May 14, 2013, 12:57:58 PM5/14/13
to webm-d...@webmproject.org

If you still need help doing this using webrtc rtp code I can definitely help you out. We are using webrtc for rtp packetization and jitter buffering quite successfully.

Yang Song

unread,
May 15, 2013, 4:50:09 AM5/15/13
to webm-d...@webmproject.org
Thanks a lot.
In RFC 6386, i read that vp8 frame header contain three bytes tag, and for keyframe another 7 bytes, for interframe none. It says in frame header tag, it contains 19 bit partition length, which is the first partition lenth. I read more but couldn't find more information about other partitions. I think if i can parse the first partition, then the second... till the last partition, i can accumlate the length of all the partitions and i can get the size of a frame, am i right?
If so, could you tell me how i can get the second partition lenth according to the first partition(or other information), and the third partion lenth according to the second...

It's very nice of you for helping me so much. Thank you!

在 2013年5月15日星期三UTC+8上午12时03分51秒,John Koleszar写道:

chaitanya reddy

unread,
May 15, 2013, 5:04:40 AM5/15/13
to webm-d...@webmproject.org

Dear Yangsong

When the number of partitions is greater than one, offsets are embedded in the bitstream to provide the
decoder direct access to token partitions. Each offset is written in 3 bytes (24 bits). Since the offset to the first
partition is always 0, only the offsets for partitions other than the first partition are encoded in the bitstream.
The partitioned data are consecutive in the bitstream, so offsets can also be used to calculate the data size of
each partition. The following pseudo code illustrates how the size/offset is defined by the three bytes in the
bitstream.

Regards,
Chinna 

John Koleszar

unread,
May 15, 2013, 11:37:54 AM5/15/13
to WebM Discussion
If there are N partitions in a frame, VP8 only stores N-1 lengths in
the bitstream, since the final partition's length can be calculated by
knowing the size of the frame as a whole. It's certainly possible to
decode the frame, and then return the length of the frame decoded so
you could figure out where the next frame starts, but that's not the
way libvpx works today. Really the best way to get this is from the
RTP layer. See the discussion of the Marker Bit[1] in the VP8 RTP
payload description. If you're constrained by the API between your RTP
depacketizer and the decoder, I'd have the depacketizer write the
length of the frame into the bitstream and strip it out in the
decoder, as Johann suggested. Other than that, you're getting into
modifications of the libvpx and its API, which is going to be more a
lot more work.

[1]: http://tools.ietf.org/html/draft-ietf-payload-vp8-08#page-6

Yang Song

unread,
May 16, 2013, 4:26:31 AM5/16/13
to webm-d...@webmproject.org
Thank you so much.
Your words greatly helped me. Now i decided to parse the RTP packet. I didn't know that RTP packet contains so much information before(i'm a stupid guy haha).
Now two things are not clear, or else it's my confusion: 
1. According to http://tools.ietf.org/html/draft-ietf-payload-vp8-08#page-6, the RTP payload may contain 1~5 bytes which is called VP8 payload descriptor, what is that used for? Can't i just ignore them and put the remain part into ffmpeg and start decode? Why on earth does descriptor exist?
2. If i want to packet a video stream to send, should i fill in the bytes myself or RTP will do it itself? I don't know much about RTP, so maybe this is a stupid question. If it is my duty, how can i know that much parameters?

在 2013年5月15日星期三UTC+8下午11时37分54秒,John Koleszar写道:

Yang Song

unread,
May 17, 2013, 4:30:11 AM5/17/13
to webm-d...@webmproject.org
Hi, i want to parse RTP packet for VP8 in my project. Could you provide me some help? I will be quite grateful. Thank you.

在 2013年5月15日星期三UTC+8上午12时57分58秒,Faraz Khan写道:

Faraz Khan

unread,
May 18, 2013, 12:54:24 AM5/18/13
to webm-d...@webmproject.org
Yang,
One simple way (the way I did it) was to simply get the webrtc trunk source and look for the rtp_rtcp_impl.cc file - There is a 'IncomingPacket' function - track it down!

Also - In the same file there is SendOutgoingData which makes calls to a RTPBuildHeader function. Might be simpler to just look at already implemented code to figure this out.

Ps. You can also use these two functions to RTP(ize) and de-rtpize the stream. Thats how I'm using these webrtc functions.


--
Faraz Khan
Simple Collaboration Screensharing

Yang Song

unread,
May 19, 2013, 8:22:49 AM5/19/13
to webm-d...@webmproject.org
Thank you very much, I'm working in your way.
Thanks again!

在 2013年5月18日星期六UTC+8下午12时54分24秒,Faraz Khan写道:
Reply all
Reply to author
Forward
0 new messages