A video transcoding plugin for NetComposer
- MP4 to MP4
- AVI to MP4
- FLV to MP4
- AAC to MP3
There are two main functions offered by this plugin:
parse_transcoder/3
returns a video transcoder configurationtranscode/3
performs an actual video transcoding, using a transcoder.
A transcoder describes what kind of underlying implementation or provider will be used to perform actual video conversion. As an example, nktranscoder_netscale_ffmpeg
supports the following syntax:
Processor = #{ class => ffmpeg,
config => #{ host => <<"...">>,
port => <<"...">>,
path => <<"...">>,
scheme => transcoder,
user => <<"...">>,
password => <<"...">> }}
where:
user
andpassword
are required only for HTTP basic authentication.scheme
is set totranscoder
by default. This implementation relies on NkPACKET's websocket client using thetranscoder://
protocol.
A request for a new transcoding looks like this:
Req => #{ callback => {M, F, A},
input => #{ type => <<"s3">>,
path => InputFileId,
content_type => <<"video/avi">> },
output => #{ type => <<"s3">>,
path => OutputFileId,
content_type => <<"video/mp4">> }
},
{ok, Pid} = nktranscoder:transcode(SrvId, Transcoder, Req).
where:
InputFileId
is the id of the input file, to be read from Netcomposer's S3 file store.OutputFileId
is the file id for the result from the the transcoding process, to be written to Netcomposer's S3 file store.Pid
is the Erlang process that owns the transcoding process.
In the above example, callback
is an Erlang module (M), function (F) and arguments (A) tuple where to notify transcodings events to. The specified list of arguments will be merged with the event data (Status, Pid and ExtraInfo), received from the transcoder provider. This is so that the application code can correlate transcoder events to the appropriate job request.
If for example we call the transcoding with:
Req => #{ callback => { mymodule, transcoding_event, [JobId] },
...
},
{ok, Pid} = nktranscoder:transcode(SrvId, Transcoder, Req).
then we can write a callback module in the form:
-module(mymodule).
-export([transcoding_event/1]).
transcoding_event([ JobId, Status, Pid, ExtraInfo]) ->
io:format("got transcoding event ~p with Pid: ~p, JobId: ~p, Msg: ~p~n",
[Status, Pid, JobId, ExtraInfo]).
where:
Status
is one of:<<"invalid">>
,<<"progress">>
,<<"finished">>
, or<<"error">>
.Pid
is the Erlang process that owns the transcoding process.ExtraInfo
is an Erlang term holding extra info about the transcoding processing.
nktranscoder_netscale_ffmpeg
, based on a custom FFMPEG based microservice with a Websocket api.