Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

playing video using vlc plugin

by awanti (Acolyte)
on Dec 28, 2015 at 06:06 UTC ( [id://1151239]=perlquestion: print w/replies, xml ) Need Help??

awanti has asked for the wisdom of the Perl Monks concerning the following question:

Hi i am trying to play the video in webmin with the help of file manager module.I have did so much research regarding this but the code doesnt seem to work. I hopefully get help from here. This is my code

#!/usr/bin/perl require './filemin-lib.pl'; use lib './lib'; use strict; use warnings; use File::Basename; use Cwd 'abs_path'; &ReadParse(); get_paths(); my $file ='/home/abhishek/Videos/lua.mp4'; my $size = -s "$file"; my $begin=0; my $end=$size; (my $name, my $dir, my $ext) = fileparse($file, qr/\.[^.]*/); print "Content-Type: application/x-vlc-plugin \n"; print "Cache-Control: public, must-revalidate, max-age=0"; print "Pragma: no-cache" ; print "Content-Disposition: attachment; filename=\"$name$ext\"\n"; print "Content-Transfer-Encoding: binary"; print "Accept-Ranges: bytes"; print "Content-Length: $end - $begin \n\n"; print "Connection: close"; open (FILE, "< $file") or die "can't open $file: $!"; binmode FILE; my $cur=$begin; seek(FILE,$begin,0); while(!eof(FILE) && $cur < $end) { my $buf=1024*16; read FILE, $buf, $end-$cur; $cur+=1024*16; } close FILE;

Though i can able to open the plugin but it is failing to play the video.Please someone help me regarding this.I am breaking my head to think some other logic. Please someone suggest me any idea about this.It will be very grateful Thanks in advance.

Replies are listed 'Best First'.
Re: playing video using vlc plugin
by Corion (Patriarch) on Dec 28, 2015 at 07:23 UTC

    Have you looked into the web server error log to find out if there are any messages from your script there?

    Have you inspected that the headers you send are the headers you should be sending?

    Also note that HTTP headers should be delimited using \r\n, not \n. You should also use binmode STDOUT; before printing anything to the client.

    Depending on how your webserver is set up, you might need to output a HTTP status line first:

    print "200 OK HTTP/1.0\r\n";
      I added this
      if ( $begin > 0 || $end < $size ) { print "HTTP/1.1 206 Partial Content" ; } else { print "HTTP/1.1 200 OK" ;
      But i am getting the error
      Error - Bad Header
      I think this is webmin error.

        Sorry for mixing up the HTTP status line - it's been a long while since I last did this manually... You will need to print at least the newlines:

        print "HTTP/1.1 206 Partial Content\r\n";

        Also consider just running your script from the command line to see whether the headers look right. You might want to comment out the sending of the video to prevent binary data being spewed to your terminal.

Re^2: playing video using vlc plugin
by hotchiwawa (Scribe) on Jan 01, 2016 at 15:29 UTC
    Hi awanti :)

    #I see a coming bug ^_^

    while(!eof(FILE) && $cur < $end) { my $buf=1024*16; read FILE, $buf, $end-$cur; $cur+=1024*16; }

    I suggest you to keep the number of bytes read in a variable:
    e.g.: $ln = read FILE, $buf, $size;
    ($size defined outside the loop and "my $buf" too)

    and compute $cur with the number of bytes read, e.g.:
    $cur += $ln;

    In fact, the block read is not always 1024*16

    The while is strange (it can work but it's stinks lol), why not simplify it with e.g.:
    while(!eof(FILE))

    Peace
Re: playing video using vlc plugin
by thomas895 (Deacon) on Jan 01, 2016 at 03:14 UTC

    It doesn't look like you're actually returning anything to the client. You're reading the file in your while loop, but then you don't do anything with $buf.

    -Thomas
    "Excuse me for butting in, but I'm interrupt-driven..."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1151239]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-16 18:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found