Subtitles

Need help? Post your questions here.

Moderator: moderators

A cleaner subtitles hook

Postby yostinso » Wed Mar 30, 2011 5:41 pm

Almost all the credit goes to badsanta, I just took his code and cleaned it up some. For one thing, it's much better at killing off mencoder as necessary now, and won't just kill every mencoder running (which is bad if you've got two streams going for whatever reason.)

This version also supports seeking so you can watch your video from the middle, and lets you add additional options via the subsonic config page. It will also use either .srt or .ass subtitles, as available.

See the usage information at the top of the script for how to install and use. If you're running Subsonic on Linux, this should be easy-peasy. If someone wants to write instructions for using this with Cygwin on Windows, please do!

Code: Select all
#!/usr/bin/perl

# mencoder_hook.pl
# Perl hook script for using mencoder to encode FLV with Subsonic
#   Renders subtitles if they exist in the same dir and with the same name as
#   the video and end in either .ass or .str
# Usage:
#   Install mencoder (apt-get install mencoder)
#   Paste this script into mencoder_hook.pl in /var/subsonic/transcode/
#   Create a link to mencoder: ln -s /usr/bin/mencoder /var/subsonic/transcode/mencoder
#   Create the folder /var/subsonic/pipes
#   Go to the "Transcoding" config in Subsonic
#   Edit "mp4 > flv" (and any other video->flv encoders that you want)
#   Set "Step 1" to:
#     mencoder_hook.pl %o %s %bk %w %h
#   Enjoy!
#   If you are having trouble with video/audio sync issues, try adding "-mc 1", e.g.:
#     mencoder_hook.pl %o %s %bk %w %h -mc 1
#   If you are getting the wrong audio track, use "-aid #", where # is the audio track number (they start at 1), e.g.:
#     mencoder_hook.pl %o %s %bk %w %h -aid 2


use strict;
use POSIX qw(mkfifo);

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 . ":acodec=libmp3lame:abitrate=96",
  "-srate", "44100",
  "-af", "lavcresample=44100",
  "-lavfopts", "format=flv",
  "-vf", "harddup,scale=$width:-3",
  "-o", $pipe
);


foreach my $ext (".ass", ".srt") {
  my $subs = $file;
  $subs =~ s/\.[^\.]*$/$ext/;
  if (-e $subs) {
    push @args, (
      "-ass",
      "-sub", $subs,
      "-subpos", "95"
    );
  }
}

open OLDOUT, ">&", \*STDOUT;
open OLDERR, ">&", \*STDERR;

my $child = fork();
if (!$child) {
  # CHILD
  $SIG{'TERM'} = sub { syslog("info", "TERMED CHILD"); };
  print STDERR "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 STDERR "killed prematurely; child was $child\n";
};

# Print the pipe to stdout
open F, "<", $pipe or print STDERR "Pipe is missing!\n";
my $buf;
my $oldout = select(OLDOUT); $| = 1; select($oldout);
while (read F, $buf, 1024) {
  print OLDOUT $buf;
}

print STDERR "finished\n";
Last edited by yostinso on Tue Apr 05, 2011 9:08 pm, edited 1 time in total.
yostinso
 
Posts: 3
Joined: Wed Mar 30, 2011 5:32 pm

Mencodered it..now video not found or access denied

Postby fractalsystems » Sat Apr 02, 2011 12:10 am

I tried this and it spits out video not found or permission denied.

On Ubuntu using Tomcat. Anyone know a solution. I have tried permissions etc and nothing. Please, thanks!

from subsonic.log
DEBUG InputStreamReaderThread - (/var/subsonic/transcode/mencoder_hook.pl) Couldn't make pipe at /var/subsonic/transcode/mencoder_hook.pl line 31.
fractalsystems
 
Posts: 15
Joined: Sun Feb 06, 2011 6:54 pm

Re: Mencodered it..now video not found or access denied

Postby yostinso » Tue Apr 05, 2011 9:11 pm

@fractalsystems:

You need to make sure you create the pipes directory:
Code: Select all
mkdir /var/subsonic/pipes


That directory needs to be writable by whatever user is running subsonic. If you're running it as root from the init script.

I've also tweaked the script slightly; it wasn't getting subtitles properly, so you'll want to get the updated version above.
yostinso
 
Posts: 3
Joined: Wed Mar 30, 2011 5:32 pm

chmod +x

Postby dorsey » Fri Apr 08, 2011 10:34 pm

Also make sure you mark the file as executable.

Code: Select all
chmod +x mencoder_hook.pl
dorsey
 
Posts: 1
Joined: Fri Apr 08, 2011 10:31 pm

Postby Trev186 » Sun Apr 10, 2011 10:51 pm

Hi,

I am having the same problems mentioned above when streaming MkV files to my Android phone as well.

I see that some people were able to get this to work on various varieties of linux.

Would anyone be willing to give me advice on how to set something similar up in Windows 7?
Trev186
 
Posts: 5
Joined: Sun Apr 10, 2011 10:47 pm

Postby fractalsystems » Mon Apr 11, 2011 5:25 am

@yostinso & @dorsey

Thanks, but I have done that and still no go.

I think I'm going to compile/install mencoder and mplayer from source.

Anyone know of any ./configure arguments I should be sure to use? or anything else I should know.

Thanks. Can't wait to get this going. FFMPEG settings produce some horrible quality.
fractalsystems
 
Posts: 15
Joined: Sun Feb 06, 2011 6:54 pm

Postby IronManUtd » Thu Apr 21, 2011 3:42 am

Yeah i have a lot of MKV files that have subs built into them. is there anyway to get those working?
IronManUtd
 
Posts: 2
Joined: Thu Apr 21, 2011 3:36 am

Postby b1ackjosh » Wed Jun 01, 2011 11:48 pm

For those of you who are wondering how to get subtitles out of mkv's you will probably be better off extracting them. I just happened to google this today and found this article:

http://mytechieself.blogspot.com/2011/0 ... m-mkv.html

If your running windows that should work for you. Not sure about linux users, i'd have to boot a virtual machine for that.

GL
b1ackjosh
 
Posts: 16
Joined: Wed Jan 19, 2011 9:15 am

Postby b1ackjosh » Thu Jun 02, 2011 2:32 am

@yostinso

I can't seem to get your solution to work at all. I'm also getting a video not found or access denied when playing the video, but I've made sure that I created the pipes directory and all the permissions are correct.

On top of that, the subsonic log doesn't give any error messages that would suggest there is an issue with the script... so I'm assume it's something to do with mencoder. Do you happen to know what I should be looking for?

Any help would be appreciated. Thanks.
b1ackjosh
 
Posts: 16
Joined: Wed Jan 19, 2011 9:15 am

Postby tgrhp » Wed Jul 13, 2011 4:14 pm

using yostinso's code I was able to make subtitles work, but I cannot seek are there other settings/code that were changed?

Also the subs do not support subtitles with location, and mkv files with chapters in separate files are omitted. [This probably requires compiling mencoder... or using a different transcoder]

I am using subsonic 4.4 and the client for android. any help would be appreciated.
Last edited by tgrhp on Wed Jul 13, 2011 5:48 pm, edited 1 time in total.
tgrhp
 
Posts: 16
Joined: Wed Jul 13, 2011 3:54 pm

Postby tgrhp » Wed Jul 13, 2011 4:30 pm

@b1ackjosh

not to insult ur intelligence [I dont know ur level of understanding] but maybe you have one of the following problems:
-this solution in for linux
-"#! /usr/bin/perl" has to be the first line of the file
tgrhp
 
Posts: 16
Joined: Wed Jul 13, 2011 3:54 pm

Postby Qbix » Wed Jul 13, 2011 7:01 pm

I want to have subtitles in some movies to so the only solution I could think
of is using 'Freemake Video Converter' and convert the movies to .flv files with the subtitles hard coded in the movie.
Cheers,
Image
------------------
14.985 artiesten
10.798 albums
90.526 nummers
822,06 GB (~ 12.770 uur)
------------------------------
Qbix
 
Posts: 97
Joined: Thu Jun 30, 2011 1:36 pm
Location: Netherlands

Postby tgrhp » Tue Jul 19, 2011 11:22 pm

As I said, this script works for transcoding most subtitles. But it doesn't work for ass/ssa subtitles [fancy subs].

The script should be able to be tweaked to work in windows.
tgrhp
 
Posts: 16
Joined: Wed Jul 13, 2011 3:54 pm

Postby Castius » Fri Jul 22, 2011 9:34 am

Here is how i added subtitles using captions plugin
http://www.longtailvideo.com/support/ad ... ence-guide

I made a "captions" folder in the subsonic webapp folder.
"\subsonic\jetty\2289\webapp\captions"

I put all my srt subtitles in there.
The name of the subtitles must match the name of the movie file.
BOONDOCK SAINTS.mkv == BOONDOCK SAINTS.srt

Then i edit videoPlayer.jsp
Code: Select all
"\subsonic\jetty\2289\webapp\WEB-INF\jsp\videoPlayer.jsp"

First I added this variable
Code: Select all
var caption = "<c:url value="/captions/${model.video.name}"/>"

Then i added the plugin info
Code: Select all
plugins:"captions-2",
"captions.back": false,
"captions.file": caption.split('.')[0] + '.srt',
"captions.state": false,


So it's pretty simple. I just do a split of the name object and add '.srt'.
I only figure this out by luck. I broke some syntax. That printed the ${model.video.name}. From there i figured out i could use the split to add the srt. I have no idea what ${model.video.path} looks like. So i can't use that to do the right manipulation.

So i couldn't leave the srt files in the same folder as the video. So if someone that is better at java can figure that out. Please let me know.

The changes should look like this
Code: Select all
        var player;
        var position;
        var maxBitRate = ${model.maxBitRate};
        var timeOffset = ${model.timeOffset};
        [color=red]var caption = "<c:url value="/captions/${model.video.name}"/>"[/color]

        function init() {

            var flashvars = {
                id:"player1",
                skin:"<c:url value="/flash/whotube.zip"/>",
                //plugins:"metaviewer-1",
                plugins:"captions-2",
                "captions.back": false,
                "captions.file": caption.split('.')[0] + '.srt',
                "captions.state": false,
                screencolor:"000000",
                controlbar:"over",
                autostart:"false",
                bufferlength:3,
                backcolor:"<spring:theme code="backgroundColor"/>",
                frontcolor:"<spring:theme code="textColor"/>",
                provider:"video"
            };
Castius
 
Posts: 34
Joined: Wed Sep 02, 2009 9:11 pm

Subtitles

Postby Soorploom » Fri Jul 22, 2011 11:52 am

Like many, I wished that Subsonic was capable to natively display subtitles form .srt, .sub files. Rather than faffing around with code, as suggested above, I used the MKVTOOLNIX available for both Windows and *nix alike (http://www.bunkus.org/videotools/mkvtoolnix/) to embed the subtitles within the video file.

My son has a huge collection of non inglis/English language videos and was unable to enjoy his movies whilst on his frequent travels. He can and does now.

Of course, it was left to me to do the work but really easy to accomplish, takes approximately 30 to 40 seconds to embed the subs.

Regards from Scotland

SP
Last edited by Soorploom on Sat Jul 23, 2011 12:11 am, edited 1 time in total.
Soorploom
 
Posts: 6
Joined: Fri Jul 22, 2011 11:27 am

PreviousNext

Return to Help

Who is online

Users browsing this forum: No registered users and 17 guests