[mythtv] MythWeb flash and ffmpeg

Shane gnome42 at gmail.com
Sat Jun 2 01:44:29 UTC 2007

> Actually, my ffmpeg processes don't quit on eof, but stay "running" (at
> 0% cpu use) until I browse away from the page.

I saw this behaviour too. In my case the parent process for that
lingering ffmpeg is init. That ffmpeg was parented by '/bin/sh' and it
is that shell that is killed in the TERM signal handler. Unfortunately
its child the ffmpeg process does not get killed, instead it
re-parents to the init process. I could reliably use pid + 1 to kill
of the ffmpeg proc itself, but that's bound to break, so I used the
alternate more complicated open that runs ffmpeg directly and does not
spawn a shell. Also, my apache seems to send SIGPIPE, not TERM too.

Anyways, here's a small patch ...

-------------- next part --------------
Index: mythweb/modules/stream/handler.pl
--- mythweb/modules/stream/handler.pl	(revision 13500)
+++ mythweb/modules/stream/handler.pl	(working copy)
@@ -20,12 +20,12 @@
 # Shutdown cleanup, of various types
     $SIG{'TERM'} = \&shutdown_handler;
+    $SIG{'PIPE'} = \&shutdown_handler;
     END {
     sub shutdown_handler {
-        kill(9, $ffmpeg_pid) if ($ffmpeg_pid);
-        usleep(100000) while (wait > 0);
+        kill(1, $ffmpeg_pid) if ($ffmpeg_pid);
 # Which show are we streaming?
@@ -129,7 +129,9 @@
     elsif ($ENV{'REQUEST_URI'} =~ /\.flv$/i) {
     # Print the movie
-        $ffmpeg_pid = open(DATA, "/usr/bin/ffmpeg -y -i $filename -s 320x240 -r 24 -f flv -ac 2 -ar 11025 -ab 64k -b 256k /dev/stdout 2>/dev/null |");
+        my @ffmpeg_cmd = ('/usr/bin/ffmpeg', '-v', '-1', '-y', '-i', "$filename", '-s', '320x240', '-r', '24',
+			  '-f', 'flv', '-ac', '2', '-ar', '11025', '-ab', '64k', '-b', '256k', '/dev/stdout');
+        $ffmpeg_pid = open(DATA, '-|', @ffmpeg_cmd);
         unless ($ffmpeg_pid) {
             print header(),
                   "Can't do ffmpeg:  $!";

More information about the mythtv-dev mailing list