
"Roll Your Own GFA BASIC Program 6" by Troy H. Cheek on May 18, 2009
(This week's article will only make sense if you started at part 1.)
a% = InStr(buf$, "VIDEO_DURATION")
a$ = Mid$(buf$, a% + 31)
a$ = Left$(a$, InStr(a$, Chr$(13)) - 1)
dur% = 0 ' video duration in minutes
a% = InStr(a$, ":")
While a% > 0
dur% = dur% * 60 + Val(a$)
a$ = Mid$(a$, a% + 1)
a% = InStr(a$, ":")
Wend
Open EZMFilename$ for Append As # 2
Print # 2; Time$; " ";
Print # 2; "Duration"; dur%; "minutes."
Close # 2
Still looking inside the data that we buffered from the GSpot log file, we find the video duration. This is just GSpot's guess based on some of the header information and is usually within a few minutes of being correct. If we let GSpot do a detailed scan of the video it can tell the running time within tenths of seconds, but the detailed scan causes other problems, so we'll stick to the superficial scan.
The While/Wend structure is supposed to convert hours, minutes, and seconds into just plain minutes. As no video I record should be longer than a few hours, and certainly not days long, this hack should work. I also don't really need seconds, so I ignore those.
The reason I wanted to determine the video duration was to decide if I wanted to compress the file or not. I checked one time and discovered that most of my disk space was taken up by movies. Movies broadcast on TV are almost always at least an hour and a half long, making them easy to spot amongst the series and specials and whatnot which are usually half an hour to an hour. Longer video files take up more space, so I'd gain more by compressing the movies first, or the movies and not the series, or the movies at higher compression, or whatever.
Another reason I wanted the video duration was to sanity check some of the recordings. I was having some loss of television signal occasionally resulting in the tv tuners giving up on recording. When the signal came back, they'd start recording again. Instead of having a single half hour recording, I'd have three 10 minute recordings. I later found an easier way to discover this.
Open EZMFilename$ for Append As # 2
Print # 2; Time$; " ";
If Exist(AcfFilename$)
Acf% = 1 ' this one needs to be compressed.
Print # 2; "Automatic Compression file located."
Else
Acf% = 0
Print # 2; "No Automatic Compression file."
EndIf
Close # 2
There's a SageTV plugin called Automatic Compression. Its purpose is to check recordings against certain criteria and compress them using SageTV's included transcoder. So that Automatic Compression doesn't keep compressing the same files over and other, it creates a file to flag that it's doing so. I changed a few settings so that Automatic Compression created such a file without actually calling the transcoder. By looking for that file, I can tell EZMedia to compress it. This way, I can let Automatic Compression pick out which files I want EZMedia to compress.
I set the Acf flag to 1 to indicate this. I'll also set this flag if other conditions come up where I decide that the video file needs to be compressed. I know that's a little sloppy, that I really should have a zillion different flags for every condition, but I'm lazy.
If Yres% > 480
Open EZMFilename$ for Append As # 2
Print # 2; Time$; " ";
Print # 2; "HD file detected (Y>480)"
Close # 2
Acf% = 1 ' this one needs to be compressed
EndIf
Standard definition (SD) video recorded by my various TV recorders are about 640x480 to 720x480, while high definition (HD) can be much bigger. However, since I don't need all that extra resolution to get acceptable results on my screens, I'm quite happy to scale it down. To scale it down, I need to compress it, hence the setting of Acf to 1 again.
Open EZMFilename$ for Append As # 2
Print # 2; Time$; " ";
Print # 2; "Reading "; LogFilename$
Print "Reading "; LogFilename$
Close # 2
Finis% = 0
If Exist(LogFilename$)
Open LogFilename$ for Input As # 1
Repeat
Line Input # 1, a$
If InStr(a$, "Dominant") > 0
Dom$ = "AR_R: "
a% = InStr(a$, ".") - 1
Dom$ = Dom$ + Mid$(a$, a%, 4)
Print Dom$
Finis% = -1
EndIf
Until EOF(# 1) Or Finis% = 1
Close # 1
If Finis% = -1
Rem Calculate Cut Values
Open LogFilename$ for Input As # 1
Finis% = 0 : MinX% = 0 : MinY% = 0 : MaxX% = 0 : MaxY% =
0
Repeat
Line Input# 1, a$
If InStr(a$, "Block:") > 0 And InStr(a$, Dom$) > 0
Inc Finis%
a% = InStr(a$, "minX=")
MinX% = MinX% + Val(Mid$(a$, a% + 5))
a% = InStr(a$, "minY=")
MinY% = MinY% + Val(Mid$(a$, a% + 5))
a% = InStr(a$, "maxX=")
MaxX% = MaxX% + Val(Mid$(a$, a% + 5))
a% = InStr(a$, "maxY=")
MaxY% = MaxY% + Val(Mid$(a$, a% + 5))
EndIf
Until EOF(# 1)
Close # 1
EndIf
EndIf
What this huge bit of code does is shuffle through the log file create by Comskip. Comskip likes to figure out the dominant aspect ratio of the video file. Comskip uses this to help seperate the show from the commercials. I like to use it to determine what kind of cropping I need to do while compressing the file. Once I figure out what the dominant aspect ratio is, I can figure out how much to crop out of those segments.
More next week.