This project has moved. For the latest updates, please go here.

Subtitles... adjust via cut amount, or can subtitles be hard burned-in before comskip?

Jan 5, 2014 at 2:26 PM
Edited Jan 5, 2014 at 2:27 PM
Hi,
I have tried to get subtitles to stay in sync with comskip cut video's, but it does not work. I think it is because the EDL cutfile (which is used to adjust the SRT subtitle file) cuts on the actual EDL file, but the video is cut on the closest B frame. So, in order for the SRT file to stay in sync with the video, the actual amount of video cut out would need to be used to adjust the SRT file, not the amount of time in the EDL cutfile. This would be an ideal solution if possible.
The other possible solution would be to use handbrake to hard burn-in the subtitles into the video stream before commercials were cut. Looking at the high level conversion process, the "Remux source file to MPEGTS" step is performed after the SRT file is extracted, and before comskip is ran. If this step is done by Handbrake, then the additional command to burn in the subtitle track is:

--subtitle-burn

Is there a way I can have the remux source file to MPEGTS step done by handbrake with the --subtitle-burn option sent to it?

Thanks,
Mark
Coordinator
Jan 8, 2014 at 8:21 AM
You're correct about the reason. To compensate for the BFrame alignment shift (which surprisingly is fairly regular after each commercial cut), I've introduced a parameter in Expert Settings called Subtitle segment offset, the purpose of that is to shift the subtitles by a predetermined amount , incrementally (not just once initially) after EACH commercial segment cut. By default it's set to 3.2 (by my tests) but you can play with that to get the right number for yourself (+ve or -ve).

For your second question, unfortunately the remuxing process is DEEPLY integrated into MCEBuddy with various checks and balances using ffmpeg so it really can't be swapped for handbrake.
However, you can run handbrake prior to MCEBuddy picking up the file using a batch script and then dropping the converted file to mcebuddy monitor directory to pick it up.

BTW, instead of handbrake, you can use ffmpeg to burn in teh subtitles also, you can customize the FFMPEGBackUpRemux section in mcebuddy.conf to include the additional settings reuqired to burn in the subtitles.
See this page for more details:
https://trac.ffmpeg.org/wiki/How%20to%20burn%20subtitles%20into%20the%20video
Jan 8, 2014 at 5:28 PM
Thank you for the detailed reply. I have no issue with doing this in ffmpeg instead of handbrake. So if I have this correct, in mcebuddy.conf, I need to add:

subtitles=<name of srt file>.srt

What parameter can I put into the FFMpegBackupRemux section of mcebuddy.conf to pass the name of the SRT file created by CC extract earlier?

Thanks!
Jan 11, 2014 at 4:25 PM
So looking at this a bit more, making the change to mcebuddy.conf in the FFMPEGBackUpRemux section won't work, because the SRT file has not been created yet. I also tried looking at the custom commands that can be used in profiles.conf. However, the place I need to run a custom command is not an option... I need to run a command after remux and captions are extracted by CCExtract, but before the commercial detection and conversion takes place.

Is there any way a custom command can be added at that point?

Thanks
Jan 12, 2014 at 2:07 AM
I am so close to making this work...

If I want to use ffmpeg, the -subtitles option fails due to the full path being passed by <source file> not being correctly escaped for ffmpeg. If the file is c:\temp\test.srt, it needs to come through for ffmpeg in the -subtitles option as:

c\:/temp/test.srt


So since that doesn't work, I set up 3 different conversion processes. The first monitors folder 1 for .wtv, and converts to .ts with subtitles extracted. It then moves the file to folder 2, where it is monitored for .ts, and embeds the subtitles and converts from .ts to .mp4. Then it is moved to folder 3. Folder 3 is monitored for .mp4, and cuts commercials, keeps it in mp4 format, and then moves it to the final folder.

If I manually add the files on step 2 and step 3, it works perfect. But I have to do it manually, because although the new file (for example in folder 2) is seen by MCEBuddy, the log says "File already converted with a status OutputFromConversion". Which means I can't string the 3 conversions together.... AGHH.


If either a new parameter can be created to escape the <source_without_ext> properly for ffmpeg (preferred), or there was an option to allow stringing multiple conversions, I could make this happen.

Thanks in advance for looking into doing either one.
Coordinator
Jan 13, 2014 at 3:04 PM
machyy1 wrote:
So looking at this a bit more, making the change to mcebuddy.conf in the FFMPEGBackUpRemux section won't work, because the SRT file has not been created yet. I also tried looking at the custom commands that can be used in profiles.conf. However, the place I need to run a custom command is not an option... I need to run a command after remux and captions are extracted by CCExtract, but before the commercial detection and conversion takes place.

Is there any way a custom command can be added at that point?

Thanks
I've added a custom command PreCommercialRemovalCustomCommand just before commercial removal (when the video and SRT files are adjust with the EDL files).
Refer to the Conversion Process page -> https://mcebuddy2x.codeplex.com/wikipage?title=Conversion%20Process

This will help you understand the various steps and what comes when.
Jan 13, 2014 at 9:42 PM
Thank you very much. Any chance of having the properly escaped for ffmpeg source without extension added to? I assume this will be in the next version, 2.3.16?

Again, thank you for all the great work on this awesome app!
Coordinator
Jan 14, 2014 at 12:34 AM
Give me some time. Escaping is not possible I will explain later why. The escaping will be limited to the source file name (without ext) which won't help.

Coordinator
Jan 14, 2014 at 3:13 PM
Edited Jan 14, 2014 at 3:14 PM
Okay done, I've added 2 options
  1. PreCommercialRemovalCustomCommand in the profile
  2. In the Monitor Location Settings now there is an Expert Settings button and an option to Monitor converted files. CAUTION: Use the VERY CAREFULLY. USE THIS ONLY IF YOU KNOW WHAT YOU’RE DOING. Otherwise it can lead to an infinite conversion loop of converted files in some cases.
Be careful not to put the converted files into the same directory as the monitor task with the same source files and the same monitor pattern (e.g. Monitor Task is monitoring all files (e.g. WTV and MP4), source being WTV and output being MP4, with this option checked, if the converted MP4 file is put into the same directory (or sub directory with monitor sub directories checked) as the WTV file, this task will pick up the MP4 and start reconverting it and if the name changes in the output files it will go into an infinite loop.

Now you an Daisy Chain the conversions if you build the options carefully. You'll find it in the next 2.3.15 BETA build
Jan 18, 2014 at 5:57 PM
Thank you for adding these. I have been playing with the build and burning in subtitles, and have found a few things. Also, with an added parameter for profiles.conf, this can be done in a single step without chaining.


First, mencoder is terrible at burning in subtitles. It works, but there are so many artifacts on the screen, it is hard to watch.
Second, handbrake cannot burn in SRT subtitles. So that is out.
That leaves FFmpeg, which works fantastic at burning in subtitles. A few things are required in order to make FFmpeg burn in subtitles though:

1) In the folder that ffmpeg.exe is located, a new folder called "fonts" must be created. Inside this folder, a file called "fonts.conf" must exist. The "fonts.conf" file, needs to have data such as the following in it:
<?xml version="1.0"?>
<fontconfig>

<dir>C:\WINDOWS\Fonts</dir>

<match target="pattern">
<test qual="any" name="family"><string>mono</string></test>
<edit name="family" mode="assign"><string>monospace</string></edit>
</match>

<match target="pattern">
<test qual="all" name="family" compare="not_eq"><string>sans-serif</string></test>
<test qual="all" name="family" compare="not_eq"><string>serif</string></test>
<test qual="all" name="family" compare="not_eq"><string>monospace</string></test>
<edit name="family" mode="append_last"><string>sans-serif</string></edit>
</match>

<alias>
<family>Times</family>
<prefer><family>Times New Roman</family></prefer>
<default><family>serif</family></default>
</alias>
<alias>
<family>Helvetica</family>
<prefer><family>Arial</family></prefer>
<default><family>sans</family></default>
</alias>
<alias>
<family>Courier</family>
<prefer><family>Courier New</family></prefer>
<default><family>monospace</family></default>
</alias>
<alias>
<family>serif</family>
<prefer><family>Times New Roman</family></prefer>
</alias>
<alias>
<family>sans</family>
<prefer><family>Arial</family></prefer>
</alias>
<alias>
<family>monospace</family>
<prefer><family>Andale Mono</family></prefer>
</alias>
<match target="pattern">
<test name="family" compare="eq">
<string>Courier New</string>
</test>
<edit name="family" mode="prepend">
<string>monospace</string>
</edit>
</match>
<match target="pattern">
<test name="family" compare="eq">
<string>Courier</string>
</test>
<edit name="family" mode="prepend">
<string>monospace</string>
</edit>
</match>

</fontconfig>
2) in the -vf section of the command line for ffmpeg, the option "subtitles=" must be added. What comes next must be the full path and file name of the SRT file to be hardcoded. The issue is that the path must be properly escaped (ffmpeg escaping rules). I have tried single quotes, double quotes, in all sorts of places. Bottom line is it doesn't work using <source_without_ext> as this is not properly escaped for ffmpeg. I understand how it might mess things up, but the whole option can be enclosed in double quotes, and this works. For example, in the profiles.conf file, for the "MP4 High Quality" settings, if I add (including the quotes and leading comma):

,"subtitles=c\:/temp/test.srt"

To the end of the -vf options, then it works perfect. So the -vf options look like:

-vf yadif=0:-1:1,hqdn3d,"subtitles=c\:/temp/test.srt"


If an option like <ffmpeg_escaped_source_without_ext> could be added, it would work very well, the profiles.conf looking like this:

-vf yadif=0:-1:1,hqdn3d,"subtitles=<ffmpeg_escaped_source_without_ext>.srt"

If that is not possible, an alternative would be to have an option like <source_without_ext_and_without_path>, meaning just the filename. MCEBuddy would have to be set to only do 1 conversion at a time, and the location of the working0 directory would be hardcoded into the profiles.conf, something like:

-vf yadif=0:-1:1,hqdn3d,"subtitles=c\:/temp/working0/<source_without_ext_and_without_path>.srt"


Thanks again.
Coordinator
Jan 18, 2014 at 6:47 PM
Where would this be put? during the conversion? Wouldn't that default the purpose (since commercials are cut before the conversion)?


Jan 18, 2014 at 8:28 PM
I was planning on using it with CutMP4Alternate=true. Wouldn't this mean the standard conversion using the above subtitles setting would burn in the subtitles to the full file, and then the commercials would be removed after complete?
Coordinator
Jan 18, 2014 at 10:05 PM
No that is just an alternative cutting tool when cutting mp4. You need to set Preconversioncommercialremoval to false.

Also note that MCEBuddy can't put quotes around the extension, it can replace the <file_name_withhout_ext> with the necessary stuff and quotes, but can't go past it.

Instead why don't yo uuse the custom command I' included, there you can write a batch file to do the stuff easily and use the filename and add the extension yo uneed. Itll be more efficient and easier.


Jan 19, 2014 at 3:45 PM
Thank you for the clarification, makes sense.

I am working on your suggestion, and trying to come up with a method that does not involve unnecessary conversions. So here is the overview:

1) Convert from WTV to TS
2) Detect commercials (generate .edl file)
3) Extract subtitles (generate .srt file)
4) Convert from TS to MP4 using ffmpeg with the subtitles option (done via .bat script)
5) Cut commercials using .edl file and mp4box


So it seems that I just need to replace the conversion section in the profiles with the bat file. I used the new section for custom commands (PreCommercialRemovalCustomCommand) to launch my bat file, which did step 4 above correctly. In the order= section for the profile, I made it blank, as I did not want any conversion to happen. This caused an error of "unsupported converter". I then tried using the mp4 unprocessed settings, which do work, but it is unnecessary step I think, right?
Coordinator
Jan 19, 2014 at 7:08 PM
Here's a little suggestion, using the new CustomCommand I've provided, use that to convert the file to mpeg4 format AND also burn the subtitles into it while doing it. Now IMPRTANTLY keep the format as TS so that MCEBuddy does not bug out post your CustomCommand.

Keep all else the same.

AND use a profile like MP4 Unprocessed (which does not recode since you've already encoded to MP4).(otherwise it will end up reconverting mpeg4 to mpeg4)


Coordinator
Jan 19, 2014 at 9:17 PM
Next best option I can put a flag in the profiles ffmpeg-subtitleburn=true, now you can play with pre or post conversion commercial removal. How'z that?


Jan 20, 2014 at 12:49 AM
That option sounds great, what exactly would it do? (I am hoping it would add the subtitles=<srt file properly escaped> to the end of the -vf section) :)

I am working on your first suggestion of using the custom command. I can convert from TS to TS with the subtitles burned in, but I lose all the cool work you've done regarding having the specific ffmpeg options set dynamically based on the input file. I have to chose what the options are up front in a batch file.
Coordinator
Jan 20, 2014 at 1:27 AM
I've run into an issue. The code to it is in place but I can't seem to figure out how the subtitles filter will work with this file name. If you can help me here I can close this fast.
D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD Small'.srt
It just does seem to take it
Jan 20, 2014 at 1:42 AM
The name of the srt file itself has a single quote in it? So the source file has a single quote in it as well?

If that is the case, I'd suggest at the very beginning do a simple search and remove any single or double quotes in the file name, and then its a non-issue from then forward anywhere.

it can be passed in as:

subtitles="<escaped format path and filename of srt file>"

And that works with spaces, underscores, etc, just not single or double quotes.
Coordinator
Jan 29, 2014 at 7:51 AM
Edited Dec 22, 2014 at 4:30 PM
I've fixed this, ffmpeg had a bug in their documentation which has been updated also. There is a new command added which can be used in the profile.
Thsi only works wiht ffmpeg and handbrake profiles.
SubtitleBurn=true
Refer to the documentation for more details, this will burn the subtitles into the file and will skip creating the SRT file as an output
Marked as answer by rboy1 on 1/29/2014 at 12:51 AM
Coordinator
Jan 29, 2014 at 7:53 AM
machyy1 wrote:
The name of the srt file itself has a single quote in it? So the source file has a single quote in it as well?

If that is the case, I'd suggest at the very beginning do a simple search and remove any single or double quotes in the file name, and then its a non-issue from then forward anywhere.

it can be passed in as:

subtitles="<escaped format path and filename of srt file>"

And that works with spaces, underscores, etc, just not single or double quotes.
Actually it does not, it's little complicated, see the ffmpeg bug report I've filed to see how and where it doesn't work.
Jan 29, 2014 at 1:50 PM
Wow, I'm seriously impressed with your troubleshooting the issue and providing the documentation to ffmpeg to correct their documentation / possibly fix the code itself.

Thank you very much for all your work on this, I'll try it out when I get home tonight. Additional donation headed your way :)
Jan 30, 2014 at 11:30 PM
First test through, and it is spot on perfect... I (and my wife) cannot thank you enough. This is fantastic :)
Coordinator
Dec 22, 2014 at 4:30 PM
Please note that ffmpeg-SubtitleBurn is no longer valid starting 2.4.1 instead please use:
SubtitleBurn=true
This is applicable for profiles based on ffmpeg and handbrake. FFmpeg and handbrake now support burning subtitles into the video effective 2.4.1