# A2DInfo library: AviSynth Media Info function
# Written by MrC (May 2009)

Function A2DInfo(string InputMedia, string OutputText, bool "IsAviSynthScript")
{
IsAviSynthScript = default(IsAviSynthScript, false)
IsAviSynthScript==true? Import(InputMedia): DirectShowSource(InputMedia)
IsYV12==true? nop(): ConvertToYV12

WriteFileStart(OutputText, """ "[Video Info]" """, true)
WriteFileStart(OutputText, """ "HasVideo: " """, HasVideo==true? """ "1" """: """ "0" """, true)
WriteFileStart(OutputText, """ "Width: " """, "Width", true)
WriteFileStart(OutputText, """ "Height: " """, "Height", true)
WriteFileStart(OutputText, """ "Framecount: " """, "Framecount", true)
WriteFileStart(OutputText, """ "Framerate: " """, "Framerate", true)
WriteFileStart(OutputText, """ "VideoTime: " """, Framerate>0? "Round(Framecount/Framerate*1000)": "", true)
WriteFileStart(OutputText, "", true)
WriteFileStart(OutputText, """ "[Audio Info]" """, true)
WriteFileStart(OutputText, """ "HasAudio: " """, HasAudio==true? """ "1" """: """ "0" """, true)
WriteFileStart(OutputText, """ "AudioLength: " """, "AudioLength", true)
WriteFileStart(OutputText, """ "AudioRate: " """, "AudioRate", true)
WriteFileStart(OutputText, """ "AudioChannels: " """, "AudioChannels", true)
WriteFileStart(OutputText, """ "AudioTime: " """, AudioRate>0? "Round(AudioLength/AudioRate*1000)": "", true)
WriteFileStart(OutputText, "", true)
WriteFileStart(OutputText, """ "# ASCII file generated by A2DInfo" """, true)

(Framecount>249)==true? SelectEvery(Floor(Framecount/50),0,1,2,3,4): nop()
Trim(0,249)
}


# Script Example:
#
#   Import("C:\Programmi\AV\AVStoDVD Dev\Lib\AVSInfo.avsi")
#   A2DInfo("D:\Personal\Movies\Test\Bad Day.avs", "C:\Programmi\AV\AVStoDVD Dev\Lib\AVSInfo Example.txt", true)
#
#
# Execute from CLI:
#
#   "C:\Program files\Avs2Avi\avs2avi.exe" "Example.avs" -c "null" -o n
#    or
#   "C:\Program files\FFmpeg\ffmpeg.exe" -i "Example.avs" -f rawvideo -y NUL
#    or
#   "C:\Program files\AVSMeter\AVSMeter.exe" "Example.avs"