@@ -21,30 +21,37 @@ using namespace std;
21
21
22
22
primo::ref<MediaSocket> createOutputSocket (Options& opt)
23
23
{
24
- auto socket = primo::make_ref (Library::createMediaSocket ());
25
- socket->setFile (primo::ustring (opt.outputFile ));
26
- socket->setStreamType (StreamType::MPEG_Audio);
27
- socket->setStreamSubType (StreamSubType::MPEG_Audio_Layer3);
28
-
29
- auto pin = primo::make_ref (Library::createMediaPin ());
30
- socket->pins ()->add (pin.get ());
31
-
24
+ // create stream info to describe the output audio stream
32
25
auto asi = primo::make_ref (Library::createAudioStreamInfo ());
33
- pin->setStreamInfo (asi.get ());
34
-
35
26
asi->setStreamType (StreamType::MPEG_Audio);
36
27
asi->setStreamSubType (StreamSubType::MPEG_Audio_Layer3);
37
28
38
- // Change the encoding bitrate with the following line. The default bitrate is 128000. You can set it to 192000, 256000, etc.
29
+ // The default bitrate is 128000. You can set it to 192000, 256000, etc.
39
30
// asi->setBitrate(192000);
40
31
41
- // Change the sampling rate and the number of the channels, e.g. Mono, 44.1 Khz
42
- // asi->setChannels(1);
32
+ // Optionally set the sampling rate and the number of the channels, e.g. 44.1 Khz, Mono
43
33
// asi->setSampleRate(44100);
34
+ // asi->setChannels(1);
44
35
45
- // Change the stereo mode, e.g. Joint Stereo
36
+ // create a pin using the stream info
37
+ auto pin = primo::make_ref (Library::createMediaPin ());
38
+ pin->setStreamInfo (asi.get ());
39
+
40
+ // the pin allows you to specify additional parameters for the encoder
41
+ // for example, change the stereo mode, e.g. Joint Stereo
46
42
// pin->params()->addInt(Param::Encoder::Audio::MPEG1::StereoMode, StereoMode::Joint);
47
43
44
+ // finally create a socket for the output container format which is MP3 in this case
45
+ auto socket = primo::make_ref (Library::createMediaSocket ());
46
+ socket->setStreamType (StreamType::MPEG_Audio);
47
+ socket->setStreamSubType (StreamSubType::MPEG_Audio_Layer3);
48
+
49
+ socket->pins ()->add (pin.get ());
50
+
51
+ // output to a file
52
+ auto output_file = primo::ustring (opt.outputFile );
53
+ socket->setFile (output_file);
54
+
48
55
return socket;
49
56
}
50
57
0 commit comments