MCPcopy Create free account
hub / github.com/davisking/dlib / main

Function main

examples/ffmpeg_file_to_speaker_ex.cpp:19–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17using namespace dlib::ffmpeg;
18
19int main(const int argc, const char** argv)
20try
21{
22 command_line_parser parser;
23 parser.add_option("i", "input audio file", 1);
24 parser.add_option("o", "output audio device (speaker). E.g. hw:0,0", 1);
25 parser.add_option("codec", "audio codec. E.g. pcm_s16le", 1);
26
27 parser.set_group_name("Help Options");
28 parser.add_option("h", "alias of --help");
29 parser.add_option("help", "display this message and exit");
30
31 parser.parse(argc, argv);
32 const char* one_time_opts[] = {"i", "o", "codec"};
33 parser.check_one_time_options(one_time_opts);
34
35 if (parser.option("h") || parser.option("help"))
36 {
37 parser.print_options();
38 return 0;
39 }
40
41 const std::string filename = get_option(parser, "i", "");
42 const std::string device = get_option(parser, "o", "hw:0,0");
43 const std::string codec = get_option(parser, "codec", "");
44
45 if (device.empty())
46 {
47 cout << "Didn't find a speaker. Exiting.\n";
48 return EXIT_FAILURE;
49 }
50
51 // Open file
52 demuxer cap({filename, video_disabled, audio_enabled});
53
54 if (!cap.is_open())
55 {
56 cout << "Failed to open " << device << endl;
57 return EXIT_FAILURE;
58 }
59
60 // Create writer to speaker
61 muxer writer([&] {
62 muxer::args args;
63 args.filepath = device;
64 args.output_format = "alsa";
65 args.enable_image = false;
66 args.args_audio.codec_name = codec;
67 args.args_audio.sample_rate = 44100;
68 args.args_audio.channel_layout = AV_CH_LAYOUT_STEREO;
69 args.args_audio.fmt = cap.sample_fmt();
70 return args;
71 }());
72
73 if (!writer.is_open())
74 {
75 cout << "Failed to open wav file" << endl;
76 return EXIT_FAILURE;

Callers

nothing calls this directly

Calls 10

get_optionFunction · 0.85
moveFunction · 0.85
parseMethod · 0.80
print_optionsMethod · 0.80
emptyMethod · 0.45
is_openMethod · 0.45
sample_fmtMethod · 0.45
readMethod · 0.45
pushMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected