Feature/video in #3
+8
-10
@@ -41,9 +41,7 @@ public:
|
|||||||
bool has_video = false;
|
bool has_video = false;
|
||||||
|
|
||||||
explicit VideoReader(const std::string& filename) {
|
explicit VideoReader(const std::string& filename) {
|
||||||
if (!open_file(filename))
|
open_file(filename);
|
||||||
return;
|
|
||||||
if (!has_video && !has_audio) return;
|
|
||||||
get_source_info();
|
get_source_info();
|
||||||
if (has_video) allocate_video_conversion_buffers();
|
if (has_video) allocate_video_conversion_buffers();
|
||||||
if (has_audio) allocate_audio_conversion_buffers();
|
if (has_audio) allocate_audio_conversion_buffers();
|
||||||
@@ -134,9 +132,11 @@ public:
|
|||||||
// EOF — loop back to start
|
// EOF — loop back to start
|
||||||
avformat_seek_file(format_context, -1, 0, 0, 0, AVSEEK_FLAG_BACKWARD);
|
avformat_seek_file(format_context, -1, 0, 0, 0, AVSEEK_FLAG_BACKWARD);
|
||||||
if (has_video) avcodec_flush_buffers(video_codec_context);
|
if (has_video) avcodec_flush_buffers(video_codec_context);
|
||||||
if (has_audio) avcodec_flush_buffers(audio_codec_context);
|
if (has_audio) {
|
||||||
swr_close(swr_audio_ctx);
|
avcodec_flush_buffers(audio_codec_context);
|
||||||
swr_init(swr_audio_ctx);
|
swr_close(swr_audio_ctx);
|
||||||
|
swr_init(swr_audio_ctx);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ private:
|
|||||||
AVFrame* audio_frame = av_frame_alloc();
|
AVFrame* audio_frame = av_frame_alloc();
|
||||||
SwrContext* swr_audio_ctx = nullptr;
|
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)
|
if (avformat_open_input(&format_context, filename.c_str(), nullptr, nullptr) != 0)
|
||||||
throw std::runtime_error("Could not open file: " + filename);
|
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);
|
avformat_close_input(&format_context);
|
||||||
throw std::runtime_error("No audio/video stream found in: " + filename);
|
throw std::runtime_error("No audio/video stream found in: " + filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_source_info() {
|
void get_source_info() {
|
||||||
|
|||||||
Reference in New Issue
Block a user