FFmpegSource2: change the api a bit more

Originally committed to SVN as r2393.
This commit is contained in:
Fredrik Mellbin 2008-09-27 19:05:10 +00:00
parent fc878f0027
commit 19f50659b6
7 changed files with 52 additions and 111 deletions

View File

@ -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; }

View File

@ -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 {

View File

@ -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();
}

View File

@ -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);

View File

@ -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>

View File

@ -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);

View File

@ -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();