webrtc_codecs_vpx (webrtc_codecs v0.1.0)

View Source

VP8 and VP9 codec plugin, on libvpx.

webrtc:add_transceiver(Pc, video, #{frames => true, codec_plugin => {webrtc_codecs_vpx, #{}}}).

decode/2 gives one webrtc_codecs:picture/0 per frame shown, with the RTP timestamp of the frame. After a frame it cannot decode it drops frames until the next key frame.

encode/2 takes webrtc_codecs:picture/0 and encodes in real time at a constant bitrate. It follows bitrate (bits per second) and makes a key frame for keyframe => true. Pictures of another size start a new stream with a key frame.

VP9 is profile 0 only: 8 bit 4:2:0.

Options:

  • bitrate: of the encoder at start, default from the picture size
  • min_bitrate, max_bitrate: bounds for the bitrate, default 30000 and none
  • keyframe_interval: most frames between two key frames, default 3000
  • threads: of the encoder, default from the picture size and the number of schedulers, and of the decoder, default 1
  • cpu_used: libvpx speed setting, default -6 for VP8 and 7 for VP9
  • max_pixels: largest picture the decoder accepts, default 3840 x 2160

Summary

Functions

The size a frame declares, read from its header without decoding it: {key, Width, Height} for a key frame, {inter, Width, Height} for another frame that sets its size, inter for one that takes the size of a frame before it.

The frames of a VP9 superframe (VP9 bitstream annex B): none when the data has no superframe index, error when it has one that does not fit the data. The index is at the end: a marker byte 110 with the number of bytes per size and the number of frames, the sizes, and the marker again.

Functions

frame_size/2

-spec frame_size(vp8 | vp9, binary()) ->
                    {key | inter, pos_integer(), pos_integer()} |
                    inter |
                    {error, invalid_frame | unsupported_profile}.

The size a frame declares, read from its header without decoding it: {key, Width, Height} for a key frame, {inter, Width, Height} for another frame that sets its size, inter for one that takes the size of a frame before it.

superframe/1

-spec superframe(binary()) -> {ok, [binary()]} | none | error.

The frames of a VP9 superframe (VP9 bitstream annex B): none when the data has no superframe index, error when it has one that does not fit the data. The index is at the end: a marker byte 110 with the number of bytes per size and the number of frames, the sizes, and the marker again.