webrtc_codecs_file (webrtc_codecs v0.1.0)

View Source

Read and write the two simple media files tests use: IVF, a list of encoded video frames (VP8, VP9, AV1), and WAV, 16 bit PCM audio.

{ok, #{fourcc := <<"VP80">>, frames := Frames}} = webrtc_codecs_file:read_ivf("clip.ivf"),
ok = webrtc_codecs_file:write_wav("out.wav", Audio).

For other containers (MP4, WebM, Matroska) go through FFmpeg: webrtc_codecs_capture reads a file as raw media and webrtc_codecs_playback writes raw media to one.

Summary

Types

fourcc names the codec: <<"VP80">>, <<"VP90">> or <<"AV01">>. time_base is the duration of one timestamp unit as {Numerator, Denominator} seconds: {1, 90000} makes the timestamps RTP timestamps.

Functions

Read an IVF file: its header and its frames, each with its timestamp in units of the time base.

The same, with options: max_bytes, the largest file to read, default 256 MB. A larger one gives {error, too_large}.

Read a WAV file of 16 bit PCM as one webrtc_codecs:audio/0.

The same, with options: max_bytes, the largest file to read, default 256 MB. A larger one gives {error, too_large}.

Write frames to an IVF file. The frames are those a video plugin's encode/2 gives: with the default time base of {1, 90000} their RTP timestamps are written as they are.

Write audio, one map or several of the same format in order, to a WAV file of 16 bit PCM.

Types

ivf()

-type ivf() ::
          #{fourcc := <<_:32>>,
            width := non_neg_integer(),
            height := non_neg_integer(),
            time_base => {pos_integer(), pos_integer()},
            frames => [ivf_frame()]}.

fourcc names the codec: <<"VP80">>, <<"VP90">> or <<"AV01">>. time_base is the duration of one timestamp unit as {Numerator, Denominator} seconds: {1, 90000} makes the timestamps RTP timestamps.

ivf_frame()

-type ivf_frame() :: #{data := binary(), timestamp := non_neg_integer(), atom() => term()}.

Functions

read_ivf(Path)

-spec read_ivf(file:filename_all()) -> {ok, ivf()} | {error, term()}.

Read an IVF file: its header and its frames, each with its timestamp in units of the time base.

read_ivf(Path, Opts)

-spec read_ivf(file:filename_all(), #{max_bytes => pos_integer()}) -> {ok, ivf()} | {error, term()}.

The same, with options: max_bytes, the largest file to read, default 256 MB. A larger one gives {error, too_large}.

read_wav(Path)

-spec read_wav(file:filename_all()) -> {ok, webrtc_codecs:audio()} | {error, term()}.

Read a WAV file of 16 bit PCM as one webrtc_codecs:audio/0.

read_wav(Path, Opts)

-spec read_wav(file:filename_all(), #{max_bytes => pos_integer()}) ->
                  {ok, webrtc_codecs:audio()} | {error, term()}.

The same, with options: max_bytes, the largest file to read, default 256 MB. A larger one gives {error, too_large}.

write_ivf/3

-spec write_ivf(file:filename_all(), ivf(), [ivf_frame()]) -> ok | {error, term()}.

Write frames to an IVF file. The frames are those a video plugin's encode/2 gives: with the default time base of {1, 90000} their RTP timestamps are written as they are.

write_wav/2

-spec write_wav(file:filename_all(), webrtc_codecs:audio() | [webrtc_codecs:audio()]) ->
                   ok | {error, term()}.

Write audio, one map or several of the same format in order, to a WAV file of 16 bit PCM.