+ }
+}
+
+void
+FFmpegExaminer::video_packet (AVCodecContext* context)
+{
+ if (_first_video && !_need_video_length) {
+ return;
+ }
+
+ int frame_finished;
+ if (avcodec_decode_video2 (context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) {
+ if (!_first_video) {
+ _first_video = frame_time (_format_context->streams[_video_stream]);
+ }
+ if (_need_video_length) {
+ _video_length = frame_time (
+ _format_context->streams[_video_stream]
+ ).get_value_or (ContentTime ()).frames (video_frame_rate().get ());
+ }
+ }
+}
+
+void
+FFmpegExaminer::audio_packet (AVCodecContext* context, shared_ptr<FFmpegAudioStream> stream)
+{
+ if (stream->first_audio) {
+ return;
+ }
+
+ int frame_finished;
+ if (avcodec_decode_audio4 (context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) {
+ stream->first_audio = frame_time (stream->stream (_format_context));
+ }
+}
+
+void
+FFmpegExaminer::subtitle_packet (AVCodecContext* context, shared_ptr<FFmpegSubtitleStream> stream)
+{
+ int frame_finished;
+ AVSubtitle sub;
+ if (avcodec_decode_subtitle2 (context, &sub, &frame_finished, &_packet) >= 0 && frame_finished) {
+ FFmpegSubtitlePeriod const period = subtitle_period (sub);
+ if (sub.num_rects <= 0 && _last_subtitle_start) {
+ stream->add_subtitle (ContentTimePeriod (_last_subtitle_start.get (), period.from));
+ _last_subtitle_start = optional<ContentTime> ();
+ } else if (sub.num_rects == 1) {
+ if (period.to) {
+ stream->add_subtitle (ContentTimePeriod (period.from, period.to.get ()));
+ } else {
+ _last_subtitle_start = period.from;
+ }