FFmpegSource2: more api stuff
Originally committed to SVN as r2384.
This commit is contained in:
parent
82810de584
commit
950c88cf77
5 changed files with 26 additions and 22 deletions
|
@ -42,9 +42,10 @@ AVSValue __cdecl CreateFFIndex(AVSValue Args, void* UserData, IScriptEnvironment
|
|||
|
||||
const char *Source = Args[0].AsString();
|
||||
const char *CacheFile = Args[1].AsString("");
|
||||
int TrackMask = Args[2].AsInt(0);
|
||||
const char *AudioFile = Args[3].AsString("");
|
||||
bool OverWrite = Args[4].AsBool(false);
|
||||
int IndexMask = Args[2].AsInt(0);
|
||||
int DumpMask = Args[3].AsInt(0);
|
||||
const char *AudioFile = Args[4].AsString("");
|
||||
bool OverWrite = Args[5].AsBool(false);
|
||||
|
||||
std::string DefaultCache(Source);
|
||||
DefaultCache.append(".ffindex");
|
||||
|
@ -61,7 +62,7 @@ AVSValue __cdecl CreateFFIndex(AVSValue Args, void* UserData, IScriptEnvironment
|
|||
|
||||
FrameIndex *Index;
|
||||
if (OverWrite || !(Index = FFMS_ReadIndex(CacheFile, ErrorMsg, MsgSize))) {
|
||||
if (!(Index = FFMS_MakeIndex(Source, TrackMask, AudioFile, NULL, NULL, ErrorMsg, MsgSize)))
|
||||
if (!(Index = FFMS_MakeIndex(Source, IndexMask, DumpMask, AudioFile, NULL, NULL, ErrorMsg, MsgSize)))
|
||||
Env->ThrowError("FFIndex: %s", ErrorMsg);
|
||||
if (FFMS_WriteIndex(CacheFile, Index, ErrorMsg, MsgSize)) {
|
||||
FFMS_DestroyFrameIndex(Index);
|
||||
|
@ -118,7 +119,7 @@ AVSValue __cdecl CreateFFVideoSource(AVSValue Args, void* UserData, IScriptEnvir
|
|||
FrameIndex *Index;
|
||||
if (Cache) {
|
||||
if (!(Index = FFMS_ReadIndex(CacheFile, ErrorMsg, MsgSize))) {
|
||||
if (!(Index = FFMS_MakeIndex(Source, 0, NULL, NULL, NULL, ErrorMsg, MsgSize)))
|
||||
if (!(Index = FFMS_MakeIndex(Source, 0, 0, NULL, NULL, NULL, ErrorMsg, MsgSize)))
|
||||
Env->ThrowError("FFVideoSource: %s", ErrorMsg);
|
||||
|
||||
if (Cache)
|
||||
|
@ -175,7 +176,7 @@ AVSValue __cdecl CreateFFAudioSource(AVSValue Args, void* UserData, IScriptEnvir
|
|||
FrameIndex *Index;
|
||||
if (Cache) {
|
||||
if (!(Index = FFMS_ReadIndex(CacheFile, ErrorMsg, MsgSize))) {
|
||||
if (!(Index = FFMS_MakeIndex(Source, -1, CacheFile, NULL, NULL, ErrorMsg, MsgSize)))
|
||||
if (!(Index = FFMS_MakeIndex(Source, -1, 0, CacheFile, NULL, NULL, ErrorMsg, MsgSize)))
|
||||
Env->ThrowError("FFAudioSource: %s", ErrorMsg);
|
||||
|
||||
if (Cache)
|
||||
|
@ -208,7 +209,7 @@ AVSValue __cdecl CreateSWScale(AVSValue Args, void* UserData, IScriptEnvironment
|
|||
}
|
||||
|
||||
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* Env) {
|
||||
Env->AddFunction("FFIndex", "[source]s[cachefile]s[trackmask]i[audiofile]s[overwrite]b", CreateFFIndex, 0);
|
||||
Env->AddFunction("FFIndex", "[source]s[cachefile]s[indexmask]i[dumpmask]i[audiofile]s[overwrite]b", CreateFFIndex, 0);
|
||||
Env->AddFunction("FFVideoSource", "[source]s[track]i[cache]b[cachefile]s[pp]s[threads]i[timecodes]s[seekmode]i", CreateFFVideoSource, 0);
|
||||
Env->AddFunction("FFAudioSource", "[source]s[track]i[cache]b[cachefile]s", CreateFFAudioSource, 0);
|
||||
Env->AddFunction("FFPP", "c[pp]s", CreateFFPP, 0);
|
||||
|
|
|
@ -163,8 +163,8 @@ FFMS_API(int) FFMS_WriteTimecodes(FrameInfoVector *FIV, const char *TimecodeFile
|
|||
return FIV->WriteTimecodes(TimecodeFile, ErrorMsg, MsgSize);
|
||||
}
|
||||
|
||||
FFMS_API(FrameIndex *) FFMS_MakeIndex(const char *SourceFile, int AudioTrackMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize) {
|
||||
return MakeIndex(SourceFile, AudioTrackMask, AudioFile, IP, Private, ErrorMsg, MsgSize);
|
||||
FFMS_API(FrameIndex *) FFMS_MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize) {
|
||||
return MakeIndex(SourceFile, IndexMask, DumpMask, AudioFile, IP, Private, ErrorMsg, MsgSize);
|
||||
}
|
||||
|
||||
FFMS_API(FrameIndex *) FFMS_ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize) {
|
||||
|
|
|
@ -182,7 +182,7 @@ FFMS_API(int) FFMS_FrameFromDTS(FrameInfoVector *FIV, int64_t DTS, char *ErrorMs
|
|||
FFMS_API(int) FFMS_ClosestFrameFromDTS(FrameInfoVector *FIV, int64_t DTS, char *ErrorMsg, unsigned MsgSize);
|
||||
FFMS_API(const TrackTimeBase *) FFMS_GetTimeBase(FrameInfoVector *FIV, char *ErrorMsg, unsigned MsgSize);
|
||||
FFMS_API(int) FFMS_WriteTimecodes(FrameInfoVector *FIV, const char *TimecodeFile, char *ErrorMsg, unsigned MsgSize);
|
||||
FFMS_API(FrameIndex *) FFMS_MakeIndex(const char *SourceFile, int AudioTrackMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize);
|
||||
FFMS_API(FrameIndex *) FFMS_MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize);
|
||||
FFMS_API(FrameIndex *) FFMS_ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize);
|
||||
FFMS_API(int) FFMS_WriteIndex(const char *IndexFile, FrameIndex *TrackIndices, char *ErrorMsg, unsigned MsgSize);
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ int WriteIndex(const char *IndexFile, FrameIndex *TrackIndices, char *ErrorMsg,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FrameIndex *MakeMatroskaIndex(const char *SourceFile, int AudioTrackMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize) {
|
||||
static FrameIndex *MakeMatroskaIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize) {
|
||||
MatroskaFile *MF;
|
||||
char ErrorMessage[256];
|
||||
MatroskaReaderContext MC;
|
||||
|
@ -161,7 +161,7 @@ static FrameIndex *MakeMatroskaIndex(const char *SourceFile, int AudioTrackMask,
|
|||
IndexMemory IM = IndexMemory(mkv_GetNumTracks(MF), db, AudioContexts);
|
||||
|
||||
for (unsigned int i = 0; i < mkv_GetNumTracks(MF); i++) {
|
||||
if (AudioTrackMask & (1 << i) && mkv_GetTrackInfo(MF, i)->Type == TT_AUDIO) {
|
||||
if (IndexMask & (1 << i) && mkv_GetTrackInfo(MF, i)->Type == TT_AUDIO) {
|
||||
AVCodecContext *AudioCodecContext = avcodec_alloc_context();
|
||||
AudioCodecContext->extradata = (uint8_t *)mkv_GetTrackInfo(MF, i)->CodecPrivate;
|
||||
AudioCodecContext->extradata_size = mkv_GetTrackInfo(MF, i)->CodecPrivateSize;
|
||||
|
@ -186,7 +186,8 @@ static FrameIndex *MakeMatroskaIndex(const char *SourceFile, int AudioTrackMask,
|
|||
return NULL;
|
||||
}
|
||||
} else {
|
||||
AudioTrackMask &= ~(1 << i);
|
||||
IndexMask &= ~(1 << i);
|
||||
DumpMask &= ~(1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,7 +221,7 @@ static FrameIndex *MakeMatroskaIndex(const char *SourceFile, int AudioTrackMask,
|
|||
if (mkv_GetTrackInfo(MF, Track)->Type == TT_VIDEO)
|
||||
(*TrackIndices)[Track].push_back(FrameInfo(StartTime, (FrameFlags & FRAME_KF) != 0));
|
||||
|
||||
if (AudioTrackMask & (1 << Track)) {
|
||||
if (IndexMask & (1 << Track)) {
|
||||
ReadFrame(FilePos, FrameSize, AudioContexts[Track].CS, MC, ErrorMsg, MsgSize);
|
||||
(*TrackIndices)[Track].push_back(FrameInfo(AudioContexts[Track].CurrentSample, FilePos, FrameSize, (FrameFlags & FRAME_KF) != 0));
|
||||
|
||||
|
@ -241,7 +242,7 @@ static FrameIndex *MakeMatroskaIndex(const char *SourceFile, int AudioTrackMask,
|
|||
Size -= Ret;
|
||||
Data += Ret;
|
||||
}
|
||||
if (dbsize > 0) {
|
||||
if (dbsize > 0 && (DumpMask & (1 << Track))) {
|
||||
// Delay writer creation until after an audio frame has been decoded. This ensures that all parameters are known when writing the headers.
|
||||
if (!AudioContexts[Track].W64W) {
|
||||
char ABuf[50];
|
||||
|
@ -265,8 +266,9 @@ static FrameIndex *MakeMatroskaIndex(const char *SourceFile, int AudioTrackMask,
|
|||
return TrackIndices;
|
||||
}
|
||||
|
||||
FrameIndex *MakeIndex(const char *SourceFile, int AudioTrackMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize) {
|
||||
FrameIndex *MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize) {
|
||||
AVFormatContext *FormatContext = NULL;
|
||||
IndexMask |= DumpMask;
|
||||
|
||||
if (av_open_input_file(&FormatContext, SourceFile, NULL, 0, NULL) != 0) {
|
||||
_snprintf(ErrorMsg, MsgSize, "Can't open '%s'", SourceFile);
|
||||
|
@ -276,7 +278,7 @@ FrameIndex *MakeIndex(const char *SourceFile, int AudioTrackMask, const char *Au
|
|||
// Do matroska indexing instead?
|
||||
if (!strcmp(FormatContext->iformat->name, "matroska")) {
|
||||
av_close_input_file(FormatContext);
|
||||
return MakeMatroskaIndex(SourceFile, AudioTrackMask, AudioFile, IP, Private, ErrorMsg, MsgSize);
|
||||
return MakeMatroskaIndex(SourceFile, IndexMask, DumpMask, AudioFile, IP, Private, ErrorMsg, MsgSize);
|
||||
}
|
||||
|
||||
if (av_find_stream_info(FormatContext) < 0) {
|
||||
|
@ -292,7 +294,7 @@ FrameIndex *MakeIndex(const char *SourceFile, int AudioTrackMask, const char *Au
|
|||
IndexMemory IM = IndexMemory(FormatContext->nb_streams, db, AudioContexts);
|
||||
|
||||
for (unsigned int i = 0; i < FormatContext->nb_streams; i++) {
|
||||
if (AudioTrackMask & (1 << i) && FormatContext->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO) {
|
||||
if (IndexMask & (1 << i) && FormatContext->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO) {
|
||||
AVCodecContext *AudioCodecContext = FormatContext->streams[i]->codec;
|
||||
|
||||
AVCodec *AudioCodec = avcodec_find_decoder(AudioCodecContext->codec_id);
|
||||
|
@ -306,7 +308,8 @@ FrameIndex *MakeIndex(const char *SourceFile, int AudioTrackMask, const char *Au
|
|||
return NULL;
|
||||
}
|
||||
} else {
|
||||
AudioTrackMask &= ~(1 << i);
|
||||
IndexMask &= ~(1 << i);
|
||||
DumpMask &= ~(1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,7 +338,7 @@ FrameIndex *MakeIndex(const char *SourceFile, int AudioTrackMask, const char *Au
|
|||
if (FormatContext->streams[Packet.stream_index]->codec->codec_type == CODEC_TYPE_VIDEO)
|
||||
(*TrackIndices)[Packet.stream_index].push_back(FrameInfo(Packet.dts, (Packet.flags & PKT_FLAG_KEY) ? 1 : 0));
|
||||
|
||||
if (AudioTrackMask & (1 << Packet.stream_index)) {
|
||||
if (IndexMask & (1 << Packet.stream_index)) {
|
||||
AVCodecContext *AudioCodecContext = FormatContext->streams[Packet.stream_index]->codec;
|
||||
int Size = Packet.size;
|
||||
uint8_t *Data = Packet.data;
|
||||
|
@ -354,7 +357,7 @@ FrameIndex *MakeIndex(const char *SourceFile, int AudioTrackMask, const char *Au
|
|||
Data += Ret;
|
||||
}
|
||||
|
||||
if (dbsize > 0) {
|
||||
if (dbsize > 0 && (DumpMask & (1 << Packet.stream_index))) {
|
||||
// Delay writer creation until after an audio frame has been decoded. This ensures that all parameters are known when writing the headers.
|
||||
if (!AudioContexts[Packet.stream_index].W64W) {
|
||||
char ABuf[50];
|
||||
|
|
|
@ -62,7 +62,7 @@ public:
|
|||
int Decoder;
|
||||
};
|
||||
|
||||
FrameIndex *MakeIndex(const char *SourceFile, int AudioTrackMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize);
|
||||
FrameIndex *MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize);
|
||||
FrameIndex *ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize);
|
||||
int WriteIndex(const char *IndexFile, FrameIndex *TrackIndices, char *ErrorMsg, unsigned MsgSize);
|
||||
|
||||
|
|
Loading…
Reference in a new issue