Perl没有用vlc插件播放视频

时间:2015-12-29 06:24:56

标签: apache perl vlc

我试图在vlc-plugin的帮助下播放视频文件。

这是我的代码: -

#!/usr/bin/perl

use strict;
use warnings;
use File::Basename;

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/\.[^.]*/);

open (my $fh, '<', $file)or die "can't open $file: $!";
binmode $fh;

print "Content-Type: application/x-vlc-plugin \n";
print "Cache-Control: public, must-revalidate, max-age=0";
print "Pragma: no-cache" ;
print "Accept-Ranges: bytes";
print "Content-Length:  $end - $begin\n\n";
print "Content-Range: bytes $begin'-'$end'/'$size";
print "Content-Disposition: inline; filename=\"$name$ext\"\n";
print "Content-Transfer-Encoding: binary";
print "Connection: close"; 

my $cur=$begin;
seek($fh,$begin,0);
while(!eof($fh) && $cur < $end)
{
    my $buf=1024*16;
    read $fh, $buf, $end-$cur;
    $cur+=1024*16;
}
close $fh;

这是我的访问日志正在编写

127.0.0.1 - - [29/Dec/2015:11:39:31 +0530] "GET /cgi-bin/download.cgi HTTP/1.1" 200 484 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0"
127.0.0.1 - - [29/Dec/2015:11:39:32 +0530] "GET /cgi-bin/download.cgi HTTP/1.1" 200 447 "-" "(null)"

当我检查apache网站的含义时,这就是我得到的内容

If no content was returned to the client, this value will be "-". To log "0" for no content, use %B instead.

没有内容返回给客户端。它返回null。 我无法弄清楚出了什么问题。任何帮助将会感激不尽。

请告诉我该怎么做才能播放视频,我不确定这是正确的方法吗?

提前致谢

2 个答案:

答案 0 :(得分:1)

我发现您要打印的标题存在许多重大问题:

onBackPressed()

此MIME类型主要用于print "Content-Type: application/x-vlc-plugin \n"; 标记以调用VLC。此文件类型的正确MIME类型可能是<embed>

video/mp4

这些标题以及后面的其他标题缺少终端换行符(print "Cache-Control: public, must-revalidate, max-age=0"; print "Pragma: no-cache" ; )。这将导致它们一起运行,从而导致意外结果。

\n

除了没有换行符之外,此标头告诉浏览器此资源支持范围请求。但是,您的脚本实际上并没有实现这一点,这将导致浏览器变得非常困惑。

print "Accept-Ranges: bytes";

Content-Length必须是表示资源总长度的单个数字(例如print "Content-Length: $end - $begin\n\n"; )。此外,您在这里有两个换行符,这将导致以下所有标题都被视为内容的一部分。

Content-Length: $size

此标头通常与范围请求一起使用,但您尚未完全实现此功能,因此此标题只会使事情混淆。

print "Content-Range: bytes $begin'-'$end'/'$size";

这个标题在这里毫无意义 - 它主要用于电子邮件。把它拿出来。

print "Content-Transfer-Encoding: binary";

此标头将根据Web服务器的需要进行设置。 CGI脚本不应该生成它。

你也错过了需要跟随最后一个标题的双重换行符。

答案 1 :(得分:0)

我太懒了,无法让它完全正常工作,这里有一些建议 这不符合评论

绝对会让你前进。

# format is in the detail
my $content_length = $end - $begin;
print "Content-Type: text/html\r\n";
print "Content-Type: application/x-vlc-plugin\r\n";
print "Cache-Control: public, must-revalidate, max-age=0\r\n";
print "Pragma: no-cache\r\n" ;
print "Accept-Ranges: bytes\r\n";
print "Content-Length: $content_length", "\r\n";
print "Content-Range: bytes ${begin}-${end}/${size}\r\n";
print "Content-Disposition: inline; filename=\"$name$ext\"\r\n";
print "Content-Transfer-Encoding: binary\r\n";
print "Connection: close\r\n";
print "\r\n";
################################
#
# flush is needed
#
# ##############################
use IO::Handle;
STDOUT->autoflush;

my $cur=$begin;
seek($fh,$begin,0);
while(!eof($fh) && $cur < $end)
{
    my $buf=1024*16;
    read $fh, $buf, $end-$cur;
    $cur+=1024*16;
    ##############################
    #   I suspect you will need this
    #
    ###############################
    print $buf;
}
close $fh;