Damn, I managed it all to work, awsome, thanks to all.
@Noxeus, your last little fix was a life saver.
Here is my computed script that works for me (I redirected the log to the subsonic log file because I did not get any log otherwise).
- Code: Select all
#!/usr/bin/perl
use strict;
use POSIX qw(mkfifo);
my $logfile = "/var/subsonic/subsonic.log";
open(my $logger, '>>', $logfile) or die "Could not open log file '$logfile' $!";
print $logger "[mencoder_hook] START\n";
my ($start_offset, $file, $bitrate, $width, $height, @user_args) = @ARGV;
$bitrate =~ s/k$//;
my $pipe = sprintf("/var/subsonic/pipes/%04d.mencoder", int(rand(10000)));
mkfifo( $pipe, 0770 ) or die "Couldn't make pipe";
my @args = (
$file,
"-ss", $start_offset,
"-of", "lavf",
"-oac", "lavc",
"-ovc", "lavc",
"-lavcopts", "vcodec=flv:vbitrate=" . $bitrate ,
"-oac", "mp3lame",
"-lameopts", "abr:br=96:vol=4",
"-srate", "44100",
"-af", "lavcresample=44100",
"-lavfopts", "format=flv",
"-vf", "fixpts=22,fixpts,harddup,scale=$width:-3",
"-utf8",
"-o", $pipe
);
foreach my $ext (".ass", ".srt") {
my $subs = $file;
$subs =~ s/\.[^\.]*$/$ext/;
if (-e $subs) {
if ($ext eq ".ass") {
push @args, (
"-ass", $subs,
"-subpos", "95"
);
} else {
push @args, (
"-sub", $subs,
"-subpos", "95"
);
}
}
}
open OLDOUT, ">&", \*STDOUT;
open OLDERR, ">&", \*STDERR;
my $child = fork();
if (!$child) {
# CHILD
$SIG{'TERM'} = sub { syslog("info", "TERMED CHILD"); };
print $logger "[mencoder_hook] mencoder " . join(" ", map { "\"$_\"" } @args, @user_args) . "\n";
open STDOUT, ">", "/dev/null";
open STDERR, ">", "/dev/null";
exec("mencoder", @args, @user_args);
}
# PARENT
$SIG{'TERM'} = sub {
# Kill mencoder with a SIGKILL so it actually quits
kill 'KILL', $child;
unlink $pipe;
print $logger "[mencoder_hook] killed prematurely; child was $child\n";
close $logger;
};
# Print the pipe to stdout
open F, "<", $pipe or print $logger "Pipe is missing!\n";
my $buf;
my $oldout = select(OLDOUT); $| = 1; select($oldout);
while (read F, $buf, 1024) {
print OLDOUT $buf;
}
print $logger "[mencoder_hook] finished\n";
close $logger;
Anyway, I'm digging out this topic because I'm dreaming about making this work for external players, such as android apps. But I don't have a clue about how to do it. I tried to play with all the transcripting commands, but it did not even alter the process. The encoding command that is prompted in the log file when i play a video from an external player remains the same whatever I do :
- Code: Select all
INFO TranscodeInputStream - Starting transcoder: [/var/subsonic/transcode/ffmpeg] [-r] [1] [-ss] [60] [-t] [1] [-i] [/path/to/video.mp4] [-s] [106x60] [-v] [0] [-f] [mjpeg] [-]
Waiting for the Subsonic developers to officialy implement subtitle support (if it's even on the roadmap), any help on how to make subtitles works with external players would be greatly appreciated.