summaryrefslogtreecommitdiff
path: root/src/lib/ffmpeg.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-01-11 16:34:26 +0100
committerCarl Hetherington <cth@carlh.net>2022-01-11 16:34:26 +0100
commit32925ee291446cfba8bbd35828ba1719373edb40 (patch)
tree6e4e823d9ea2a63b829a795e36d8a569cdd51207 /src/lib/ffmpeg.cc
parentd5c44276a81e85613702567eee59412a2d99bcdd (diff)
Use a separate AVFrame for each stream when decoding.
This seems to be what ffplay does and it feels like it makes sense as frames may be built from multiple packets AFAICS.
Diffstat (limited to 'src/lib/ffmpeg.cc')
-rw-r--r--src/lib/ffmpeg.cc30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc
index eed9ab94c..0f63ea172 100644
--- a/src/lib/ffmpeg.cc
+++ b/src/lib/ffmpeg.cc
@@ -72,7 +72,11 @@ FFmpeg::~FFmpeg ()
avcodec_free_context (&i);
}
- av_frame_free (&_frame);
+ av_frame_free (&_video_frame);
+ for (auto& audio_frame: _audio_frame) {
+ av_frame_free (&audio_frame.second);
+ }
+
avformat_close_input (&_format_context);
}
@@ -188,8 +192,8 @@ FFmpeg::setup_general ()
}
}
- _frame = av_frame_alloc ();
- if (_frame == 0) {
+ _video_frame = av_frame_alloc ();
+ if (_video_frame == nullptr) {
throw std::bad_alloc ();
}
}
@@ -354,3 +358,23 @@ FFmpeg::pts_offset (vector<shared_ptr<FFmpegAudioStream>> audio_streams, optiona
return po;
}
+
+
+AVFrame *
+FFmpeg::audio_frame (shared_ptr<const FFmpegAudioStream> stream)
+{
+ auto iter = _audio_frame.find(stream);
+ if (iter != _audio_frame.end()) {
+ return iter->second;
+ }
+
+ auto frame = av_frame_alloc ();
+ if (frame == nullptr) {
+ throw std::bad_alloc();
+ }
+
+ _audio_frame[stream] = frame;
+ return frame;
+
+}
+