| 364 | } |
| 365 | |
| 366 | void test_demuxer_full ( |
| 367 | const std::string& filepath, |
| 368 | const int nframes, |
| 369 | const int height, |
| 370 | const int width, |
| 371 | const int sample_rate, |
| 372 | bool has_video, |
| 373 | bool has_audio |
| 374 | ) |
| 375 | { |
| 376 | demuxer cap(filepath); |
| 377 | DLIB_TEST(cap.video_enabled() == has_video); |
| 378 | DLIB_TEST(cap.audio_enabled() == has_audio); |
| 379 | DLIB_TEST(cap.height() == height); |
| 380 | DLIB_TEST(cap.width() == width); |
| 381 | DLIB_TEST(cap.sample_rate() == sample_rate); |
| 382 | // DLIB_TEST(cap.estimated_nframes() == nframes); // This won't always work with ffmpeg v3. v4 onwards is fine |
| 383 | const int estimated_samples_min = cap.estimated_total_samples() - cap.sample_rate(); // - 1s |
| 384 | const int estimated_samples_max = cap.estimated_total_samples() + cap.sample_rate(); // + 1s |
| 385 | |
| 386 | dlib::ffmpeg::frame frame; |
| 387 | int counter_images{0}; |
| 388 | int counter_samples{0}; |
| 389 | int iteration{0}; |
| 390 | |
| 391 | resizing_args args_image; |
| 392 | args_image.fmt = AV_PIX_FMT_RGB24; |
| 393 | |
| 394 | resampling_args args_audio; |
| 395 | args_audio.sample_rate = sample_rate; |
| 396 | args_audio.fmt = AV_SAMPLE_FMT_S16; |
| 397 | args_audio.channel_layout = AV_CH_LAYOUT_STEREO; |
| 398 | |
| 399 | while (cap.read(frame, args_image, args_audio)) |
| 400 | { |
| 401 | if (frame.is_image()) |
| 402 | { |
| 403 | DLIB_TEST(frame.height() == height); |
| 404 | DLIB_TEST(frame.width() == width); |
| 405 | DLIB_TEST(frame.pixfmt() == args_image.fmt); |
| 406 | |
| 407 | ++counter_images; |
| 408 | } |
| 409 | |
| 410 | if (frame.is_audio()) |
| 411 | { |
| 412 | DLIB_TEST(frame.sample_rate() == sample_rate); |
| 413 | DLIB_TEST(frame.layout() == args_audio.channel_layout); |
| 414 | DLIB_TEST(frame.samplefmt() == args_audio.fmt); |
| 415 | counter_samples += frame.nsamples(); |
| 416 | } |
| 417 | |
| 418 | ++iteration; |
| 419 | if (iteration % 10 == 0) |
| 420 | print_spinner(); |
| 421 | } |
| 422 | |
| 423 | DLIB_TEST(counter_images == nframes); |
no test coverage detected