diff --git a/FFmpegSource2/ffavisynth.h b/FFmpegSource2/ffavisynth.h index 6e592431d4623f681219beff1fdeced116a3aead..28d4afc7d59310ab0103eaa6a28bcdbd0d5a4ec9 100644 --- a/FFmpegSource2/ffavisynth.h +++ b/FFmpegSource2/ffavisynth.h @@ -44,7 +44,6 @@ private: public: AvisynthVideoSource(const char *SourceFile, int Track, FrameIndex *TrackIndices, const char *PP, int Threads, int SeekMode, IScriptEnvironment* Env, char *ErrorMsg, unsigned MsgSize); ~AvisynthVideoSource(); - int GetTrack() { return FFMS_GetVSTrack(VS); } bool __stdcall GetParity(int n) { return false; } void __stdcall SetCacheHints(int cachehints, int frame_range) { } const VideoInfo& __stdcall GetVideoInfo() { return VI; } @@ -59,7 +58,6 @@ private: public: AvisynthAudioSource(const char *SourceFile, int Track, FrameIndex *TrackIndices, IScriptEnvironment* Env, char *ErrorMsg, unsigned MsgSize); ~AvisynthAudioSource(); - int GetTrack() { return FFMS_GetASTrack(AS); } bool __stdcall GetParity(int n) { return false; } void __stdcall SetCacheHints(int cachehints, int frame_range) { } const VideoInfo& __stdcall GetVideoInfo() { return VI; } diff --git a/FFmpegSource2/ffavsfilters.cpp b/FFmpegSource2/ffavsfilters.cpp index bbc0c25fbdd7b8b81b6548a988815f06b501371e..1161a1dd53e294a10bde50d0c3efe3abc860c251 100644 --- a/FFmpegSource2/ffavsfilters.cpp +++ b/FFmpegSource2/ffavsfilters.cpp @@ -130,6 +130,18 @@ AVSValue __cdecl CreateFFVideoSource(AVSValue Args, void* UserData, IScriptEnvir } } + if (Track == -1) + Track = FFMS_GetFirstTrackOfType(Index, FFMS_TYPE_VIDEO, ErrorMsg, MsgSize); + if (Track < 0) + Env->ThrowError("FFVideoSource: No video track found"); + + if (strcmp(Timecodes, "")) { + if (FFMS_WriteTimecodes(FFMS_GetTITrackIndex(Index, Track, ErrorMsg, MsgSize), Timecodes, ErrorMsg, MsgSize)) { + FFMS_DestroyFrameIndex(Index); + Env->ThrowError("FFVideoSource: %s", ErrorMsg); + } + } + AvisynthVideoSource *Filter; try { @@ -139,14 +151,6 @@ AVSValue __cdecl CreateFFVideoSource(AVSValue Args, void* UserData, IScriptEnvir throw; } - if (strcmp(Timecodes, "")) { - if (FFMS_WriteTimecodes(FFMS_GetTITrackIndex(Index, Filter->GetTrack(), ErrorMsg, MsgSize), Timecodes, ErrorMsg, MsgSize)) { - FFMS_DestroyFrameIndex(Index); - delete Filter; - Env->ThrowError("FFVideoSource: %s", ErrorMsg); - } - } - FFMS_DestroyFrameIndex(Index); return Filter; } @@ -187,6 +191,11 @@ AVSValue __cdecl CreateFFAudioSource(AVSValue Args, void* UserData, IScriptEnvir } } + if (Track == -1) + Track = FFMS_GetFirstTrackOfType(Index, FFMS_TYPE_AUDIO, ErrorMsg, MsgSize); + if (Track < 0) + Env->ThrowError("FFAudioSource: No audio track found"); + AvisynthAudioSource *Filter; try { diff --git a/FFmpegSource2/ffms.cpp b/FFmpegSource2/ffms.cpp index 27c9f1a2c695bc0979e703e860a05e81f81705b5..ff6fd2770f655ed43a93f503624a89cd4f384e56 100644 --- a/FFmpegSource2/ffms.cpp +++ b/FFmpegSource2/ffms.cpp @@ -90,16 +90,6 @@ FFMS_API(void) FFMS_DestroyAudioSource(AudioBase *AB) { delete AB; } -FFMS_API(int) FFMS_GetVSTrack(VideoBase *VB) { - return VB->GetTrack(); -} - -FFMS_API(int) FFMS_GetASTrack(AudioBase *AB) { - // FIXME - // return AB->GetTrack(); - return 0; -} - FFMS_API(const VideoProperties *) FFMS_GetVideoProperties(VideoBase *VB) { return &VB->GetVideoProperties(); } @@ -132,6 +122,14 @@ FFMS_API(void) FFMS_DestroyFrameIndex(FrameIndex *FI) { delete FI; } +FFMS_API(int) FFMS_GetFirstTrackOfType(FrameIndex *TrackIndices, int TrackType, char *ErrorMsg, unsigned MsgSize) { + for (int i = 0; i < TrackIndices->size(); i++) + if ((*TrackIndices)[i].TT == TrackType) + return i; + _snprintf(ErrorMsg, MsgSize, "No suitable track found"); + return -1; +} + FFMS_API(int) FFMS_GetNumTracks(FrameIndex *TrackIndices, char *ErrorMsg, unsigned MsgSize) { return TrackIndices->size(); } diff --git a/FFmpegSource2/ffms.h b/FFmpegSource2/ffms.h index 9347b20f1d1166e9ff32c59d2872e523b4c34668..7c017c56915df98aea1cbad0d9a47c00905e4657 100644 --- a/FFmpegSource2/ffms.h +++ b/FFmpegSource2/ffms.h @@ -145,6 +145,8 @@ struct VideoProperties { int CropBottom; int CropLeft; int CropRight; + double FirstTime; + double LastTime; }; struct AudioProperties { @@ -160,8 +162,6 @@ FFMS_API(VideoBase *) FFMS_CreateVideoSource(const char *SourceFile, int Track, FFMS_API(AudioBase *) FFMS_CreateAudioSource(const char *SourceFile, int Track, FrameIndex *TrackIndices, char *ErrorMsg, unsigned MsgSize); FFMS_API(void) FFMS_DestroyVideoSource(VideoBase *VB); FFMS_API(void) FFMS_DestroyAudioSource(AudioBase *AB); -FFMS_API(int) FFMS_GetVSTrack(VideoBase *VB); -FFMS_API(int) FFMS_GetASTrack(AudioBase *AB); FFMS_API(const VideoProperties *) FFMS_GetVideoProperties(VideoBase *VB); FFMS_API(const AudioProperties *) FFMS_GetAudioProperties(AudioBase *AB); FFMS_API(const AVFrameLite *) FFMS_GetFrame(VideoBase *VB, int n, char *ErrorMsg, unsigned MsgSize); @@ -170,6 +170,7 @@ FFMS_API(int) FFMS_GetAudio(AudioBase *AB, void *Buf, int64_t Start, int64_t Cou FFMS_API(int) FFMS_SetOutputFormat(VideoBase *VB, int TargetFormat, int Width, int Height); FFMS_API(void) FFMS_ResetOutputFormat(VideoBase *VB); FFMS_API(void) FFMS_DestroyFrameIndex(FrameIndex *FI); +FFMS_API(int) FFMS_GetFirstTrackOfType(FrameIndex *TrackIndices, int TrackType, char *ErrorMsg, unsigned MsgSize); FFMS_API(int) FFMS_GetNumTracks(FrameIndex *TrackIndices, char *ErrorMsg, unsigned MsgSize); FFMS_API(int) FFMS_GetTrackType(FrameInfoVector *FIV, char *ErrorMsg, unsigned MsgSize); FFMS_API(int) FFMS_GetNumFrames(FrameInfoVector *FIV, char *ErrorMsg, unsigned MsgSize); diff --git a/FFmpegSource2/ffmpegsource2.html b/FFmpegSource2/ffms2.html similarity index 95% rename from FFmpegSource2/ffmpegsource2.html rename to FFmpegSource2/ffms2.html index 4e53ea092aeaa0f1d28f1cc3dc0b9016f47a018e..52b5206476312d86b2565e4cb1637605f36d78ee 100644 --- a/FFmpegSource2/ffmpegsource2.html +++ b/FFmpegSource2/ffms2.html @@ -186,8 +186,16 @@ Note that --enable-w32threads is required for multithreaded decoding to work. <h2>Changes</h2> <ul> + +<li>2.00 beta 3<ul> +<li>Added a VFR to CFR mode</li> +<li>Readded FFAudioSource support for other containers (glitches still present as in previous versions but should be better now)</li> +<li>Renamed the dll to FFMS2.dll, FFMS2 is now the official short name of the project</li> +<li>Updated FFmpeg to rev X</li> +</ul></li> + <li>2.00 beta 2<ul> -<ll>More API changes (and more are likely to come)</li> +<li>More API changes (and more are likely to come)</li> <li>Includes a simple CLI indexing application</li> <li>FFIndex now takes a few more arguments</li> <li>Readded FFAudioSource (only matroska supported for now)</li> @@ -199,6 +207,7 @@ Note that --enable-w32threads is required for multithreaded decoding to work. <li>Rewrote most things</li> <li>Updated FFmpeg to rev 15301</li> </ul></li> + </ul> </body> diff --git a/FFmpegSource2/ffvideosource.cpp b/FFmpegSource2/ffvideosource.cpp index b60a1ce463cd56eaea7f74399a3048d7bb480c47..77f21bbb71e94e6b695a90322627c039cf05879c 100644 --- a/FFmpegSource2/ffvideosource.cpp +++ b/FFmpegSource2/ffvideosource.cpp @@ -165,34 +165,6 @@ void VideoBase::ResetOutputFormat() { VP.PixelFormat = CodecContext->pix_fmt; } -int FFVideoSource::GetTrackIndex(int &Index, char *ErrorMsg, unsigned MsgSize) { - if (Index < 0) { - Index = -1; - for (unsigned int i = 0; i < FormatContext->nb_streams; i++) - if (FormatContext->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) { - Index = i; - break; - } - } - - if (Index < 0) { - _snprintf(ErrorMsg, MsgSize, "No video track found"); - return 1; - } - - if (Index >= (int)FormatContext->nb_streams) { - _snprintf(ErrorMsg, MsgSize, "Invalid video track number"); - return 2; - } - - if (FormatContext->streams[Index]->codec->codec_type != CODEC_TYPE_VIDEO) { - _snprintf(ErrorMsg, MsgSize, "Selected track is not video"); - return 3; - } - - return 0; -} - void FFVideoSource::Free(bool CloseCodec) { if (CloseCodec) avcodec_close(CodecContext); @@ -207,6 +179,13 @@ FFVideoSource::FFVideoSource(const char *SourceFile, int Track, FrameIndex *Trac FormatContext = NULL; AVCodec *Codec = NULL; this->SeekMode = SeekMode; + VideoTrack = Track; + Frames = (*TrackIndices)[VideoTrack]; + + if (Frames.size() == 0) { + _snprintf(ErrorMsg, MsgSize, "Video track contains no frames"); + throw ErrorMsg; + } if (av_open_input_file(&FormatContext, SourceFile, NULL, 0, NULL) != 0) { _snprintf(ErrorMsg, MsgSize, "Couldn't open '%s'", SourceFile); @@ -219,20 +198,6 @@ FFVideoSource::FFVideoSource(const char *SourceFile, int Track, FrameIndex *Trac throw ErrorMsg; } - VideoTrack = Track; - if (GetTrackIndex(VideoTrack, ErrorMsg, MsgSize)) { - Free(false); - throw ErrorMsg; - } - - Frames = (*TrackIndices)[VideoTrack]; - - if (Frames.size() == 0) { - Free(false); - _snprintf(ErrorMsg, MsgSize, "Video track contains no frames"); - throw ErrorMsg; - } - if (SeekMode >= 0 && av_seek_frame(FormatContext, VideoTrack, Frames[0].DTS, AVSEEK_FLAG_BACKWARD) < 0) { Free(false); _snprintf(ErrorMsg, MsgSize, "Video track is unseekable"); @@ -400,35 +365,6 @@ AVFrameLite *FFVideoSource::GetFrame(int n, char *ErrorMsg, unsigned MsgSize) { return OutputFrame(DecodeFrame); } - -int MatroskaVideoSource::GetTrackIndex(int &Index, char *ErrorMsg, unsigned MsgSize) { - if (Index < 0) { - Index = -1; - for (unsigned int i = 0; i < mkv_GetNumTracks(MF); i++) - if (mkv_GetTrackInfo(MF, i)->Type == TT_VIDEO) { - Index = i; - break; - } - } - - if (Index < 0) { - _snprintf(ErrorMsg, MsgSize, "No video track found"); - return 1; - } - - if (Index >= (int)mkv_GetNumTracks(MF)) { - _snprintf(ErrorMsg, MsgSize, "Invalid video track number"); - return 2; - } - - if (mkv_GetTrackInfo(MF, Index)->Type != TT_VIDEO) { - _snprintf(ErrorMsg, MsgSize, "Selected track is not video"); - return 3; - } - - return 0; -} - void MatroskaVideoSource::Free(bool CloseCodec) { if (CS) cs_Destroy(CS); @@ -449,6 +385,13 @@ MatroskaVideoSource::MatroskaVideoSource(const char *SourceFile, int Track, CodecContext = NULL; TrackInfo *TI = NULL; CS = NULL; + VideoTrack = Track; + Frames = (*TrackIndices)[VideoTrack]; + + if (Frames.size() == 0) { + _snprintf(ErrorMsg, MsgSize, "Video track contains no frames"); + throw ErrorMsg; + } MC.ST.fp = fopen(SourceFile, "rb"); if (MC.ST.fp == NULL) { @@ -465,20 +408,6 @@ MatroskaVideoSource::MatroskaVideoSource(const char *SourceFile, int Track, throw ErrorMsg; } - VideoTrack = Track; - if (GetTrackIndex(VideoTrack, ErrorMsg, MsgSize)) { - Free(false); - throw ErrorMsg; - } - - Frames = (*TrackIndices)[VideoTrack]; - - if (Frames.size() == 0) { - Free(false); - _snprintf(ErrorMsg, MsgSize, "Video track contains no frames"); - throw ErrorMsg; - } - mkv_SetTrackMask(MF, ~(1 << VideoTrack)); TI = mkv_GetTrackInfo(MF, VideoTrack); diff --git a/FFmpegSource2/ffvideosource.h b/FFmpegSource2/ffvideosource.h index 850802ae202d74e97beaf464e8ba4dc0768c5eb6..dd97489ec67e9f5b3b28038c01a1aed77786934b 100644 --- a/FFmpegSource2/ffvideosource.h +++ b/FFmpegSource2/ffvideosource.h @@ -55,7 +55,6 @@ protected: public: virtual ~VideoBase(); const VideoProperties& GetVideoProperties() { return VP; } - int GetTrack() { return VideoTrack; } FrameInfoVector *GetFrameInfoVector() { return &Frames; } virtual AVFrameLite *GetFrame(int n, char *ErrorMsg, unsigned MsgSize) = 0; AVFrameLite *GetFrameByTime(double Time, char *ErrorMsg, unsigned MsgSize); @@ -69,7 +68,6 @@ private: int SeekMode; void Free(bool CloseCodec); - int GetTrackIndex(int &Index, char *ErrorMsg, unsigned MsgSize); int DecodeNextFrame(AVFrame *Frame, int64_t *DTS, char *ErrorMsg, unsigned MsgSize); public: FFVideoSource(const char *SourceFile, int Track, FrameIndex *TrackIndices, const char *PP, int Threads, int SeekMode, char *ErrorMsg, unsigned MsgSize); @@ -86,7 +84,6 @@ private: void Free(bool CloseCodec); int DecodeNextFrame(AVFrame *AFrame, int64_t *AFirstStartTime, char *ErrorMsg, unsigned MsgSize); - int GetTrackIndex(int &Index, char *ErrorMsg, unsigned MsgSize); public: MatroskaVideoSource(const char *SourceFile, int Track, FrameIndex *TrackIndices, const char *PP, int Threads, char *ErrorMsg, unsigned MsgSize); ~MatroskaVideoSource();