| 17 | using namespace dlib::ffmpeg; |
| 18 | |
| 19 | int main(const int argc, const char** argv) |
| 20 | try |
| 21 | { |
| 22 | command_line_parser parser; |
| 23 | parser.add_option("t", "capture time in seconds", 1); |
| 24 | parser.add_option("i", "input microphone device. E.g. hw:0,0", 1); |
| 25 | parser.add_option("o", "output audio file. E.g. recording.m4a, recording.wav. Default: recording.m4a", 1); |
| 26 | parser.add_option("codec", "audio codec. E.g. `aac`, `pcm_s16le`. Recommend `pcm_s16le` for WAV files and `aac` for `M4A` files. Default: `aac`", 1); |
| 27 | |
| 28 | parser.set_group_name("Help Options"); |
| 29 | parser.add_option("h", "alias of --help"); |
| 30 | parser.add_option("help", "display this message and exit"); |
| 31 | |
| 32 | parser.parse(argc, argv); |
| 33 | const char* one_time_opts[] = {"t", "i", "o", "codec"}; |
| 34 | parser.check_one_time_options(one_time_opts); |
| 35 | |
| 36 | if (parser.option("h") || parser.option("help")) |
| 37 | { |
| 38 | parser.print_options(); |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | const seconds time{get_option(parser, "t", 1)}; |
| 43 | const std::string device = get_option(parser, "i", "hw:0,0"); |
| 44 | const std::string filename = get_option(parser, "o", "recording.m4a"); |
| 45 | const std::string codec = get_option(parser, "codec", "aac"); |
| 46 | |
| 47 | // Open microphone |
| 48 | demuxer cap([&] { |
| 49 | demuxer::args args; |
| 50 | args.filepath = device; |
| 51 | args.input_format = "alsa"; |
| 52 | return args; |
| 53 | }()); |
| 54 | |
| 55 | if (!cap.is_open()) |
| 56 | { |
| 57 | cout << "Failed to open device: " << device << '\n'; |
| 58 | return EXIT_FAILURE; |
| 59 | } |
| 60 | |
| 61 | // Create WAV file |
| 62 | muxer writer([&] { |
| 63 | muxer::args args; |
| 64 | args.filepath = filename; |
| 65 | args.enable_image = false; |
| 66 | args.args_audio.codec_name = codec; |
| 67 | args.args_audio.sample_rate = cap.sample_rate(); |
| 68 | args.args_audio.channel_layout = cap.channel_layout(); |
| 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; |
nothing calls this directly
no test coverage detected