INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: need some help... mkv with external subtitles?  (Read 1900 times)

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4580
need some help... mkv with external subtitles?
« on: March 06, 2009, 09:50:17 am »

ive spend several hours today to get external subtitles (sub files) to work with mkv files. i have cccp installed, tryed the haali splitter with ffd show video (where i can set subtitles), tried directvobsub, and searched other settings. also tried to do the same in an other player, and on an other machine with an other op system. searched the forum, rereread the wiki... did not get it to work.

so when somebody has some usefull tips, or can tell how he/she got it working, im all ear.

thanks
 :)
gab
Logged

leezer3

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1588
Re: need some help... mkv with external subtitles?
« Reply #1 on: March 06, 2009, 10:58:24 am »

I think your issue is probably that as MKV can have subtitles embedded, all the splitters are assuming that these are the only subtitles.
I've run together a minor script based on my MKV muxer, that'll find & embed any .srt or .idx files with the same name as your current file:
Code: [Select]
using System;
using System.Windows.Forms; 
using System.IO;
using System.Drawing;
using System.Data;
using System.ComponentModel;
using System.Collections;
//css_reference MediaCenter.dll;

class Script : MarshalByRefObject
{
const bool autoupdate=false;
const bool deletefiles=false;

public string GetTempPath()
{
string path = System.Environment.GetEnvironmentVariable("TEMP");
if (!path.EndsWith("\\")) path += "\\";
return path;
}
public void LogMessageToFile(string msg)
{
System.IO.StreamWriter sw = System.IO.File.AppendText(
GetTempPath() + "MKVMux_log.txt");
try
{
string logLine = System.String.Format(
"{0:G}: {1}.", System.DateTime.Now, msg);
sw.WriteLine(logLine);
}
finally
{
sw.Close();
}
}
public void Init(MediaCenter.MCAutomation mediaCenterInterface)
{
//Start logging
LogMessageToFile("Subs Muxing started");
//Get the current playing now playlist
MediaCenter.IMJCurPlaylistAutomation playlist = mediaCenterInterface.GetCurPlaylist ( );
//Iterate through all the files in the playlist
for (int counter = 0; counter < playlist.GetNumberFiles() ; ++counter)
{
//Get the file from the current position in the playlist
MediaCenter.IMJFileAutomation track = playlist.GetFile(counter);
string Extension= track.Filetype;
//Check the file's format- We can only mux subs into MKVs.
if (Extension == "mkv")
{
//Mux subs into the current MKV
System.Console.WriteLine("Needs muxing!");
System.Console.WriteLine("Looking for subtitles");
{
string subscheck=track.Filename;
subscheck= subscheck.Replace(".mkv",".srt");
string subscheck2=track.Filename;
subscheck2= subscheck2.Replace(".mkv",".idx");
if (File.Exists(subscheck))
{
//MKV Merge- With SRT Subs
string part1A=track.Filename;
string part2A="\"";
string part3A=" -o ";
string part4A=".mkv ";
string part5A=" ";
string subs=track.Filename;
subs= subs.Replace(".mkv",".srt");
string fileNameA=
string.Concat(part3A,part1A,part4A,part1A,part5A,subs);
fileNameA= fileNameA.Replace(".mkv.mkv","-subs.mkv");
//Launch MKV Merge
System.Console.WriteLine("Launching MKV Merge.....");
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "mkvmerge.exe";
//Pass the argument we constructed earlier
proc.StartInfo.Arguments = fileNameA;
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.RedirectStandardOutput = false;
proc.Start();
proc.WaitForExit();
//The MKV file has been created sucessfully- Print its path
System.Console.WriteLine(fileNameA);
System.Console.WriteLine("Muxed successfully!");
string fileName2= ("Muxed sucessfully!");
string fileName3=
string.Concat(part1A,fileName2);
LogMessageToFile(fileName3);
goto dbupdate;
}
if (File.Exists(subscheck2))
{
//MKV Merge- With IDX Subs
string part1A=track.Filename;
string part2A="\"";
string part3A=" -o ";
string part4A=".mkv ";
string part5A=" ";
string subs=track.Filename;
subs= subs.Replace(".mkv",".idx");
string fileNameA=
string.Concat(part3A,part1A,part4A,part1A,part5A,subs);
fileNameA= fileNameA.Replace(".mkv.mkv","-subs.mkv");
//Launch MKV Merge
System.Console.WriteLine("Launching MKV Merge.....");
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "mkvmerge.exe";
//Pass the argument we constructed earlier
proc.StartInfo.Arguments = fileNameA;
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.RedirectStandardOutput = false;
proc.Start();
proc.WaitForExit();
//The MKV file has been created sucessfully- Print its path
System.Console.WriteLine(fileNameA);
System.Console.WriteLine("Muxed successfully!");
string fileName2= ("Muxed sucessfully!");
string fileName3=
string.Concat(part1A,fileName2);
LogMessageToFile(fileName3);
goto dbupdate;
}
else
{
//No subs found- Nothing to do.
goto dontmux;
}
dontmux:
LogMessageToFile("No subs were found- Nothing to do");
}
dbupdate:
//Determines what to do with the original file.
//If autoupdate is set to true, then the original
//file will be renamed or deledted.
if (autoupdate==true)
{
//If deletefiles is set to true, the original file will be deleted.
//Otherwise, it will be renamed to .bak
if (deletefiles==true){
string deleteFile=track.Filename;
System.IO.File.Delete(deleteFile);
string deleteFile1=" has been deleted";
string deleteFile2=
string.Concat(deleteFile,deleteFile1);
LogMessageToFile(deleteFile2);
string deleteFile3=track.Filename;
deleteFile3= deleteFile3.Replace(".mkv",".srt");
deleteFile3= deleteFile3.Replace(".mkv",".idx");
System.IO.File.Delete(deleteFile3);
string deleteFile4=
string.Concat(deleteFile,deleteFile3);
LogMessageToFile(deleteFile4);
}
else
{
string trackFileBak1=track.Filename;
string trackFileBak2=track.Filename;
trackFileBak2= trackFileBak2.Replace(".mkv",".mkv.bak");
System.IO.File.Move(trackFileBak1, trackFileBak2);
string trackFileBak3= ("has been renamed to ");
string trackFileBak4=
string.Concat(trackFileBak1,trackFileBak3,trackFileBak2);
LogMessageToFile(trackFileBak4);
string trackFileName=track.Filename;
trackFileName= trackFileName.Replace(".mkv","-subs.mkv");
track.Filename = trackFileName;
string filetype = "mkv";
track.Filetype= filetype;
System.Console.WriteLine(trackFileName);
string trackFileBak5= ("Your database has been modified to point to the new MKV");
string trackFileBak6=
string.Concat(trackFileBak1,trackFileBak5);
LogMessageToFile(trackFileBak6);
}
}
if (autoupdate==false)
{
//If autoupdate is set to false, you will be prompted each time.
//Answering "No" will produce a new MKV which is not in the library
{
DialogResult reply = MessageBox.Show("Modify the database?",
"Do you want to modify the database to point to the new MKV?",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
 
if (reply == DialogResult.Yes){
if (deletefiles==true){
string deleteFile=track.Filename;
System.IO.File.Delete(deleteFile);
string deleteFile1=" has been deleted";
string deleteFile2=
string.Concat(deleteFile,deleteFile1);
LogMessageToFile(deleteFile2);
}
else{
string trackFileBak1=track.Filename;
string trackFileBak2=track.Filename;
trackFileBak2= trackFileBak2.Replace(".mkv",".mkv.bak");
System.IO.File.Move(trackFileBak1, trackFileBak2);
string trackFileBak3= ("has been renamed to ");
string trackFileBak4=
string.Concat(trackFileBak1,trackFileBak3,trackFileBak2);
LogMessageToFile(trackFileBak4);
}
string trackFileName=track.Filename;
string trackFileName1=track.Filename;
trackFileName= trackFileName1.Replace(".mkv","-subs.mkv");
track.Filename = trackFileName1;
string filetype = "mkv";
track.Filetype= filetype;
System.Console.WriteLine(trackFileName1);
string trackFileBak5= ("Your database has been modified to point to the new MKV");
string trackFileBak6=
string.Concat(trackFileName,trackFileBak5);
LogMessageToFile(trackFileBak6);
} else {
LogMessageToFile("Muxing was completed, but your database has not been modified at this time");
}
}
}
}
}
}
}

Overview:
This script uses MrChriZ's scripting plugin to mux subtitles (.srt or .idx) into any MKVs present in Playing Now.
A new file will be produced, with -subs at the end to distinguish it from the original file, so it would look like this:
test.mkv ==> test-subs.mkv & so on.
Please don't assume its ready for primetime/ use on a live library- Its not, so please test on non-critical data first! Again, my coding may not be the best, but I think just about everything works as intended.

Available variables
These are the variables, which should be altered depending on how you want the script to run-
Quote
const bool autoupdate=false
true: The source AVI will be renamed to .bak or deleted (See below), and the new MKV will be inserted into the library (The filename has -subs inserted at the end, as you can't read & write an MKV at the same time).
false: You will be prompted as to whether to update the library with each muxed file. Choosing 'No' will leave the original file intact & in your library, regardless of whether you have selected to delete or rename files.
Quote
const bool deletefiles=true;
WARNING: SEVERE DATA DAMAGE/ LOSS POTENTIAL!!!
true: The source file will be deleted assuming a replacement is muxed.
false: Your original MKV file will be re-named to .bak & the subs will remain as-is. This is the default option, I'd advise only changing it if you are 100% sure things will work out fine ;)

A detailed log file may be found in %temp%\MKVMux_Log.txt (This logs to the scripting plugin console as well, but the detailed log should give times, as well as being persistant)

Cheers

-Leezer-
Logged

ThoBar

  • Citizen of the Universe
  • *****
  • Posts: 992
  • Was confishy
Re: need some help... mkv with external subtitles?
« Reply #2 on: March 06, 2009, 11:11:17 am »

Nice script.

I often wonder how many scripts and plugins are there that never see the outside of the author's machine. There seems to be a lot of useful bits'n'bobs about.
Logged

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4580
Re: need some help... mkv with external subtitles?
« Reply #3 on: March 07, 2009, 04:35:00 am »

thanks leezer, thanks for sharing, nice script...

until now ive used mkvmerge to get srt files in mkv files. but this seems handy..
the problem is though, that i would really like to get .sub files working. directvobsub and ffdvideo both 'except' .sub files but nothing happens.

 :)
gab
Logged

leezer3

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1588
Re: need some help... mkv with external subtitles?
« Reply #4 on: March 07, 2009, 07:22:44 pm »

thanks leezer, thanks for sharing, nice script...

until now ive used mkvmerge to get srt files in mkv files. but this seems handy..
the problem is though, that i would really like to get .sub files working. directvobsub and ffdvideo both 'except' .sub files but nothing happens.

 :)
gab

You ought to have a .idx file which goes with the .sub files. Try feeding them this instead :)
If the .idx is missing, some .sub files will work, but most won't.

Cheers

-Leezer-
Logged

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4580
Re: need some help... mkv with external subtitles?
« Reply #5 on: March 08, 2009, 06:04:35 pm »

thanks leezer, you answer is really appreciated, and makes some things clear. i guess i have to think some things over.

 :)
gab
Logged
Pages: [1]   Go Up