diff --git a/ThumbnailGenerator b/ThumbnailGenerator index 3196ede..b557850 100755 Binary files a/ThumbnailGenerator and b/ThumbnailGenerator differ diff --git a/src/Main.cpp b/src/Main.cpp index 3d07aa1..590fd1f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -25,7 +25,10 @@ int main(int argc, char *argv[]) { std::unique_ptr thumbnailGenerator = std::make_unique(); - thumbnailGenerator->readVideoFrames(input_file_path); + int duration = thumbnailGenerator->get_duration(input_file_path); + std::cout << "duration: " << duration << std::endl; + + // thumbnailGenerator->read_video_frames(input_file_path); return 0; } diff --git a/src/ThumbnailGenerator.cpp b/src/ThumbnailGenerator.cpp index 1843e19..5b6787c 100644 --- a/src/ThumbnailGenerator.cpp +++ b/src/ThumbnailGenerator.cpp @@ -11,12 +11,36 @@ extern "C" { ThumbnailGenerator::ThumbnailGenerator() { av_register_all(); } -std::string ThumbnailGenerator::generateThumbnail(std::string path) { +int ThumbnailGenerator::get_duration_microseconds(std::string input_file_path) { + // Open input file and allocate format context + AVFormatContext *format_ctx = nullptr; + int ret = avformat_open_input(&format_ctx, input_file_path.c_str(), nullptr, + nullptr); + if (ret < 0) { + std::cerr << "Could not open input file: " << input_file_path << std::endl; + // char buff[256]; + // av_strerror(ret, buff, 256); + // printf(buff); + + std::cerr << "Error: " << ret << std::endl; + AVERROR(ret); + + throw std::runtime_error("Could not open input file"); + } + + int duration = format_ctx->duration; + + avformat_close_input(&format_ctx); + + return duration; +} + +std::string ThumbnailGenerator::generate_thumbnail(std::string path) { std::cout << "generateThumbnail: " << path << std::endl; return "generateThumbnail: " + path; } -void ThumbnailGenerator::readVideoFrames(std::string input_file_path) { +void ThumbnailGenerator::read_video_frames(std::string input_file_path) { std::cout << "readVideoFrames: " << input_file_path << std::endl; // Open input file and allocate format context diff --git a/src/include/ThumbnailGenerator.hpp b/src/include/ThumbnailGenerator.hpp index 15d20f8..25fef55 100644 --- a/src/include/ThumbnailGenerator.hpp +++ b/src/include/ThumbnailGenerator.hpp @@ -5,9 +5,11 @@ class ThumbnailGenerator { public: ThumbnailGenerator(); // given a path to a video file, generate a thumbnail - std::string generateThumbnail(std::string path); + std::string generate_thumbnail(std::string path); // reads and simply prints out information about the video frames - void readVideoFrames(std::string path); + void read_video_frames(std::string path); + + int get_duration_microseconds(std::string path); private: };