How to write VP8 video packets to a webm file

361 views
Skip to first unread message

Austin Einter

unread,
Jan 12, 2018, 1:19:01 AM1/12/18
to discuss...@googlegroups.com
I have a c/c++ based application.
From my application, I am making webrtc call to chrome.
After the call establishment, RTP/VP8 packets from chrome is received in my application.
I need to write the VP8 data to a webm file.
This webm file I should be able to play using any player like ffplay or avplay etc.

I am using libwebm for writing VP8 data to webm file.
Basically I am doing initialization of writer, segment objects (of libwebm), write vp8 data (AddFrame) and at last segment finalize (segment.Finalize()).

For writing vp8 data, I am using AddFrame API.
Now my question is, should I call AddFrame after receiving each RTP packet. From each RTP packet, I can extract VP8 data and call AddFrame.   

OR

I need to concatenate data of few RTP packets and then write data by calling   AddFrame.
If this is the case, what is the logic to know how many RTP packets VP8 data should be concatenated and then AddFrame should be called.

Any hint highly appreciated.

Thanks
Austin

James Zern

unread,
Jan 12, 2018, 3:10:06 AM1/12/18
to WebM Discussion, discuss...@googlegroups.com
+discuss-webrtc (once more after joining)
> --
> 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
> https://groups.google.com/a/webmproject.org/group/webm-discuss/.
> For more options, visit
> https://groups.google.com/a/webmproject.org/d/optout.

Sergio Garcia Murillo

unread,
Jan 12, 2018, 3:46:11 AM1/12/18
to discuss...@googlegroups.com
Just remove the vp8 payload description from the rtp payload and
concatenate the rest of the payload to create a vp8 frame, then add it
to the webm.

Best regards
Sergio

austin...@gmail.com

unread,
Jan 16, 2018, 5:32:26 AM1/16/18
to discuss-webrtc
Dear Serigo
I have done same thing.
I have removed vp8 descriptor, vp8 header and writing to webm file.

I am doing something wrong in passing timestamp to AddFrame api.
I have taken timecodescale as 1000000 and setting it as below.

uint64_t kTimecodeScale = 1000000;
mkvmuxer::SegmentInfo *const info = segment->GetSegmentInfo();
info->set_timecode_scale(kTimecodeScale);

Next I take all the packets having same timestamp (in sequence) and remove descriptor and header, concatenate and pass resultant buffer to AddFrame. I am not sure, how do I calculate the timestamp, that I need to pass to AddFrame. I am using below logic to calculate timestamp.

VP8 sampling rate is 90kHz
1 unit in timestamp = 1/90,000 second = 1/90 millsec = (1/90) * 1000 * 1000 nano sec = (1/9) * 1000,00 ns
timens = (rtp packet timestamp / 9 ) * 1000,00

I pass this timens as timestamp to AddFrame api. The webm video file is written, but only for 4.29 seconds. Even I can see video file size is less. However if I pass smaller timens (say 1/10th ), it is writing complete video file,  but when I play, it plays at fast forward rate.

How do I correct it, please help.

Thanks
Austin

Lorenzo Miniero

unread,
Jan 16, 2018, 7:00:29 AM1/16/18
to discuss-webrtc
We do this in Janus as that's how we support recordings for VP8 streams (dump the RTP packets and then depacketize the payload to a webm), you can have a look at our source code here as a reference: https://github.com/meetecho/janus-gateway/blob/master/postprocessing/pp-webm.c

L.

Eric Davies

unread,
Jan 16, 2018, 1:53:46 PM1/16/18
to discuss-webrtc
Have you checked to see if your video playing program is respecting the timestamps on the individual frames? Possibly it is assuming the frames have constant spacing?

austin...@gmail.com

unread,
Jan 16, 2018, 9:00:45 PM1/16/18
to discuss-webrtc
I am using avplay , ffplay to play the output webm file, and I hope these players can play with variable spacing. 

Something wrong with timestamp I pass to AddFrame api. If I put higher value for timestamp, the output webm file size is less and plays properly for around 4 second. If I put less value for timestamp I get proper size output webm file, but it plays like fast forward.

Best Regards,
Austin

austin...@gmail.com

unread,
Jan 17, 2018, 11:59:05 AM1/17/18
to discuss-webrtc

I debugged it further.
Looks AddFrame is failing to write.

Timecodescale is 1000,000. RTP packet timestamps starting from 0. I concatenate few packets (with same timestamps as well as marker bit set to 1 for last packet in a vp8 frame) after removing vp8 descriptor and header if present.

After adding 198 packets, when I am trying to add next packets Segment::AddFrame is failing. 


Here I am adding only video packets (no audio) to output file.
Can that cause this failure?

Thanks
Austin
Reply all
Reply to author
Forward
0 new messages