diff --git a/shared/VideoReader.hpp b/shared/VideoReader.hpp index 2ae087d..d7814b2 100644 --- a/shared/VideoReader.hpp +++ b/shared/VideoReader.hpp @@ -41,9 +41,7 @@ public: bool has_video = false; explicit VideoReader(const std::string& filename) { - if (!open_file(filename)) - return; - if (!has_video && !has_audio) return; + open_file(filename); get_source_info(); if (has_video) allocate_video_conversion_buffers(); if (has_audio) allocate_audio_conversion_buffers(); @@ -134,9 +132,11 @@ public: // EOF — loop back to start avformat_seek_file(format_context, -1, 0, 0, 0, AVSEEK_FLAG_BACKWARD); if (has_video) avcodec_flush_buffers(video_codec_context); - if (has_audio) avcodec_flush_buffers(audio_codec_context); - swr_close(swr_audio_ctx); - swr_init(swr_audio_ctx); + if (has_audio) { + avcodec_flush_buffers(audio_codec_context); + swr_close(swr_audio_ctx); + swr_init(swr_audio_ctx); + } continue; } @@ -166,7 +166,7 @@ private: AVFrame* audio_frame = av_frame_alloc(); SwrContext* swr_audio_ctx = nullptr; - bool open_file(const std::string& filename) { + void open_file(const std::string& filename) { if (avformat_open_input(&format_context, filename.c_str(), nullptr, nullptr) != 0) throw std::runtime_error("Could not open file: " + filename); @@ -186,12 +186,10 @@ private: } } - if (video_stream_index == -1 && audio_stream_index == -1) { + if (!has_video && !has_audio) { avformat_close_input(&format_context); throw std::runtime_error("No audio/video stream found in: " + filename); } - - return true; } void get_source_info() {