mapping.as_xml (root->add_child("Mapping"));
}
-int
-FFmpegStream::index (AVFormatContext const * fc) const
+bool
+FFmpegStream::uses_index (AVFormatContext const * fc, int index) const
{
if (_legacy_id) {
- return id;
+ return id == index;
}
size_t i = 0;
while (i < fc->nb_streams) {
if (fc->streams[i]->id == id) {
- return i;
+ return int (i) == index;
}
++i;
}
- assert (false);
+ return false;
}
AVStream *
void as_xml (xmlpp::Node *) const;
/** @param c An AVFormatContext.
- * @return Stream index within the AVFormatContext.
+ * @param index A stream index within the AVFormatContext.
+ * @return true if this FFmpegStream uses the given stream index.
*/
- int index (AVFormatContext const * c) const;
+ bool uses_index (AVFormatContext const * c, int index) const;
AVStream* stream (AVFormatContext const * c) const;
std::string name;
if (si == _video_stream && _decode_video) {
decode_video_packet ();
- } else if (_ffmpeg_content->audio_stream() && si == _ffmpeg_content->audio_stream()->index (_format_context) && _decode_audio) {
+ } else if (_ffmpeg_content->audio_stream() && _ffmpeg_content->audio_stream()->uses_index (_format_context, si) && _decode_audio) {
decode_audio_packet ();
- } else if (_ffmpeg_content->subtitle_stream() && si == _ffmpeg_content->subtitle_stream()->index (_format_context) && film->with_subtitles ()) {
+ } else if (_ffmpeg_content->subtitle_stream() && _ffmpeg_content->subtitle_stream()->uses_index (_format_context, si) && film->with_subtitles ()) {
decode_subtitle_packet ();
}
if (_packet.stream_index == _video_stream && !_first_video) {
if (avcodec_decode_video2 (context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) {
- _first_video = frame_time (_video_stream);
+ _first_video = frame_time (_format_context->streams[_video_stream]);
}
} else {
for (size_t i = 0; i < _audio_streams.size(); ++i) {
- if (_packet.stream_index == _audio_streams[i]->index (_format_context) && !_audio_streams[i]->first_audio) {
+ if (_audio_streams[i]->uses_index (_format_context, _packet.stream_index) && !_audio_streams[i]->first_audio) {
if (avcodec_decode_audio4 (context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) {
- _audio_streams[i]->first_audio = frame_time (_audio_streams[i]->index (_format_context));
+ _audio_streams[i]->first_audio = frame_time (_audio_streams[i]->stream (_format_context));
}
}
}
}
optional<double>
-FFmpegExaminer::frame_time (int stream) const
+FFmpegExaminer::frame_time (AVStream* s) const
{
optional<double> t;
int64_t const bet = av_frame_get_best_effort_timestamp (_frame);
if (bet != AV_NOPTS_VALUE) {
- t = bet * av_q2d (_format_context->streams[stream]->time_base);
+ t = bet * av_q2d (s->time_base);
}
return t;
std::string stream_name (AVStream* s) const;
std::string audio_stream_name (AVStream* s) const;
std::string subtitle_stream_name (AVStream* s) const;
- boost::optional<double> frame_time (int) const;
+ boost::optional<double> frame_time (AVStream* s) const;
std::vector<boost::shared_ptr<FFmpegSubtitleStream> > _subtitle_streams;
std::vector<boost::shared_ptr<FFmpegAudioStream> > _audio_streams;