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

Function main

examples/ffmpeg_rtsp_ex.cpp:28–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26using namespace dlib::ffmpeg;
27
28int main(const int argc, const char** argv)
29try
30{
31 command_line_parser parser;
32 parser.add_option("i", "input video", 1);
33 parser.add_option("codec", "video codec name. e.g. `h264`. Defaults to `mpeg4`", 1);
34 parser.add_option("height", "height of encoded stream. Defaults to whatever is in the video file", 1);
35 parser.add_option("width", "width of encoded stream. Defaults to whatever is in the video file", 1);
36
37 parser.set_group_name("Help Options");
38 parser.add_option("h", "alias of --help");
39 parser.add_option("help", "display this message and exit");
40
41 parser.parse(argc, argv);
42 const char* one_time_opts[] = {"i", "codec", "height", "width"};
43 parser.check_one_time_options(one_time_opts);
44
45 if (parser.option("h") || parser.option("help"))
46 {
47 parser.print_options();
48 return 0;
49 }
50
51 const std::string input_filepath = parser.option("i").argument();
52
53 // First, we open a video which we use to transmit and receive images over RTSP.
54 demuxer cap({input_filepath, video_enabled, audio_disabled});
55
56 if (!cap.is_open())
57 {
58 cout << "Failed to open " << input_filepath << endl;
59 return EXIT_FAILURE;
60 }
61
62 if (!cap.video_enabled())
63 {
64 cout << "This video does not contain images." << endl;
65 return EXIT_FAILURE;
66 }
67
68 const std::string url = "rtsp://0.0.0.0:8000/stream";
69
70 // We start 2 threads:
71 // - 1 for an RTSP server that listens for an incoming RTSP client and decodes the frames
72 // - 1 for an RTSP client that connects and pushes/muxes image frames.
73
74 std::thread rx{[&]
75 {
76 // This is an example that show-cases the usage of demuxer::args::format_options.
77 // This is used for AVFormatContext and demuxer-private options specific to the container.
78 // {"rtsp_flags", "listen"} tells the RTSP demuxer that it is a server
79 // {"rtsp_transport", "tcp"} configures RTSP over TCP transport. This way we don't loose any packets.
80 // We set a listening timeout of 5s.
81
82 demuxer cap([&] {
83 demuxer::args args;
84 args.filepath = url;
85 args.format_options["rtsp_flags"] = "listen";

Callers

nothing calls this directly

Calls 14

get_optionFunction · 0.85
moveFunction · 0.85
parseMethod · 0.80
print_optionsMethod · 0.80
is_openMethod · 0.45
video_enabledMethod · 0.45
readMethod · 0.45
set_imageMethod · 0.45
heightMethod · 0.45
widthMethod · 0.45
pixel_fmtMethod · 0.45
fpsMethod · 0.45

Tested by

no test coverage detected