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

Function test_encoder

dlib/test/ffmpeg.cpp:434–594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

432//////////////////////////////////////////////////////////////////////////////////////////////////////
433
434 void test_encoder (
435 const std::string& filepath,
436 AVCodecID image_codec,
437 AVCodecID audio_codec
438 )
439 {
440 // Load a video/audio as a source of frames
441 demuxer cap(filepath);
442 DLIB_TEST(cap.is_open());
443 const bool has_video = cap.video_enabled();
444 const bool has_audio = cap.audio_enabled();
445 const int height = cap.height();
446 const int width = cap.width();
447 const auto pixfmt = cap.pixel_fmt();
448 const auto fps = cap.fps();
449 const int rate = cap.sample_rate();
450 const auto samplefmt = cap.sample_fmt();
451 const auto layout = cap.channel_layout();
452
453 std::vector<frame> frames;
454 frame f;
455 int nimages{0};
456 int nsamples{0};
457
458 while (cap.read(f))
459 {
460 if (f.is_image())
461 ++nimages;
462 if (f.is_audio())
463 nsamples += f.nsamples();
464 frames.push_back(std::move(f));
465 }
466
467 print_spinner();
468
469 // Encoder configured using same parameters as video
470 encoder enc_image, enc_audio;
471 std::vector<uint8_t> buf_image, buf_audio;
472
473 if (has_video)
474 {
475 enc_image = encoder([&] {
476 encoder::args args;
477 args.args_codec.codec = image_codec;
478 args.args_image.h = height;
479 args.args_image.w = width;
480 args.args_image.framerate = fps;
481 args.args_image.fmt = AV_PIX_FMT_YUV420P;
482 return args;
483 }());
484
485 DLIB_TEST(enc_image.is_open());
486 DLIB_TEST(enc_image.is_image_encoder());
487 DLIB_TEST(enc_image.get_codec_id() == image_codec);
488 DLIB_TEST(enc_image.height() == height);
489 DLIB_TEST(enc_image.width() == width);
490 // Can't check for framerate, as this might have been changed from requested value, due to codec availability.
491 print_spinner();

Callers 1

perform_testMethod · 0.85

Calls 15

moveFunction · 0.85
print_spinnerFunction · 0.85
encoderClass · 0.85
sinkFunction · 0.85
decoderClass · 0.85
readMethod · 0.80
is_imageMethod · 0.80
is_audioMethod · 0.80
nsamplesMethod · 0.80
is_image_encoderMethod · 0.80
is_audio_encoderMethod · 0.80
is_image_decoderMethod · 0.80

Tested by

no test coverage detected