webrtc_codecs_file (webrtc_codecs v0.1.0)
View SourceRead 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
-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.
-type ivf_frame() :: #{data := binary(), timestamp := non_neg_integer(), atom() => term()}.
Functions
-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.
-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}.
-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.
-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}.
-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.
-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.