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

Function main

examples/ffmpeg_video_decoding2_ex.cpp:20–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18using namespace dlib::ffmpeg;
19
20int main(const int argc, const char** argv)
21try
22{
23 command_line_parser parser;
24 parser.add_option("i", "input video encoded stream. e.g. dlib/test/ffmpeg_data/MOT20-08-raw.h264", 1);
25 parser.add_option("codec", "codec name. e.g. h264", 1);
26 parser.set_group_name("Help Options");
27 parser.add_option("h", "alias of --help");
28 parser.add_option("help", "display this message and exit");
29
30 parser.parse(argc, argv);
31 const char* one_time_opts[] = {"i"};
32 parser.check_one_time_options(one_time_opts);
33
34 if (parser.option("h") || parser.option("help"))
35 {
36 parser.print_options();
37 return 0;
38 }
39
40 const std::string filepath = parser.option("i").argument();
41 const std::string codec = parser.option("codec").argument();
42
43 decoder dec([&] {
44 decoder::args args;
45 args.codec_name = codec;
46 return args;
47 }());
48
49 if (!dec.is_open())
50 {
51 printf("Failed to create decoder.\n");
52 return EXIT_FAILURE;
53 }
54
55 frame f;
56 array2d<rgb_pixel> img;
57 int samples{0};
58 image_window win;
59
60 // When reading frames, we get exactly what's in the codec by default.
61 // To resize, change pixel format, resample or change sample format,
62 // you have to pass extra arguments to wrap() which either resizes or resamples
63 // the frame. Since we want rgb_pixel, we need to set the pixel format appropriately.
64 const resizing_args args_image {0, 0, pix_traits<rgb_pixel>::fmt};
65
66 const auto callback = [&](frame& f)
67 {
68 if (f.is_image())
69 {
70 convert(f, img);
71 win.set_image(img);
72 }
73 else if (f.is_audio())
74 {
75 samples += f.nsamples();
76 }
77 };

Callers

nothing calls this directly

Calls 15

parseMethod · 0.80
print_optionsMethod · 0.80
is_imageMethod · 0.80
is_audioMethod · 0.80
nsamplesMethod · 0.80
readMethod · 0.80
convertFunction · 0.50
wrapFunction · 0.50
is_openMethod · 0.45
set_imageMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected