Skip to content

Commit

Permalink
Persist has_b_frames for lavf and haali as well
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne committed Apr 4, 2014
1 parent 0dcaaa6 commit 1a7fc3f
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion doc/ffms2-changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h1>FFmpegSource2 Changelog</h1>
<li>Fix infinite loop on garbage data at the beginning of AAC files (Plorkyeran)</li>
<li>Deal with the never-ending bitrot from FFmpeg/Libav API changes (Daemon404, Plorkyeran)</li>
<li>Make indexes not arch-specific and trivially smaller (Plorkyeran)</li>
<li>Fix bug where the first b-frame was replaced with the frame before it with open-gop h.264 in matroska (Plorkyeran)</li>
<li>Fix bug where the first b-frame was replaced with the frame before it with open-gop h.264 (Plorkyeran)</li>
<li>Fix seeking issues with open-gop h.264 (Plorkyeran)</li>
</ul>
</li>
Expand Down
2 changes: 1 addition & 1 deletion include/ffms.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define FFMS_H

// Version format: major - minor - micro - bump
#define FFMS_VERSION ((2 << 24) | (19 << 16) | (0 << 8) | 9)
#define FFMS_VERSION ((2 << 24) | (19 << 16) | (0 << 8) | 10)

#include <stdint.h>

Expand Down
2 changes: 1 addition & 1 deletion src/core/haaliindexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ FFMS_Index *FFHaaliIndexer::DoIndexing() {
av_free(TempPacket.data);
}

TrackIndices->Sort();
TrackIndices->Finalize(VideoContexts);
return TrackIndices.release();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/core/haalivideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ FFHaaliVideo::FFHaaliVideo(const char *SourceFile, int Track, FFMS_Index &Index,

HCodecContext = InitializeCodecContextFromHaaliInfo(pBag);
CodecContext = HCodecContext;
CodecContext->has_b_frames = Frames.MaxBFrames;

const AVCodec *Codec = NULL;
std::swap(Codec, CodecContext->codec);
Expand Down
25 changes: 22 additions & 3 deletions src/core/indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,28 @@ void FFMS_Index::Release() {
delete this;
}

void FFMS_Index::Sort() {
for (FFMS_Index::iterator Cur = begin(); Cur != end(); ++Cur)
Cur->FinalizeTrack();
void FFMS_Index::Finalize(std::vector<SharedVideoContext> const& video_contexts) {
for (size_t i = 0, end = size(); i != end; ++i) {
FFMS_Track& track = (*this)[i];
track.FinalizeTrack();

if (track.TT != FFMS_TYPE_VIDEO) continue;

if (video_contexts[i].CodecContext->has_b_frames) {
track.MaxBFrames = video_contexts[i].CodecContext->has_b_frames;
continue;
}

// Whether or not has_b_frames gets set during indexing seems
// to vary based on version of FFmpeg/Libav, so do an extra
// check for b-frames if it's 0.
for (size_t f = 0; f < track.size(); ++f) {
if (track[f].FrameType == AV_PICTURE_TYPE_B) {
track.MaxBFrames = 1;
break;
}
}
}
}

bool FFMS_Index::CompareFileSignature(const char *Filename) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/indexing.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct FFMS_Index : public std::vector<FFMS_Track>, private noncopyable {
int64_t Filesize;
uint8_t Digest[20];

void Sort();
void Finalize(std::vector<SharedVideoContext> const& video_contexts);
bool CompareFileSignature(const char *Filename);
void WriteIndex(const char *IndexFile);

Expand Down
2 changes: 1 addition & 1 deletion src/core/lavfindexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ FFMS_Index *FFLAVFIndexer::DoIndexing() {
av_free_packet(&Packet);
}

TrackIndices->Sort();
TrackIndices->Finalize(VideoContexts);
return TrackIndices.release();
}

Expand Down
1 change: 1 addition & 0 deletions src/core/lavfvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ FFLAVFVideo::FFLAVFVideo(const char *SourceFile, int Track, FFMS_Index &Index,

CodecContext = FormatContext->streams[VideoTrack]->codec;
CodecContext->thread_count = DecodingThreads;
CodecContext->has_b_frames = Frames.MaxBFrames;

Codec = avcodec_find_decoder(CodecContext->codec_id);
if (Codec == NULL)
Expand Down
22 changes: 1 addition & 21 deletions src/core/matroskaindexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,7 @@ FFMS_Index *FFMatroskaIndexer::DoIndexing() {
}
}

for (size_t i = 0; i < TrackIndices->size(); ++i) {
FFMS_Track& track = (*TrackIndices)[i];
if (track.TT != FFMS_TYPE_VIDEO) continue;

if (VideoContexts[i].CodecContext->has_b_frames) {
track.MaxBFrames = VideoContexts[i].CodecContext->has_b_frames;
continue;
}

// Whether or not has_b_frames gets set during indexing seems
// to vary based on version of FFmpeg/Libav, so do an extra
// check for b-frames if it's 0.
for (size_t f = 0; f < track.size(); ++f) {
if (track[f].FrameType == AV_PICTURE_TYPE_B) {
track.MaxBFrames = 1;
break;
}
}
}

TrackIndices->Sort();
TrackIndices->Finalize(VideoContexts);
return TrackIndices.release();
}
}
Expand Down

0 comments on commit 1a7fc3f

Please sign in to comment.