|
Answer» Hello everybody, I know very little about writing a cgi script but really need one. I need to write a cgi script that will execute a bat file on my local server when a request is made. I have no idea how to do this or where to start. I no nothing about perl or c, which I have discovered is used to write a lot of cgi scripts. Any help in doing this will be greatly appreciated. ThanksWhat is your batch going to do?
Explain in great detail exactly what it will process, paths and all.
Maybe one of us can supply you with the perl script translation of the batch you provide here that achieves the same goal. You are going to run into problems trying to integrate CGI and Batch as for the server has to have a module that handles the script. If using Apache server for example to host the website/webpage there is a httpd.conf file that gets altered and you remove a # to enable the scripting module for perl or php, etc. There are none for batch!
Perl is the better language for batch like system functionality server side from a web interface. Perl is also very easy to learn, so even if you are new to programming its not too hard to figure out with the determination to learn it.
With a Perl version of what you want to achieve in Batch, you will then just need to MAKE the CGI of this implementing the Perl script to it.
*Note: Please do not disclose any user/password info in this batch... you can simply enter USER and PASSWORD where confidential info would reside. You can then later edit that to be your credentials.Sorry for the delay in replying. The batch script is a single line that executes a video conversion thru rtmp and ffmpeg. There is no web page involved in doing this. I have a roku player where I have developed a channel that will play a live stream from the internet. Unfortunately Roku only recognizes a limited number of video files, hls being one. Roku channels are created with BrightScript which as I have discovered has little complete documentation other than a reference guide. In the script for channel there resides an xml file which contain the url information. Now, in a normal world where a video player would recognize multiple file types, the roku would just go to the url, grab the requested stream and play it. Since it doesn't recognize flv, I first have to call the batch script which in turn downloads the stream, converts it and saves it on my local server. Once the stream starts to save, the roku can start streaming the hls (m3u8)file. I know this works since I can manually start the batch script, go to the player and select the channel and it play the stream that is being saved on my server. It will continue to play until I stop it and then manually stop the batch file. I know there are several server providing companies like Amazon and Wazoz(?) that provide transcode on the fly (of course for money) , but I am not looking to provide a channel for the public. I did come up with a slight alternative type of work around by setting up a listener on the port, when it detects activity it will trigger the script. Not ideal since I had to setup a reverse proxy since only one application can access a port at a time. This is where the gci would come into play. Instead pointing to the url on the net, the roku channel would point to my server and cgi. The cgi would execute the batch file. I can either hard code the particular ur into the batch file or ideally pass a variable representing the url to the cgi all depending on which channel selected. Sorry to be so long with this, but thought a complete explanation might lend to somebody else preventing me from reinventing the wheel. Thanks for any advice or help.What is the single line that the batch is processing?
This should be able to be executed from perl which works will with CGI's. I can show you the perl version of it if you provide the single line instruction.This is an example of the line.
rtmpdump -v -r rtmp://nyk.premiumcdnlive.com/edge -y xoaaohmeuajfeyf -W http://player.ilive.to/secure_player_ilive_z.swf --token "I8772LDKksadhGHGagf#" --live -P "http://www.ilive.to/view/48501/watch-live-SIC_Noticias-streaming-channel-for-free" -| ffmpeg -report -i pipe:0 -c:v libx264 -c:a aac -ac 1 -strict -2 -crf 18 -profile:v baseline -maxrate 400k -bufsize 1835k -pix_fmt yuv420p -flags -global_header -hls_time 10 -hls_list_size 6 -hls_wrap 10 -start_number 1 tv/espn.m3u8
The url following the rtmp can change depending on what is being streamed. The "xoaaohmeuaifey" is the actual flv file from the website. The line following the token can also be changed depending on what is being streamed. The above line basically uses rtmp to download the stream and pushes it into the ffmpeg to convert it to an hls segment. I have this in line in a single bat file called conversion. I can double CLICK the file and it runs as expected. I need to have it activate when the channel is selected so the m3u8 file can be created for the roku to read. Of course the cgi script must pass the url to the roku once the conversion has started. I guess what I see is my Brightscript code will have the url point to the cgi something like http://localhost:port/cgi-bin/conversionstarter.pl or something similar. Once the conversion is started, the script should pass the m3u8 url to the roku which would be something like http://localhost:port/tv/mystream.m3u8. Thanks againHere is a perl script that I put together quickly. It has not been tested yet. I dont have access to perl interpreter to pass a different instruction between my $status = system("..."); to test as I am posting this. But basically anything that is passed within the " " of the system call will execute just as if it was executed from command shell as a batch would process or as manually entered... however you have to take into consideration the use of escape characters so that the perl interpreter knows which " to ignore, and so I copy pasted what you shared with me and I placed a \ escape character prior to each " that is required for this lengthy instruction to execute properly.
In addition to this looking at what you have, what is shown below is static, that is that it should work for this specific path and specifications, however you will want this to probably be dynamic, and so you would want to have a dynamic fields for your URL's so that other URL's can be plugged into this and then executed.
For testing purposes before using this perl instruction within CGI, you can install the Perl interpreter to a system that you want to test this with, and run it locally to make sure it behaves in static form before moving forward with adding dynamic URL instructions to this and then containing in then within a CGI with user interface to pass the URL's to to process.
Here is a link to the Perl Interpreter that I use, which is the free community edition: http://www.activestate.com/activeperl/downloads
Here is how to run Perl scripts in Windows: http://editrocket.com/articles/perl_windows.html
Code: [Select] #!/usr/bin/perl use strict; use warnings; my $status = system("rtmpdump -v -r rtmp://nyk.premiumcdnlive.com/edge -y xoaaohmeuajfeyf -W http://player.ilive.to/secure_player_ilive_z.swf --token \"I8772LDKksadhGHGagf#\" --live -p \"http://www.ilive.to/view/48501/watch-live-SIC_Noticias-streaming-channel-for-free\" -| ffmpeg -report -i pipe:0 -c:v libx264 -c:a aac -ac 1 -strict -2 -crf 18 -profile:v baseline -maxrate 400k -bufsize 1835k -pix_fmt yuv420p -flags -global_header -hls_time 10 -hls_list_size 6 -hls_wrap 10 -start_number 1 tv/espn.m3u8"); More info here on examples: http://perlmeme.org/faqs/system/system.html
Lastly... Perl is an easy to learn scripting language, .... so with a little research into Perl and as long as you know HTML and how to create a CGI, and then have a web server to host this, this should be PRETTY easy to accomplish.
*** SECURITY NOTICE *** If this is run locally you wont run into any security issues, however I wouldnt host this on the web for others as for there are security concerns with using system(); calls in all languages to where there is the potential for buffer overflow hacks and for a hacker to gain remote admin access to the web server beyond the functionality that is INITIALLY exposed. Even if you are not going to run into this situation, I just wanted to specify this in case anyone else later stumbles upon this on a google search hit and decided to use the system(); call instruction on a live web server. The danger comes into play mainly when there is a dynamic input and if the length of the input is not controlled a overflow condition can be passed to the input of the system(); call and gain unauthorized admin access to the web server.Once again I wish to extend my thanks to you. I had previously download perl and was dabbling in it, I just didn't know where to go. To be honest I have programmed several projects in VB but nothing really dealing with server or internet, mostly stand alone app for specific work related task. You are correct in the static, I was planning on getting it to to work then dive into making the url dynamic. Thanks again, I will let you know how it turns out.
|