Use batch files and vbs scripts to realize automatic recording of website videos
Now that TV stations basically have their own portals, we can make full use of the advantages of the Internet to expand the influence of local TV stations. In fact, the practice of hanging local TV stations' daily flagship programs on the website has become one of the necessary steps in establishing a TV station website. But the problem that comes with it is that the manual recording process required every day will bring great inconvenience to managers. On the basis of Windows scheduled tasks, this problem can be effectively solved by organically integrating batch programs and script programs.
1: Create a coding task
We will use a computer with a video capture card to complete the encoding process. Although coding is not the focus of this article, it is still necessary to explain it. The main thing is to use helix producer plus9 to create a coding parameter file. In fact, it is just an xml file with the rpjf suffix (Figure 1). It should be noted that the audio input options include line input and microphone input, which need to match the actual access line; in addition, there is no need to select the 2 pass vedio encoding option, selecting it will have no effect except displaying a warning. ; Furthermore, because most of the current network access modes are dial-up and dsl, it is only necessary to generate video files with 56k and 384k bit rates; finally, the name of the recorded video file is best identified by date. for example: 20060301.rm.
<?xml version=1.0 encoding=UTF-8?>
<job xmlns=http://ns.real.com/tools/job.1.0.1>
<enableTwoPass type=bool>false</enableTwoPass>
<clipInfo>
<entry>
<name>Author</name>
<value type=string>ZSTV</value>
</entry>
<entry>
<name>Copyright</name>
<value type=string>(c) ZSTV2006 </value>
</entry>
<entry>
<name>Keywords</name>
<value type=string>ZSNews[2006-03-21]</value>
</entry>
<entry>
<name>Title</name>
<value type=string>ZSNews[2006-03-21]</value>
</entry>
</clipInfo>
<input>
<captureInput>
<audioDeviceID type=string>Intel(r) Integrated Audio</audioDeviceID>
..................................................
We can create a batch file named shixian.bat to call the parameter file shown above. The internal details are as follows:
producer -jd:/shixian/shixian.rpjf -daw -lc e,i
The default recording process monitors audio changes in real time and records them to a file called producer.log. However, a lot of wanging records are generated, which quickly makes the log file huge and may cause unexpected interruptions in the recording process. So we can use the -daw parameter to turn off audio monitoring, and then use lc e,i to specify that only errors and information will be logged. After doing this, the recording process becomes more stable.
As long as we add the task of executing the shixian.bat file daily in the plan, we will get an rm file with the same file attributes and name every day. A file named 20060321.rm with the attribute 2006-03-21 will be generated here every day. It sounds like a mouthful, and what's worse is that it doesn't make the administrator's job any easier, because he has to open the server and change its name every day. And even if he is lucky enough to hire a diligent administrator (who doesn't mind doing such repetitive things every day), he still can't change the attribute of the date displayed in the file, which has been decided during this recording process. unless…….
2: Create a task to modify the coding parameter file
The principle is simple: update the date-related xml fields in the encoding parameter file every day. In this case it's the file's attributes showing the date and filename. Here is the script code used to update the date field:
dimregOR
set regOR=new regexp 'Create a regular expression object
regOR.ignorecase=True ' Ignore case
regOR.global=True ' Search applies to the entire string
regOR.pattern=^([0-9]{1})$ ' Create a search pattern as a single numeric expression
dim mytime
mytime=date ' Use the date function to reach the system date and assign it to mydate
yy=year(mytime) 'Extract the year from the system date
mm=month(mytime) 'Extract the month from the system date
dd=day(mytime) 'Extract the date from the system date
if regOR.test(mm) then ' Check whether the month is an odd number (January to September)
mm=regOR.replace(mm,0$1) ' If so, add 0 before the month to make it two digits
end if
if regOR.test(dd) then ' Check whether the date is an odd number (one to nine)
dd=regOR.replace(dd,0$1) ' If so, add 0 before the date to make it two digits
end if
mytime=yy & - & mm & - & dd ' Combine the year, month and day into the form of yy-mm-dd
dest=yy & mm & dd ' Combine the year, month and day into the form of yymmdd
pattern1=(.*[^0-9])([0-9]{4}/-[0-9]{2}/-[0-9]{2})([^0-9]. *)
'Set the pattern variable pattern1 to %d%d%d %d- %d %d -%d %d
pattern2=(.*[^0-9])([0-9]{8})([^0-9].*) ' Set pattern variable pattern2 to 8 consecutive numbers
regOR.pattern=pattern1 ' Create search pattern as pattern1
dimtempstring
Set fso = CreateObject(Scripting.FileSystemObject) 'Create a system file object
Set f = fso.CreateTextFile(d:/shixian/temp.txt, True) ' Create a new text file named temp
Set fr = fso.GetFile(d:/shixian/shixian.rpjf) ' Get the encoding parameter file shixian.rpjf
Set ts = fr.OpenAsTextStream(1,-2) 'Open the parameter file as read-only text
do until ts.AtEndOfStream ' Create a loop until the parameter file is read
tempstring=ts.readline 'Read parameter file in line units
if regOR.test(tempstring) then 'Search for a date field in the line change parameter
tempstring=regOR.replace(tempstring,$1 & mytime & $3) 'If it exists, update it
end if
regOR.pattern=pattern2 ' Create search pattern as pattern2
if regOR.test(tempstring) then 'Search for a date field in the line change parameter
tempstring=regOR.replace(tempstring,$1 & dest & $3) 'If exists, update
end if
regOR.pattern=pattern1 ' Re-establish the search pattern as pattern1
f.writeline(tempstring) 'Write the updated data to the temp.txt file
loop
ts.close 'The following is to close and log out each object
f.close
set regOR=nothing
setts=nothing
set fr=nothing
set f=nothing
set fso=nothing
What needs to be explained is why 0 is added before single-digit months and days. It is easier to explain with an analogy: If 0 is not added, then for a file named 2006111.rm, does it refer to January 11, 2006 or November 1, 2006? After adding 0, it becomes 20060111.rm. It is clear at a glance that it is the former.
The specific function of the above script code is to import the data in the parameter file into a temporary text file in behavioral units, monitor the time-related xml fields in real time and update them, and finally generate a temp.txt file. After that, all we have to do is call the script with a batch file, delete the old parameter file, and finally rename temp.txt to the parameter file.
This is the code in the update.bat batch file:
@echo off
d:/shixian/update.vbs
if exist d:/shixian/shixian.rpjf del d:/shixian/shixian.rpjf
if exist d:/shixian/temp.txt rename d:/shixian/temp.txt shixian.rpjf
As in the first section, you still need to add the update.bat batch file to the plan and tasks so that it can be started regularly every day.
3: Create automatic transmission tasks
In order to ensure stability, the encoding server and the website server are usually separated, which requires us to transfer the recorded video files to the website server every day. The ftp command in the batch file can perfectly implement this function.
The following is the code in the transfer.bat batch process:
@echo off
ftp -s:media.txt
if exist d:/shixian/shixian20060321.rm del d:/shixian/shixian20060321.rm
Considering the astonishing price of SCSI hard drives, the hard disk space of the encoding server does not need to be too large. The function of the last line is to delete the video files in the encoding server to save space. Media.txt is an ftp parameter file, which records the name, user name, password and related operations of the ftp login server. The specific form is as follows:
open/server name or IP address/
/ username/
/user password/
put / file name to be transferred /
quit
Obviously, there are many date literal expressions that need to be updated in the above code snippets. For the same reason, we also need to use a similar update script, and the specific code will not be repeated.
4: Some suggestions for improvement
1: The coding function can also be realized using media player.
2: In the update script, the code used to declare and unregister objects has several lines, which can be greatly simplified if using perl. Because perl provides a series of operation symbols to implement the functions of regular expressions, and in fact perl was born to process text.
open(RPJF,<c:/code/10161.rpjf) or die(can not open because of $!/n);
open(TEMP,>c:/code/temp.txt) or die(can not open because of $!/n);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime();
$mday=sprintf(%.2d,$mday);
$mon=sprintf(%.2d,$mon+1);
$year+=1900;
$timerF=$year.$mon.$mday;
$timerS=$year.-.$mon.-.$mday;
while(<RPJF>){
chomp();
$_=~s/(.*)([0-9]{8})(.*)/$1$timerF$3/;
$_=~s/(.*)([0-9]{4}/-[0-9]{2}/-[0-9]{2})(.*)/$1$timerS$3/ ;
print TEMP $_/n;
}
close(RPJF);
close(TEMP);
3: Using disk mapping can make file transfer more convenient, but security issues need to be considered.