How to configure output socket for MP3 encoding in .NET#
Here is a quick snippet for configuring the output socket of a Transcoder for MP3 encoding using C#.
Diagram#
Code#
This is the code for the output socket:
static MediaSocket CreateOutputSocket(Options opt)
{
AudioStreamInfo asi = new AudioStreamInfo();
asi.StreamType = StreamType.MpegAudio;
asi.StreamSubType = StreamSubType.MpegAudioLayer3;
// The default bitrate is 128000. You can set it to 192000, 256000, etc.
// asi.Bitrate = 192000;
// You can change the sampling rate and the number of the channels
// asi.SampleRate = 44100;
// asi.Channels = 1;
MediaPin pin = new MediaPin();
pin.StreamInfo = asi;
MediaSocket socket = new MediaSocket();
socket.StreamType = StreamType.MpegAudio;
socket.StreamSubType = StreamSubType.MpegAudioLayer3;
socket.Pins.Add(pin);
// output to a file
socket.File = opt.OutputFile;
return socket;
}
The complete program is available on GitHub:
Comments
comments powered by Disqus