<div dir="ltr">That's certainly a possibility, but since this app is primarily aimed at mobile devices that will be landing directly on stream URLs (for the most part not launched from their browser but through a handful of other apps that will simply make a call to the OS to open a URL for them to stream media directly) it would make this approach less than idea and not as robust as I was hoping for. :( </div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On 21 December 2013 03:52, Matthew Mallard <span dir="ltr"><<a href="mailto:mqm@q-technologies.com.au" target="_blank">mqm@q-technologies.com.au</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Just an idea.<br>
<br>
Why don't you use ajax and only allow on conversion per user at a
time. You can create an ajax query to check on progress, plus the
user can cancel. Basically detach the conversion from the web
client, but allow client to check on progress and have access to the
file when it has finished.<div><div class="h5"><br>
<br>
<div>On 21/12/2013 5:40 am, Nicola
Worthington wrote:<br>
</div>
</div></div><blockquote type="cite"><div><div class="h5">
<div dir="ltr">I have a handler that transcodes video files using
ffmpeg which all works fine. However, if the web client
disconnects or otherwise stops reading from the socket, my
handler will continue reading from the ffmpeg filehandle and
writing out to the writer object until ffmpeg has completed the
transcode.
<div>
<br>
</div>
<div>This wouldn't be a problem is we lived in a perfect world
where every web client would send a single request to a URL
and not make additional requests until the first one had been
completed, but of course we don't live in an ideal world,..
and I would prefer my webapp not kill the server it is running
on my spawning off more CPU intensive processes than
necessary.</div>
<div><br>
</div>
<div>Is there any way for me to determine how much data is sat
waiting to be flushed to the web client so that if it exceeded
a predetermined number of bytes I can assume that I should
kill my ffmpeg file handle and exit the handler prematurely,..
or any other way to determine if the web client has gone away?</div>
<div><br>
</div>
<div>Apologies if I haven't explained myself especially
articulately.</div>
<div><br>
</div>
<div>This is the handler in question:</div>
<div><br>
</div>
<div>
<div><font face="courier new, monospace"><b>get
'/stream/:file/:format' => sub {</b></font></div>
<div><font face="courier new, monospace"><b> my $file =
params->{file};</b></font></div>
<div><b style="font-family:'courier new',monospace"> my
$format = params->{format};</b><br>
</div>
<div><font face="courier new, monospace"><b><br>
</b></font></div>
<div><font face="courier new, monospace"><b> return
send_file(</b></font></div>
<div><font face="courier new, monospace"><b>
'favicon.ico',</b></font></div>
<div><font face="courier new, monospace"><b> streaming
=> 1,</b></font></div>
<div><font face="courier new, monospace"><b> callbacks
=> {</b></font></div>
<div><font face="courier new, monospace"><b>
override => sub {</b></font></div>
<div><font face="courier new, monospace"><b> my
($respond, $response) = @_;</b></font></div>
<div><font face="courier new, monospace"><b><br>
</b></font></div>
<div><b style="font-family:'courier new',monospace">
my $mime = 'video/mp4';</b><br>
</div>
<div><font face="courier new, monospace"><b> my
@ffmpeg_args = qw(-threads 0 -i $file);</b></font></div>
<div><b style="font-family:'courier new',monospace"><br>
</b></div>
<div><b style="font-family:'courier new',monospace">
if (exists $ffmpeg_formats{$format}) {</b><br>
</div>
<div><font face="courier new, monospace"><b>
$mime = 'video/' . $format;</b></font></div>
<div><font face="courier new, monospace"><b>
push @ffmpeg_args, @{$ffmpeg_formats{$format}};</b></font></div>
<div><font face="courier new, monospace"><b> }
else {</b></font></div>
<div><font face="courier new, monospace"><b>
push @ffmpeg_args, @{$ffmpeg_formats{mp4}};</b></font></div>
<div><font face="courier new, monospace"><b> }</b></font></div>
<div><font face="courier new, monospace"><b>
push @ffmpeg_args, '-';</b></font></div>
<div><font face="courier new, monospace"><b><br>
</b></font></div>
<div><font face="courier new, monospace"><b> my
$writer = $respond->([200, ['Content-Type' =>
$mime]]);</b></font></div>
<div><font face="courier new, monospace"><b>
open(my $fh, '-|', join(' ', '/usr/bin/ffmpeg',
@ffmpeg_args));</b></font></div>
<div><font face="courier new, monospace"><b> my
$buffer;</b></font></div>
<div><font face="courier new, monospace"><b>
while (read($fh, $buffer, 1024) ) {</b></font></div>
<div><font face="courier new, monospace"><b>
$writer->write($buffer);</b></font></div>
<div><font face="courier new, monospace"><b> }</b></font></div>
<div><font face="courier new, monospace"><b>
close($fh);</b></font></div>
<div><font face="courier new, monospace"><b> },</b></font></div>
<div><font face="courier new, monospace"><b> },</b></font></div>
<div><font face="courier new, monospace"><b> );</b></font></div>
<div><font face="courier new, monospace"><b>};</b></font></div>
</div>
<div><br>
</div>
<div>
<div><br>
</div>
-- <br>
<div dir="ltr">Nicola Worthington<br>
<div><a href="mailto:nicolaw@tfb.net" target="_blank">nicolaw@tfb.net</a><br>
</div>
<div><br>
</div>
</div>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
</div></div><pre>_______________________________________________
dancer-users mailing list
<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a>
</pre>
</blockquote>
<br>
</div>
<br>_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Nicola Worthington<br><div>+44 (0)3333 406 333</div><div><a href="mailto:nicolaw@tfb.net" target="_blank">nicolaw@tfb.net</a></div><div><br>
</div></div>
</div>