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

Function test_demuxer_full

dlib/test/ffmpeg.cpp:366–427  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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);

Callers 1

perform_testMethod · 0.85

Calls 15

print_spinnerFunction · 0.85
is_imageMethod · 0.80
pixfmtMethod · 0.80
is_audioMethod · 0.80
samplefmtMethod · 0.80
nsamplesMethod · 0.80
video_enabledMethod · 0.45
audio_enabledMethod · 0.45
heightMethod · 0.45
widthMethod · 0.45
sample_rateMethod · 0.45

Tested by

no test coverage detected