View Single Post
Old 28th July 2019, 02:56   #20  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
From prev post.
Quote:
Unfortunately, in case where video opens in AVI, but no audio, will try open audio and index in both FFMS and LSmash (Non ISO) and so scan entire clip twice
only to find that it aint got no audio. [took a long long time on audioless Starwars PAL DVD in UT_Video avi].
Added Mifo_Library (Included in 7z). Avoids unnecessary (perhaps multiple) scans for non existing audio.

Here:- http://www.mediafire.com/file/xrf6rd...190728.7z/file

Now Require, RT_Stats, FFMS, LSmash, CallCmd, MediaInfo CLI, (tested only with v0.7.83, probably ok with later).

EDIT: Hard to tell exactly how long it took without timer (Media player start up etc, I'll add one) but above mentioned StarWars took ~= 2 seconds with Mifo_Library,
whereas was more like half an hour or more without it (so a bit faster, sometimes).

EDIT: MIFO_Library(slight mod included in GetSeq zip):- https://forum.doom9.org/showthread.p...hlight=library

EDIT: I suspect that giving a cachefile="whatever" type thing may have produced a full scan even when it was unnecessary, maybe.

EDIT: Non AVS+ guys will have to GImport() [gimport from GScript] the AVSI's, either from an avsi in plugins, or from the client script.

EDIT: Looks like this now (NOW requires either AVS+, or GSCript which must GImport the .avsi files GetSeq.avsi, and MIFO_Library.avsi. [STUFF added since zip upload in RED]
Code:
# GetSeq.avsi

Global GLB_GETSEQ_FFMS_CACHE_DIR       =   RT_GetSystemEnv("TEMP")  # Set to the Current User's Temp directory.

Global GLB_GETSEQ_DEL_INDEX_ON_CLOSE   =   True                     # If True then auto delete index's on clip closure.  [FFMS or LSMASH]


Function GetSeq(String vFn,String "aFn",Val "fpsNum",Val "fpsDen") {
/*
    Req:- RT_Stats, FFMS, LSmash. CallCmd, MediaInfo CLI v0.7.83+ (may work with later versions)

    Specify FrameRate using fpsnum (Numerator) and fpsden (Denominator)    # *** INGNORED if AVI ***
        num only,  eg fpsnum=25.0,               FrameRate = 25.0  FPS
        num & den, eg fpsnum=24000 fpsden=1001,  FrameRate = 23.976 FPS (Both should be type Int).
        neither specified                        FrameRate = UnDefined, ie whatever source filter thinks it is.
        ALWAYS:- use named args if using fpsnum/fpsden, argument order may change.

    FFMS Cachefile (used for .ffindex file) directory can be set using global variable GLB_GETSEQ_FFMS_CACHE_DIR, NO trailing backslash.
        Global GLB_GETSEQ_FFMS_CACHE_DIR = RT_GetSystemEnv("TEMP")  # Set to the Current User's Temp directory.

    If Global variable GLB_GETSEQ_DEL_INDEX_ON_CLOSE is True, then will auto Delete both FFMS and LSMash indexes on clip closure.
        Global GLB_GETSEQ_DEL_INDEX_ON_CLOSE = True    # If true, Auto delete indexes on clip closure. # Could create stub which sets True/False depending upon your own arg.

*/
    Function IsISOFileName(String s)  {s=RT_GetFileExtension(s) Return(s==".mov"||s==".mp4"||s==".m4v"||s==".3gp"||s==".3g2"||s==".mj2"||s==".dvb"||s==".dcf"||s==".m21")}
    Function IsRiffFileName(String s) {s=RT_GetFileExtension(s) Return(s==".avi"||s==".wav")}
    myName="GetSeq: "                                           aFn = Default(aFn,"")           aFn = (aFn=="") ? vFn : aFn
    Assert(RT_FunctionExist("MIFO_Version"),RT_String("%sWe require MIFO_Library",myName))
    Assert(vFn!="",RT_String("%svFn Cannot be ''",myName))      vFn = vFn.RT_GetFullPathName    IsRiffV = vFn.IsRiffFileName    IsIsoV = vFn.IsISOFileName
    Assert(aFn!="",RT_String("%saFn Cannot be ''",myName))      aFn = aFn.RT_GetFullPathName    IsRiffA = aFn.IsRiffFileName    IsIsoA = aFn.IsISOFileName
    Assert(RT_FunctionExist("CallCmd"),RT_String("%sCallCmd essential",myName))

    Start_T = RT_TimerHP()

    c=0 a=0
    def = fpsnum.Defined ? (fpsden.Defined ?1:0) : (!fpsden.Defined) ? 2 : -1    # 0=NumOnlyDef, 1=BothDef, 2=NoneDef, -1=DenOnlyError
    Assert(0<=def,myName+"Cannot specify framerate using fpsden only")
    #              Rate=num            :  Rate=num/den             : Rate=Undefined
    num=(def==0) ? Round(fpsnum * 1000): (def==1) ?    Int(fpsnum) : RT_Undefined
    den=(def==0) ?                1000 : (def==1) ?    fpsden      : RT_Undefined
    CacheFile = ""  FFMS_Index_file = ""    LSMASH_Index_file=""
    msgNL = Chr(10)+"   "
    VideoCount = MI_VideoCount(vFn,Debug=true)                      # Number of Video Streams in vFn
    RT_DebugF("File has %d Video streams.  '%s'",VideoCount,vFn,name=myName)
    Assert(VideoCount>0,myName+"File has no video\n'vFN'")
    AudioCount = MI_AudioCount(aFn,Debug=true)                      # Number of Audio Streams in aFn
    RT_DebugF("File has %d Audio streams.  '%s'",AudioCount,aFn,name=myName)
    #
    Try { # 1st Try specialized AVI
        c = (IsRiffV)                            ? vFn.AviSource                                                       : NOP
        (c.IsClip)                               ? RT_DebugF("OK ... AviSource opened Video\n  '%s'",vFn,name=myName)  : NOP
    } catch (msg) { RT_DebugF("*** Catch *** %s",RT_StrReplace(msg,Chr(10),msgNL),name=myName) }
    Try {
        if(AudioCount>0) {
            a = (c.IsClip && c.HasAudio && aFn==vFn) ? c : (IsRiffA) ? aFn.WavSource                                       : NOP
            (a.IsClip && a.HasAudio)                 ? RT_DebugF("OK ... %s opened Audio\n  '%s'",(c.IsClip && c.HasAudio && aFn==vFn)?"AviSource":"WavSource",aFn,name=myName) : NOP
        }
    } catch (msg) { RT_DebugF("*** Catch *** : %s",RT_StrReplace(msg,Chr(10),msgNL),name=myName) }

    # Next try specialized ISO LSMash
    Try {
        IsOpenV=(c.IsClip && c.HasVideo)
        c = (IsIsoV)                       ? LSMASHVideoSource(vFn,fpsnum=num,fpsden=den)                                 : c
        (IsIsoV)                           ? RT_DebugF("OK ... LSMASHVideoSource opened Video\n  '%s'",vFn,name=myName)   : NOP
    } catch (msg) { RT_DebugF("*** Catch *** : %s",RT_StrReplace(msg,Chr(10),msgNL),name=myName) }
    Try {
        if(AudioCount>0) {
            IsOpenA=(a.IsClip && a.HasAudio)
            a = (IsIsoA)                       ? LSMASHAudioSource(aFn)                                                       : a
            (IsIsoA)                           ? RT_DebugF("OK ... LSMASHAudioSource opened Audio\n  '%s'",aFn,name=myName)   : NOP
        }
    } catch (msg) { RT_DebugF("*** Catch *** : %s",RT_StrReplace(msg,Chr(10),msgNL),name=myName) }

     # Next try FFMS2
    Try {
        IsOpenV=(c.IsClip && c.HasVideo)    IsOpenA=(a.IsClip && a.HasAudio)
        IsSetCache = (!IsOpenV && !IsOpenA && vFn==aFn && RT_VarExist("GLB_GETSEQ_FFMS_CACHE_DIR") && GLB_GETSEQ_FFMS_CACHE_DIR.IsString && Exist(GLB_GETSEQ_FFMS_CACHE_DIR))
        Cachefile = (IsSetCache) ? RT_GetFullPathName(GLB_GETSEQ_FFMS_CACHE_DIR + "\" + RT_FilenameSplit(vFn,12) + ".ffindex") : Cachefile
        (IsSetCache) ? RT_DebugF("!!! Set !!! ... FFMS CacheFile = %s",CacheFile,name=myName) : NOP
    } catch (msg) { RT_DebugF("*** Catch *** : %s",RT_StrReplace(msg,Chr(10),msgNL),name=myName) }

    Try {
        IsOpenV=(c.IsClip && c.HasVideo)
        FFMS_Index_file = (!IsOpenV && CacheFile=="") ? vFn + ".ffindex" : CacheFile                               # May create Index on fail (so rem before we try)
        (!IsOpenV)    ? FFIndex(vFn,cachefile=CacheFile==""?RT_Undefined:CacheFile)                             : NOP
        c=(!IsOpenV)  ? FFVideoSource(vFn,fpsnum=num,fpsden=den,cachefile=CacheFile==""?RT_Undefined:CacheFile) : c
        (!IsOpenV)    ? RT_DebugF("OK ... FFVideoSource opened Video\n  '%s'",vFn,name=myName)                  : NOP
    } catch (msg) { RT_DebugF("*** Catch *** : %s",RT_StrReplace(msg,Chr(10),msgNL),name=myName) }
    Try {
        if(AudioCount>0) {
            IsOpenA=(a.IsClip && a.HasAudio)
            FFMS_Index_file = (FFMS_Index_file!="") ? FFMS_Index_file :  (!IsOpenA && CacheFile=="") ? aFn + ".ffindex" : CacheFile    # May create Index on fail (so rem before we try)
            a=(!IsOpenA)  ? FFAudioSource(aFn,cachefile=CacheFile==""?RT_Undefined:CacheFile)      : a
            (!IsOpenA)    ? RT_DebugF("OK ... FFAudioSource opened Audio\n  '%s'",aFn,name=myName) : NOP
        }
    } catch (msg) { RT_DebugF("*** Catch *** : %s",RT_StrReplace(msg,Chr(10),msgNL),name=myName) }

    # Next try LSmash non ISO Video : Try even if have tried ISO Open
    Try {
        IsOpenV=(c.IsClip && c.HasVideo)
        LSMASH_Index_file = (!IsOpenV) ? vFn + ".lwi" : LSMASH_Index_file                                      # May create Index on fail (so rem before we try)
        c = (!IsOpenV)                 ? LWLibavVideoSource(vFn,fpsnum=num,fpsden=den)                         : c
        (!IsOpenV)                     ? RT_DebugF("OK ... LWLibavVideoSource opened Video\n  '%s'",vFn,name=myName)  : NOP
    } catch (msg) { RT_DebugF("*** Catch *** : %s",RT_StrReplace(msg,Chr(10),msgNL),name=myName) }
    Try {
        if(AudioCount>0) {
            IsOpenA=(a.IsClip && a.HasAudio)
            LSMASH_Index_file = (LSMASH_Index_file!="") ? LSMASH_Index_file : (!IsOpenA) ? aFn + ".lwi" : ""        # May create Index on fail (so rem before we try)
            a = (!IsOpenA)                 ? LWLibavAudioSource(aFn)                                                       : a
            (!IsOpenA)                     ? RT_DebugF("OK ... LWLibavAudioSource opened Audio\n  '%s'",aFn,name=myName)   : NOP
        }
    } catch (msg) { RT_DebugF("*** Catch *** : %s",RT_StrReplace(msg,Chr(10),msgNL),name=myName) }

    Assert(c.IsClip, RT_String("!!! %s failed open on\n  '%s'",myName,vFn))

    if(AudioCount>0) {
        c = (!c.HasAudio && a.IsClip && a.HasAudio) ? AudioDubEx(c,a)     : c
        Assert(c.HasAudio,RT_String("%s!!! Audio failed Open on '%s'",myName,aFn))
    }

    AutoDEL = (RT_VarExist("GLB_GETSEQ_DEL_INDEX_ON_CLOSE") && GLB_GETSEQ_DEL_INDEX_ON_CLOSE)

    Try {
        c = (AutoDEL && FFMS_Index_file!="" && Exist(FFMS_Index_file))
            \ ? c.CallCmd(close="CMD /C chcp 1252 && del " + RT_QuoteStr(FFMS_Index_file),   hide=true, debug=true, Synchronous=7)
            \ : c
    } catch (msg) { RT_DebugF("*** Catch *** : %s",RT_StrReplace(msg,Chr(10),msgNL),name=myName) }

    Try {
        c = (AutoDEL && LSMASH_Index_file!="" && Exist(LSMASH_Index_file))
            \ ? c.CallCmd(close="CMD /C chcp 1252 && del " + RT_QuoteStr(LSMASH_Index_file), hide=true, debug=true, Synchronous=7)
            \ : c
    } catch (msg) { RT_DebugF("*** Catch *** : %s",RT_StrReplace(msg,Chr(10),msgNL),name=myName) }

    T = RT_TimerHP() - Start_T
    RT_DebugF("Time taken to Open clip = %.6f Seconds(%.6f Mins)\n    '%s'",T,T/60.0,vFN,name=myName)

    return c
}

# END OF GetSeq.avsi
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 28th July 2019 at 16:45.
StainlessS is offline   Reply With Quote