perl - 如何捕获多播[视频]流?

时间:2015-04-22 15:32:49

标签: perl udp multicast

我正在尝试录制来自网络摄像头的多播流,并将其记录到文件中。我可以访问多播流并使用VLC查看我的视频,但是当我尝试播放我通过Perl编写的文件时,我看不到任何内容。

这是我的代码:

use strict;
use warnings;
use IO::Socket::Multicast;

my $group = shift @ARGV;
my $port  = shift @ARGV;

# Set up the stream
my $stream = IO::Socket::Multicast->new(Proto=>'udp', LocalPort => $port);
$stream->mcast_add($group) or die "Couldn't set group: $!\n";

# Get the date and time. We'll use this to name the stream file
my $fname = `date +%Y-%m-%dT%H_%M_%S`;
chomp $fname;
$fname .= ".mpg";

open (my $file, ">", $fname)
    or die "Couldn't open file  $fname for writing: $!";
binmode($file);

print "Streaming $group:$port to $fname!\n";

for my $i (0..500){
    my $data;
    next unless $stream->recv($data,1024);
    print "data received! $i \n";
    print {$file} $data;
}
close ($file);

Wireshark显示流的协议为MPEG TS

我感谢任何帮助!

0 个答案:

没有答案