Skip to content

Instantly share code, notes, and snippets.

@h2oota
Created November 16, 2012 12:42
Show Gist options
  • Save h2oota/4087040 to your computer and use it in GitHub Desktop.
Save h2oota/4087040 to your computer and use it in GitHub Desktop.
プレイリスト、tsファイルを生成し続ける bin/start_watch
#!/usr/local/bin/perl -w
our $segment_duration = 10;
our $window_size = 3;
sub is_active
{
return 0 unless (open (TS, "$_[0]/stream.m3u8.last") );
my $last = <TS>;
close(TS);
return $segment_duration * $window_size + $last > time;
}
$ARGV[0] =~ m!.*/([^/]+)$!;
our $id = $1;
our $pid = fork();
sub cleanup
{
chdir $ARGV[0] && chdir ".." && exec "/usr/bin/find", $id, "-delete" ;
}
if ($pid) {
local $SIG{SIGCHLD} = sub { cleanup; exit; };
while (is_active($ARGV[0])) {
sleep($segment_duration);
}
kill 2, $pid;
wait;
cleanup;
} else {
$ENV{PATH} = "/usr/local/bin:$ENV{PATH}";
chdir $ARGV[0];
exec "/bin/sh", "-c",
qq#exec >log 2>&1;recptx $ARGV[1] 0 /dev/stdout| tssplit -P 0x1fc8 - - | segmenter - ${segment\
_duration} stream stream.m3u8 /data/$id/ ${window_size}& trap "kill \$!" 2; echo $$ >pid;wait#;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment