Skip to content

Instantly share code, notes, and snippets.

@milabs
Created December 6, 2015 16:33
Show Gist options
  • Save milabs/84224927368dd751205e to your computer and use it in GitHub Desktop.
Save milabs/84224927368dd751205e to your computer and use it in GitHub Desktop.
Wrapper for ffplay to watch RTSP disconnection without TEARDOWN
#!/usr/bin/perl -w
use strict;
no warnings 'once';
my $cmd = "ffplay -nodisp -loglevel info rtsp://SERVER/live";
pipe( READER, WRITER ) ;
my $child = open READER, '-|';
defined $child or die "fork(): $!\n";
if ( $child ) {
local $/ = "\r";
my $threshold = 0;
while (my $line = <READER>) {
if ($line =~ /aq=\s+0KB/) {
last if (++$threshold > 32); next;
}
$threshold = 0;
}
} else {
open STDERR, '>&STDOUT';
exec( $cmd ) or exit(1) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment