diff --git a/FFmpegSource2/ffavisynth.h b/FFmpegSource2/ffavisynth.h index 6e592431d..28d4afc7d 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 bbc0c25fb..1161a1dd5 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 27c9f1a2c..ff6fd2770 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 9347b20f1..7c017c569 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 4e53ea092..52b520647 100644 --- a/FFmpegSource2/ffmpegsource2.html +++ b/FFmpegSource2/ffms2.html @@ -186,8 +186,16 @@ Note that --enable-w32threads is required for multithreaded decoding to work.

Changes

diff --git a/FFmpegSource2/ffvideosource.cpp b/FFmpegSource2/ffvideosource.cpp index b60a1ce46..77f21bbb7 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 850802ae2..dd97489ec 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();