| 44 | using namespace dlib::ffmpeg; |
| 45 | |
| 46 | int main(const int argc, const char** argv) |
| 47 | try |
| 48 | { |
| 49 | command_line_parser parser; |
| 50 | parser.add_option("i", "input video encoded stream. e.g. dlib/test/ffmpeg_data/MOT20-08-raw.h264", 1); |
| 51 | parser.add_option("codec", "codec name. e.g. h264", 1); |
| 52 | parser.set_group_name("Help Options"); |
| 53 | parser.add_option("h", "alias of --help"); |
| 54 | parser.add_option("help", "display this message and exit"); |
| 55 | |
| 56 | parser.parse(argc, argv); |
| 57 | const char* one_time_opts[] = {"i"}; |
| 58 | parser.check_one_time_options(one_time_opts); |
| 59 | |
| 60 | if (parser.option("h") || parser.option("help")) |
| 61 | { |
| 62 | parser.print_options(); |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | const std::string filepath = parser.option("i").argument(); |
| 67 | const std::string codec = parser.option("codec").argument(); |
| 68 | |
| 69 | decoder dec([&] { |
| 70 | decoder::args args; |
| 71 | args.codec_name = codec; |
| 72 | return args; |
| 73 | }()); |
| 74 | |
| 75 | if (!dec.is_open()) |
| 76 | { |
| 77 | printf("Failed to create decoder.\n"); |
| 78 | return EXIT_FAILURE; |
| 79 | } |
| 80 | |
| 81 | image_window win; |
| 82 | |
| 83 | const auto callback = [&](array2d<rgb_pixel>& img) |
| 84 | { |
| 85 | win.set_image(img); |
| 86 | }; |
| 87 | |
| 88 | ifstream fin{filepath, std::ios::binary}; |
| 89 | std::vector<char> buf(1024); |
| 90 | |
| 91 | while (fin) |
| 92 | { |
| 93 | fin.read(buf.data(), buf.size()); |
| 94 | size_t ret = fin.gcount(); |
| 95 | dec.push((const uint8_t*)buf.data(), ret, wrap(callback)); |
| 96 | } |
| 97 | |
| 98 | dec.flush(wrap(callback)); |
| 99 | |
| 100 | return EXIT_SUCCESS; |
| 101 | } |
| 102 | catch (const std::exception& e) |
| 103 | { |