diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-01-11 16:34:26 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-01-11 22:16:04 +0100 |
| commit | b703142e8750c509174b4d964009aecf93f3d834 (patch) | |
| tree | 22936a3161af7df64acb42f95d0b08d32e9593dd /src/lib/ffmpeg.cc | |
| parent | 5cb5c48441b20c478eb29001cebe3b08c0422341 (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.cc | 30 |
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; + +} + |
