diff --git a/aegisub/FFmpegSource2/ffaudiosource.cpp b/aegisub/FFmpegSource2/ffaudiosource.cpp index 1cca94c1a..038147611 100644 --- a/aegisub/FFmpegSource2/ffaudiosource.cpp +++ b/aegisub/FFmpegSource2/ffaudiosource.cpp @@ -62,7 +62,7 @@ void TAudioCache::CacheBlock(int64_t Start, int64_t Samples, uint8_t *SrcData) { } push_front(new TAudioBlock(Start, Samples, SrcData, Samples * BytesPerSample)); - if (size() >= MaxCacheBlocks) { + if (static_cast(size()) >= MaxCacheBlocks) { delete back(); pop_back(); } @@ -427,9 +427,9 @@ int FFMatroskaAudio::GetAudio(void *Buf, int64_t Start, int64_t Count, char *Err } CurrentAudioBlock++; - if (CurrentAudioBlock < Frames.size()) + if (CurrentAudioBlock < static_cast(Frames.size())) CurrentSample = Frames[CurrentAudioBlock].SampleStart; - } while (Start + Count - CacheEnd > 0 && CurrentAudioBlock < Frames.size()); + } while (Start + Count - CacheEnd > 0 && CurrentAudioBlock < static_cast(Frames.size())); return 0; } @@ -666,7 +666,7 @@ int FFHaaliAudio::GetAudio(void *Buf, int64_t Start, int64_t Count, char *ErrorM if (CacheEnd == Start + Count) return 0; - int64_t CurrentAudioBlock; + int CurrentAudioBlock; // Is seeking required to decode the requested samples? // if (!(CurrentSample >= Start && CurrentSample <= CacheEnd)) { if (CurrentSample != CacheEnd) { @@ -702,9 +702,9 @@ int FFHaaliAudio::GetAudio(void *Buf, int64_t Start, int64_t Count, char *ErrorM } CurrentAudioBlock++; - if (CurrentAudioBlock < Frames.size()) + if (CurrentAudioBlock < static_cast(Frames.size())) CurrentSample = Frames[CurrentAudioBlock].SampleStart; - } while (Start + Count - CacheEnd > 0 && CurrentAudioBlock < Frames.size()); + } while (Start + Count - CacheEnd > 0 && CurrentAudioBlock < static_cast(Frames.size())); return 0; } diff --git a/aegisub/FFmpegSource2/ffavisynth.cpp b/aegisub/FFmpegSource2/ffavisynth.cpp index cc81bdbd0..a4fc7df72 100644 --- a/aegisub/FFmpegSource2/ffavisynth.cpp +++ b/aegisub/FFmpegSource2/ffavisynth.cpp @@ -18,14 +18,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include #include "ffavisynth.h" -#include "utils.h" +#include AvisynthVideoSource::AvisynthVideoSource(const char *SourceFile, int Track, FFIndex *Index, int FPSNum, int FPSDen, const char *PP, int Threads, int SeekMode, IScriptEnvironment* Env, char *ErrorMsg, unsigned MsgSize) { memset(&VI, 0, sizeof(VI)); - SWS = NULL; - ConvertToFormat = PIX_FMT_NONE; this->FPSNum = FPSNum; this->FPSDen = FPSDen; @@ -33,105 +30,92 @@ AvisynthVideoSource::AvisynthVideoSource(const char *SourceFile, int Track, FFIn if (!V) Env->ThrowError(ErrorMsg); - const TVideoProperties VP = *FFMS_GetVideoProperties(V); - - VI.image_type = VideoInfo::IT_TFF; - VI.width = VP.Width; - VI.height = VP.Height; - - if (FPSNum > 0 && FPSDen > 0) { - VI.fps_denominator = FPSDen; - VI.fps_numerator = FPSNum; - VI.num_frames = static_cast(ceil(((VP.LastTime - VP.FirstTime) * FPSNum) / FPSDen)); - } else { - VI.fps_denominator = VP.FPSDenominator; - VI.fps_numerator = VP.FPSNumerator; - VI.num_frames = VP.NumFrames; - } - try { - InitOutputFormat(static_cast(VP.VPixelFormat), Env); + InitOutputFormat(Env); } catch (AvisynthError &) { FFMS_DestroyVideoSource(V); throw; } + const TVideoProperties *VP = FFMS_GetVideoProperties(V); + + if (FPSNum > 0 && FPSDen > 0) { + VI.fps_denominator = FPSDen; + VI.fps_numerator = FPSNum; + VI.num_frames = static_cast(ceil(((VP->LastTime - VP->FirstTime) * FPSNum) / FPSDen)); + } else { + VI.fps_denominator = VP->FPSDenominator; + VI.fps_numerator = VP->FPSNumerator; + VI.num_frames = VP->NumFrames; + } + // Set AR variables - Env->SetVar("FFSAR_NUM", VP.SARNum); - Env->SetVar("FFSAR_DEN", VP.SARDen); - if (VP.SARNum > 0 && VP.SARDen > 0) - Env->SetVar("FFSAR", VP.SARNum / (double)VP.SARDen); + Env->SetVar("FFSAR_NUM", VP->SARNum); + Env->SetVar("FFSAR_DEN", VP->SARDen); + if (VP->SARNum > 0 && VP->SARDen > 0) + Env->SetVar("FFSAR", VP->SARNum / (double)VP->SARDen); // Set crop variables - Env->SetVar("FFCROP_LEFT", VP.CropLeft); - Env->SetVar("FFCROP_RIGHT", VP.CropRight); - Env->SetVar("FFCROP_TOP", VP.CropTop); - Env->SetVar("FFCROP_BOTTOM", VP.CropBottom); + Env->SetVar("FFCROP_LEFT", VP->CropLeft); + Env->SetVar("FFCROP_RIGHT", VP->CropRight); + Env->SetVar("FFCROP_TOP", VP->CropTop); + Env->SetVar("FFCROP_BOTTOM", VP->CropBottom); } AvisynthVideoSource::~AvisynthVideoSource() { - if (SWS) - sws_freeContext(SWS); FFMS_DestroyVideoSource(V); } -void AvisynthVideoSource::InitOutputFormat(enum PixelFormat CurrentFormat, IScriptEnvironment *Env) { - int Loss; - enum PixelFormat BestFormat = avcodec_find_best_pix_fmt((1 << PIX_FMT_YUVJ420P) | (1 << PIX_FMT_YUV420P) | (1 << PIX_FMT_YUYV422) | (1 << PIX_FMT_RGB32) | (1 << PIX_FMT_BGR24), CurrentFormat, 1 /* Required to prevent pointless RGB32 => RGB24 conversion */, &Loss); +void AvisynthVideoSource::InitOutputFormat(IScriptEnvironment *Env) { + const TVideoProperties *VP = FFMS_GetVideoProperties(V); - switch (BestFormat) { - case PIX_FMT_YUVJ420P: // stupid yv12 distinctions, also inexplicably completely undeniably incompatible with all other supported output formats - case PIX_FMT_YUV420P: VI.pixel_type = VideoInfo::CS_I420; break; - case PIX_FMT_YUYV422: VI.pixel_type = VideoInfo::CS_YUY2; break; - case PIX_FMT_RGB32: VI.pixel_type = VideoInfo::CS_BGR32; break; - case PIX_FMT_BGR24: VI.pixel_type = VideoInfo::CS_BGR24; break; - default: - Env->ThrowError("FFVideoSource: No suitable output format found"); - } + if (FFMS_SetOutputFormat(V, (1 << FFMS_GetPixFmt("yuvj420p")) | + (1 << FFMS_GetPixFmt("yuv420p")) | (1 << FFMS_GetPixFmt("yuyv422")) | + (1 << FFMS_GetPixFmt("rgb32")) | (1 << FFMS_GetPixFmt("bgr24")), + VP->Width, VP->Height, NULL, 0)) + Env->ThrowError("FFVideoSource: No suitable output format found"); - if (BestFormat != CurrentFormat) { - ConvertToFormat = BestFormat; - SWS = sws_getContext(VI.width, VI.height, CurrentFormat, VI.width, VI.height, ConvertToFormat, GetCPUFlags() | SWS_BICUBIC, NULL, NULL, NULL); - } + VP = FFMS_GetVideoProperties(V); - if (BestFormat == PIX_FMT_YUVJ420P || BestFormat == PIX_FMT_YUV420P) { + if (VP->VPixelFormat == FFMS_GetPixFmt("yuvj420p") || VP->VPixelFormat == FFMS_GetPixFmt("yuv420p")) + VI.pixel_type = VideoInfo::CS_I420; + else if (VP->VPixelFormat == FFMS_GetPixFmt("yuyv422")) + VI.pixel_type = VideoInfo::CS_YUY2; + else if (VP->VPixelFormat == FFMS_GetPixFmt("rgb32")) + VI.pixel_type = VideoInfo::CS_BGR32; + else if (VP->VPixelFormat == FFMS_GetPixFmt("bgr24")) + VI.pixel_type = VideoInfo::CS_BGR24; + else + Env->ThrowError("FFVideoSource: No suitable output format found"); + + VI.image_type = VideoInfo::IT_TFF; + VI.width = VP->Width; + VI.height = VP->Height; + + // Crop to obey avisynth's even width/height requirements + if (VP->VPixelFormat == FFMS_GetPixFmt("yuvj420p") || VP->VPixelFormat == FFMS_GetPixFmt("yuv420p")) { VI.height -= VI.height & 1; VI.width -= VI.width & 1; } - if (BestFormat == PIX_FMT_YUYV422) { + if (VP->VPixelFormat == FFMS_GetPixFmt("yuyv422")) { VI.width -= VI.width & 1; } } PVideoFrame AvisynthVideoSource::OutputFrame(const TAVFrameLite *Frame, IScriptEnvironment *Env) { // Yes, this function is overly complex and could probably be simplified - AVPicture *SrcPicture = reinterpret_cast(const_cast(Frame)); + TAVFrameLite *SrcPicture = const_cast(Frame); PVideoFrame Dst = Env->NewVideoFrame(VI); - if (ConvertToFormat != PIX_FMT_NONE && VI.pixel_type == VideoInfo::CS_I420) { - uint8_t *DstData[3] = {Dst->GetWritePtr(PLANAR_Y), Dst->GetWritePtr(PLANAR_U), Dst->GetWritePtr(PLANAR_V)}; - int DstStride[3] = {Dst->GetPitch(PLANAR_Y), Dst->GetPitch(PLANAR_U), Dst->GetPitch(PLANAR_V)}; - sws_scale(SWS, SrcPicture->data, SrcPicture->linesize, 0, VI.height, DstData, DstStride); - } else if (ConvertToFormat != PIX_FMT_NONE) { - if (VI.IsRGB()) { - uint8_t *DstData[1] = {Dst->GetWritePtr() + Dst->GetPitch() * (Dst->GetHeight() - 1)}; - int DstStride[1] = {-Dst->GetPitch()}; - sws_scale(SWS, SrcPicture->data, SrcPicture->linesize, 0, VI.height, DstData, DstStride); - } else { - uint8_t *DstData[1] = {Dst->GetWritePtr()}; - int DstStride[1] = {Dst->GetPitch()}; - sws_scale(SWS, SrcPicture->data, SrcPicture->linesize, 0, VI.height, DstData, DstStride); - } - } else if (VI.pixel_type == VideoInfo::CS_I420) { - Env->BitBlt(Dst->GetWritePtr(PLANAR_Y), Dst->GetPitch(PLANAR_Y), SrcPicture->data[0], SrcPicture->linesize[0], Dst->GetRowSize(PLANAR_Y), Dst->GetHeight(PLANAR_Y)); - Env->BitBlt(Dst->GetWritePtr(PLANAR_U), Dst->GetPitch(PLANAR_U), SrcPicture->data[1], SrcPicture->linesize[1], Dst->GetRowSize(PLANAR_U), Dst->GetHeight(PLANAR_U)); - Env->BitBlt(Dst->GetWritePtr(PLANAR_V), Dst->GetPitch(PLANAR_V), SrcPicture->data[2], SrcPicture->linesize[2], Dst->GetRowSize(PLANAR_V), Dst->GetHeight(PLANAR_V)); + if (VI.pixel_type == VideoInfo::CS_I420) { + Env->BitBlt(Dst->GetWritePtr(PLANAR_Y), Dst->GetPitch(PLANAR_Y), SrcPicture->Data[0], SrcPicture->Linesize[0], Dst->GetRowSize(PLANAR_Y), Dst->GetHeight(PLANAR_Y)); + Env->BitBlt(Dst->GetWritePtr(PLANAR_U), Dst->GetPitch(PLANAR_U), SrcPicture->Data[1], SrcPicture->Linesize[1], Dst->GetRowSize(PLANAR_U), Dst->GetHeight(PLANAR_U)); + Env->BitBlt(Dst->GetWritePtr(PLANAR_V), Dst->GetPitch(PLANAR_V), SrcPicture->Data[2], SrcPicture->Linesize[2], Dst->GetRowSize(PLANAR_V), Dst->GetHeight(PLANAR_V)); + } else if (VI.IsRGB()) { + Env->BitBlt(Dst->GetWritePtr() + Dst->GetPitch() * (Dst->GetHeight() - 1), -Dst->GetPitch(), SrcPicture->Data[0], SrcPicture->Linesize[0], Dst->GetRowSize(), Dst->GetHeight()); } else { - if (VI.IsRGB()) - Env->BitBlt(Dst->GetWritePtr() + Dst->GetPitch() * (Dst->GetHeight() - 1), -Dst->GetPitch(), SrcPicture->data[0], SrcPicture->linesize[0], Dst->GetRowSize(), Dst->GetHeight()); - else - Env->BitBlt(Dst->GetWritePtr(), Dst->GetPitch(), SrcPicture->data[0], SrcPicture->linesize[0], Dst->GetRowSize(), Dst->GetHeight()); + Env->BitBlt(Dst->GetWritePtr(), Dst->GetPitch(), SrcPicture->Data[0], SrcPicture->Linesize[0], Dst->GetRowSize(), Dst->GetHeight()); } return Dst; diff --git a/aegisub/FFmpegSource2/ffavisynth.h b/aegisub/FFmpegSource2/ffavisynth.h index 5d03f4ac1..28c93bf7c 100644 --- a/aegisub/FFmpegSource2/ffavisynth.h +++ b/aegisub/FFmpegSource2/ffavisynth.h @@ -21,13 +21,6 @@ #ifndef FFAVISYNTH_H #define FFAVISYNTH_H -extern "C" { -#include -#include -#include -#include -} - #include #include "avisynth.h" #include "ffms.h" @@ -36,12 +29,10 @@ class AvisynthVideoSource : public IClip { private: VideoInfo VI; FFVideo *V; - SwsContext *SWS; - PixelFormat ConvertToFormat; int FPSNum; int FPSDen; - void InitOutputFormat(enum PixelFormat CurrentFormat, IScriptEnvironment *Env); + void InitOutputFormat(IScriptEnvironment *Env); PVideoFrame OutputFrame(const TAVFrameLite *SrcPicture, IScriptEnvironment *Env); public: AvisynthVideoSource(const char *SourceFile, int Track, FFIndex *Index, int FPSNum, int FPSDen, const char *PP, int Threads, int SeekMode, IScriptEnvironment* Env, char *ErrorMsg, unsigned MsgSize); diff --git a/aegisub/FFmpegSource2/ffavsfilters.cpp b/aegisub/FFmpegSource2/ffavsfilters.cpp index 651d49caf..b90a5b21a 100644 --- a/aegisub/FFmpegSource2/ffavsfilters.cpp +++ b/aegisub/FFmpegSource2/ffavsfilters.cpp @@ -138,7 +138,7 @@ static AVSValue __cdecl CreateFFVideoSource(AVSValue Args, void* UserData, IScri Env->ThrowError("FFVideoSource: No video track found"); if (strcmp(Timecodes, "")) { - if (FFMS_WriteTimecodes(FFMS_GetTrackFromIndex(Index, Track, ErrorMsg, MsgSize), Timecodes, ErrorMsg, MsgSize)) { + if (FFMS_WriteTimecodes(FFMS_GetTrackFromIndex(Index, Track), Timecodes, ErrorMsg, MsgSize)) { FFMS_DestroyFFIndex(Index); Env->ThrowError("FFVideoSource: %s", ErrorMsg); } diff --git a/aegisub/FFmpegSource2/ffms.cpp b/aegisub/FFmpegSource2/ffms.cpp index 0662f1561..9bdca5d6e 100644 --- a/aegisub/FFmpegSource2/ffms.cpp +++ b/aegisub/FFmpegSource2/ffms.cpp @@ -126,8 +126,8 @@ FFMS_API(int) FFMS_GetAudio(FFAudio *A, void *Buf, int64_t Start, int64_t Count, return A->GetAudio(Buf, Start, Count, ErrorMsg, MsgSize); } -FFMS_API(int) FFMS_SetOutputFormat(FFVideo *V, int TargetFormat, int Width, int Height, char *ErrorMsg, unsigned MsgSize) { - return V->SetOutputFormat(TargetFormat, Width, Height, ErrorMsg, MsgSize); +FFMS_API(int) FFMS_SetOutputFormat(FFVideo *V, int64_t TargetFormats, int Width, int Height, char *ErrorMsg, unsigned MsgSize) { + return V->SetOutputFormat(TargetFormats, Width, Height, ErrorMsg, MsgSize); } FFMS_API(void) FFMS_ResetOutputFormat(FFVideo *V) { @@ -174,22 +174,12 @@ FFMS_API(int) FFMS_GetNumFrames(FFTrack *T) { return T->size(); } -FFMS_API(const FFFrameInfo *) FFMS_GetFrameInfo(FFTrack *T, int Frame, char *ErrorMsg, unsigned MsgSize) { - if (Frame < 0 || Frame >= static_cast(T->size())) { - _snprintf(ErrorMsg, MsgSize, "Invalid frame specified"); - return NULL; - } else { - return reinterpret_cast(&(*T)[Frame]); - } +FFMS_API(const FFFrameInfo *) FFMS_GetFrameInfo(FFTrack *T, int Frame) { + return reinterpret_cast(&(*T)[Frame]); } -FFMS_API(FFTrack *) FFMS_GetTrackFromIndex(FFIndex *Index, int Track, char *ErrorMsg, unsigned MsgSize) { - if (Track < 0 || Track >= static_cast(Index->size())) { - _snprintf(ErrorMsg, MsgSize, "Invalid track specified"); - return NULL; - } else { - return &(*Index)[Track]; - } +FFMS_API(FFTrack *) FFMS_GetTrackFromIndex(FFIndex *Index, int Track) { + return &(*Index)[Track]; } FFMS_API(FFTrack *) FFMS_GetTrackFromVideo(FFVideo *V) { diff --git a/aegisub/FFmpegSource2/ffms.h b/aegisub/FFmpegSource2/ffms.h index 83843b4fc..1f74268f9 100644 --- a/aegisub/FFmpegSource2/ffms.h +++ b/aegisub/FFmpegSource2/ffms.h @@ -135,7 +135,7 @@ FFMS_API(const TAudioProperties *) FFMS_GetAudioProperties(FFAudio *A); FFMS_API(const TAVFrameLite *) FFMS_GetFrame(FFVideo *V, int n, char *ErrorMsg, unsigned MsgSize); FFMS_API(const TAVFrameLite *) FFMS_GetFrameByTime(FFVideo *V, double Time, char *ErrorMsg, unsigned MsgSize); FFMS_API(int) FFMS_GetAudio(FFAudio *A, void *Buf, int64_t Start, int64_t Count, char *ErrorMsg, unsigned MsgSize); -FFMS_API(int) FFMS_SetOutputFormat(FFVideo *V, int TargetFormat, int Width, int Height, char *ErrorMsg, unsigned MsgSize); +FFMS_API(int) FFMS_SetOutputFormat(FFVideo *V, int64_t TargetFormats, int Width, int Height, char *ErrorMsg, unsigned MsgSize); FFMS_API(void) FFMS_ResetOutputFormat(FFVideo *V); FFMS_API(void) FFMS_DestroyFFIndex(FFIndex *Index); FFMS_API(int) FFMS_GetFirstTrackOfType(FFIndex *Index, int TrackType, char *ErrorMsg, unsigned MsgSize); @@ -146,8 +146,8 @@ FFMS_API(FFMS_TrackType) FFMS_GetTrackType(FFTrack *T); FFMS_API(FFMS_TrackType) FFMS_GetTrackTypeI(FFIndexer *Indexer, int Track); FFMS_API(const char *) FFMS_CodecName(FFIndexer *Indexer, int Track); FFMS_API(int) FFMS_GetNumFrames(FFTrack *T); -FFMS_API(const FFFrameInfo *) FFMS_GetFrameInfo(FFTrack *T, int Frame, char *ErrorMsg, unsigned MsgSize); -FFMS_API(FFTrack *) FFMS_GetTrackFromIndex(FFIndex *Index, int Track, char *ErrorMsg, unsigned MsgSize); +FFMS_API(const FFFrameInfo *) FFMS_GetFrameInfo(FFTrack *T, int Frame); +FFMS_API(FFTrack *) FFMS_GetTrackFromIndex(FFIndex *Index, int Track); FFMS_API(FFTrack *) FFMS_GetTrackFromVideo(FFVideo *V); FFMS_API(FFTrack *) FFMS_GetTrackFromAudio(FFAudio *A); FFMS_API(const TTrackTimeBase *) FFMS_GetTimeBase(FFTrack *T); diff --git a/aegisub/FFmpegSource2/ffvideosource.cpp b/aegisub/FFmpegSource2/ffvideosource.cpp index d8c1bcca8..adb0319d3 100644 --- a/aegisub/FFmpegSource2/ffvideosource.cpp +++ b/aegisub/FFmpegSource2/ffvideosource.cpp @@ -118,15 +118,14 @@ TAVFrameLite *FFVideo::GetFrameByTime(double Time, char *ErrorMsg, unsigned MsgS return GetFrame(Frame, ErrorMsg, MsgSize); } -int FFVideo::SetOutputFormat(int TargetFormats, int Width, int Height, char *ErrorMsg, unsigned MsgSize) { -// FIXME: investigate the possible bug in avcodec_find_best_pix_fmt -// int Loss; -// int OutputFormat = avcodec_find_best_pix_fmt(TargetFormats, -// CodecContext->pix_fmt, 1 /* Required to prevent pointless RGB32 => RGB24 conversion */, &Loss); -// if (OutputFormat == -1) -// return -1; - - PixelFormat OutputFormat = static_cast(TargetFormats); +int FFVideo::SetOutputFormat(int64_t TargetFormats, int Width, int Height, char *ErrorMsg, unsigned MsgSize) { + int Loss; + PixelFormat OutputFormat = avcodec_find_best_pix_fmt(TargetFormats, + CodecContext->pix_fmt, 1 /* Required to prevent pointless RGB32 => RGB24 conversion */, &Loss); + if (OutputFormat == PIX_FMT_NONE) { + _snprintf(ErrorMsg, MsgSize, "No suitable output format found"); + return -1; + } SwsContext *NewSWS = NULL; if (CodecContext->pix_fmt != OutputFormat || Width != CodecContext->width || Height != CodecContext->height) { diff --git a/aegisub/FFmpegSource2/ffvideosource.h b/aegisub/FFmpegSource2/ffvideosource.h index ee297e995..c4f272585 100644 --- a/aegisub/FFmpegSource2/ffvideosource.h +++ b/aegisub/FFmpegSource2/ffvideosource.h @@ -69,7 +69,7 @@ public: FFTrack *GetFFTrack() { return &Frames; } virtual TAVFrameLite *GetFrame(int n, char *ErrorMsg, unsigned MsgSize) = 0; TAVFrameLite *GetFrameByTime(double Time, char *ErrorMsg, unsigned MsgSize); - int SetOutputFormat(int TargetFormats, int Width, int Height, char *ErrorMsg, unsigned MsgSize); + int SetOutputFormat(int64_t TargetFormats, int Width, int Height, char *ErrorMsg, unsigned MsgSize); void ResetOutputFormat(); }; diff --git a/aegisub/FFmpegSource2/indexing.cpp b/aegisub/FFmpegSource2/indexing.cpp index 242c1fa1d..b9f396c97 100644 --- a/aegisub/FFmpegSource2/indexing.cpp +++ b/aegisub/FFmpegSource2/indexing.cpp @@ -511,6 +511,14 @@ FFIndexer *FFIndexer::CreateFFIndexer(const char *Filename, char *ErrorMsg, unsi return new FFLAVFIndexer(Filename, FormatContext, ErrorMsg, MsgSize); } +FFIndexer::FFIndexer() { + DecodingBuffer = new int16_t[AVCODEC_MAX_AUDIO_FRAME_SIZE * 5]; +} + +FFIndexer::~FFIndexer() { + delete[] DecodingBuffer; +} + FFLAVFIndexer::FFLAVFIndexer(const char *Filename, AVFormatContext *FormatContext, char *ErrorMsg, unsigned MsgSize) { SourceFile = Filename; this->FormatContext = FormatContext; diff --git a/aegisub/FFmpegSource2/indexing.h b/aegisub/FFmpegSource2/indexing.h index 72349009c..7c381b1ee 100644 --- a/aegisub/FFmpegSource2/indexing.h +++ b/aegisub/FFmpegSource2/indexing.h @@ -24,7 +24,7 @@ #include "utils.h" #include "wave64writer.h" -#define INDEXVERSION 25 +#define INDEXVERSION 26 #define INDEXID 0x53920873 struct IndexHeader { @@ -71,8 +71,8 @@ protected: bool WriteAudio(SharedAudioContext &AudioContext, FFIndex *Index, int Track, int DBSize, char *ErrorMsg, unsigned MsgSize); public: static FFIndexer *CreateFFIndexer(const char *Filename, char *ErrorMsg, unsigned MsgSize); - FFIndexer() { DecodingBuffer = new int16_t[AVCODEC_MAX_AUDIO_FRAME_SIZE * 5]; } - virtual ~FFIndexer() { delete[] DecodingBuffer; } + FFIndexer(); + virtual ~FFIndexer(); void SetIndexMask(int IndexMask) { this->IndexMask = IndexMask; } void SetDumpMask(int DumpMask) { this->DumpMask = DumpMask; } void SetIgnoreDecodeErrors(bool IgnoreDecodeErrors) { this->IgnoreDecodeErrors = IgnoreDecodeErrors; } diff --git a/aegisub/FFmpegSource2/utils.cpp b/aegisub/FFmpegSource2/utils.cpp index 1158b5616..4c443c81e 100644 --- a/aegisub/FFmpegSource2/utils.cpp +++ b/aegisub/FFmpegSource2/utils.cpp @@ -156,17 +156,17 @@ int FFIndex::WriteIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize) IndexStream.write(reinterpret_cast(&IH), sizeof(IH)); for (unsigned int i = 0; i < IH.Tracks; i++) { - int TT = at(i).TT; + FFMS_TrackType TT = at(i).TT; IndexStream.write(reinterpret_cast(&TT), sizeof(TT)); int64_t Num = at(i).TB.Num; IndexStream.write(reinterpret_cast(&Num), sizeof(Num)); int64_t Den = at(i).TB.Den; IndexStream.write(reinterpret_cast(&Den), sizeof(Den)); - size_t Frames = at(i).size(); + int64_t Frames = at(i).size(); IndexStream.write(reinterpret_cast(&Frames), sizeof(Frames)); - for (size_t j = 0; j < Frames; j++) - IndexStream.write(reinterpret_cast(&(at(i)[j])), sizeof(TFrameInfo)); + for (FFTrack::iterator Cur=at(i).begin(); Cur!=at(i).end(); Cur++) + IndexStream.write(reinterpret_cast(&*Cur), sizeof(TFrameInfo)); } return 0; @@ -211,7 +211,7 @@ int FFIndex::ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize) Index.read(reinterpret_cast(&Num), sizeof(Num)); int64_t Den; Index.read(reinterpret_cast(&Den), sizeof(Den)); - size_t Frames; + int64_t Frames; Index.read(reinterpret_cast(&Frames), sizeof(Frames)); push_back(FFTrack(Num, Den, TT)); diff --git a/aegisub/src/audio_provider_ffmpegsource.cpp b/aegisub/src/audio_provider_ffmpegsource.cpp index db3884b5a..7e11b27a4 100644 --- a/aegisub/src/audio_provider_ffmpegsource.cpp +++ b/aegisub/src/audio_provider_ffmpegsource.cpp @@ -98,7 +98,7 @@ void FFmpegSourceAudioProvider::LoadAudio(Aegisub::String filename) { } for (int i = 0; i < NumTracks; i++) { - FFTrack *FrameData = FFMS_GetTrackFromIndex(Index, i, FFMSErrMsg, MsgSize); + FFTrack *FrameData = FFMS_GetTrackFromIndex(Index, i); if (FrameData == NULL) { FFMS_DestroyFFIndex(Index); Index = NULL; diff --git a/aegisub/src/video_provider_ffmpegsource.cpp b/aegisub/src/video_provider_ffmpegsource.cpp index d4e50639f..c52794e80 100644 --- a/aegisub/src/video_provider_ffmpegsource.cpp +++ b/aegisub/src/video_provider_ffmpegsource.cpp @@ -166,7 +166,7 @@ void FFmpegSourceVideoProvider::LoadVideo(Aegisub::String filename, double fps) // build list of keyframes and timecodes for (int CurFrameNum = 0; CurFrameNum < VideoInfo->NumFrames; CurFrameNum++) { - CurFrameData = FFMS_GetFrameInfo(FrameData, CurFrameNum, FFMSErrorMessage, MessageSize); + CurFrameData = FFMS_GetFrameInfo(FrameData, CurFrameNum); if (CurFrameData == NULL) { wxString temp(FFMSErrorMessage, wxConvUTF8); ErrorMsg << _T("Couldn't get framedata for frame ") << CurFrameNum << _T(": ") << temp; @@ -254,7 +254,7 @@ const AegiVideoFrame FFmpegSourceVideoProvider::GetFrame(int _n, int FormatType) // requested format was changed since last time we were called, (re)set output format if (LastDstFormat != DstFormat) { - if (FFMS_SetOutputFormat(VideoSource, DstFormat, w, h, FFMSErrorMessage, MessageSize)) { + if (FFMS_SetOutputFormat(VideoSource, 1 << DstFormat, w, h, FFMSErrorMessage, MessageSize)) { wxString temp(FFMSErrorMessage, wxConvUTF8); ErrorMsg << _T("Failed to set output format: ") << temp; throw ErrorMsg;