| 23 | using namespace dlib::ffmpeg; |
| 24 | |
| 25 | int main(const int argc, const char** argv) |
| 26 | try |
| 27 | { |
| 28 | command_line_parser parser; |
| 29 | parser.add_option("i", "input video", 1); |
| 30 | parser.add_option("codec", "codec name. e.g. h264. Defaults to mpeg4", 1); |
| 31 | parser.add_option("height", "height of encoded stream. Defaults to whatever is in the video file", 1); |
| 32 | parser.add_option("width", "width of encoded stream. Defaults to whatever is in the video file", 1); |
| 33 | |
| 34 | parser.set_group_name("Help Options"); |
| 35 | parser.add_option("h", "alias of --help"); |
| 36 | parser.add_option("help", "display this message and exit"); |
| 37 | |
| 38 | parser.parse(argc, argv); |
| 39 | const char* one_time_opts[] = {"i", "codec", "height", "width"}; |
| 40 | parser.check_one_time_options(one_time_opts); |
| 41 | |
| 42 | if (parser.option("h") || parser.option("help")) |
| 43 | { |
| 44 | parser.print_options(); |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | const std::string filepath = parser.option("i").argument(); |
| 49 | |
| 50 | // Load input video. |
| 51 | // Note, this uses a convenient constructor which (dis)enables audio and/or video. |
| 52 | demuxer cap({filepath, video_enabled, audio_disabled}); |
| 53 | |
| 54 | if (!cap.is_open() || !cap.video_enabled()) |
| 55 | { |
| 56 | cout << "Failed to open " << filepath << endl; |
| 57 | return EXIT_FAILURE; |
| 58 | } |
| 59 | |
| 60 | // This is a small functor that creates an encoder using the command line arguments |
| 61 | // and different types of output buffers using the convenient sink() overload. |
| 62 | const auto make_encoder = [&] |
| 63 | { |
| 64 | return encoder([&] { |
| 65 | encoder::args args; |
| 66 | args.args_codec.codec_name = get_option(parser, "codec", "mpeg4"); |
| 67 | args.args_image.h = get_option(parser, "height", cap.height()); |
| 68 | args.args_image.w = get_option(parser, "width", cap.width()); |
| 69 | args.args_image.fmt = cap.pixel_fmt(); |
| 70 | args.args_image.framerate = cap.fps(); |
| 71 | return args; |
| 72 | }()); |
| 73 | }; |
| 74 | |
| 75 | // Encode to multiple different types of buffers. |
| 76 | std::vector<char> buf1; |
| 77 | std::vector<int8_t> buf2; |
| 78 | std::vector<uint8_t> buf3; |
| 79 | std::ostringstream buf4; |
| 80 | std::ofstream buf5("encoded.dat", std::ios::binary); |
| 81 | |
| 82 | // Different encoders for different buffers |
nothing calls this directly
no test coverage detected