View Full Version : New Application trimsrt trims and shifts srt subtitle file based on range of frames
xekon
21st October 2011, 03:08
I made a couple of posts and searched everywhere I could think of for an application that would take an srt subtitle file and trim/shift it based on a range of frames for situations where you do something like this in Avisynth:
A = NicAC3Source("E:\AviSynth\job.ac3")
V = FFVideoSource("E:\AviSynth\job.mkv")
AudioDub(V, A)
AlignedSplice(Trim(2832, 16727), Trim(16896, 31295))
I was unable to find an application that would do this via command line, so I wrote this program.
The Source code is included, I release it under the GPL.
If you find any problems please report them. If you know c++ and fix a problem or extend the application, please share.
I just started using Avisynth a couple of weeks ago, and I just wrote this application over the last couple days.
So far it has worked perfectly for me, but consider it to be in Beta testing stage.
most of my testing has been using 2 frame ranges (2832,16727,16896,31295), but it should accept as many frame ranges as you need.
Usage is -i <file> -f <fps> -t <frames>
omitting -f <fps> assumes an fps of 23.976024
trimsrt -i 004.srt -t 2832,16727,16896,31295
trimsrt -i 004.srt -f 29.97 -t 2832,16727,16896,31295
Guide showing trimsrt usage via batch script: http://forum.doom9.org/showthread.php?t=162830
other format conversion to srt tip:
To convert SUB/IDX or .SUP to .SRT. I recommend using Subtitle Edit: http://forum.doom9.org/showthread.php?t=162721
Guest
21st October 2011, 03:36
[bump after attachment approval -- thanks for your contribution!]
mastrboy
21st October 2011, 15:45
Thanks, any chance you will add support for .ass subtitles?
b66pak
21st October 2011, 18:55
thanks a lot...
_
xekon
21st October 2011, 21:04
Thanks, any chance you will add support for .ass subtitles?
I have not worked with that format but after quickly checking I see that it is also text based so it should be easy enough to add support for.
I will look into it, and see about adding support for that.
mastrboy
21st October 2011, 22:11
Thanks.. You can easily convert a .srt subtitle to .ass subtitle format with Aegisub if you don't have any .ass files lying around...
Have to say I'm quite surprised you haven't touch .ass subtitles before, it's a superior subtitle format compared to srt.
duedel
18th March 2015, 22:44
Does anyone still use this tool? It sounds exactly like something I'd love to use, unfortunately, the cuts are never correct, and I don't know why.
I noticed that no matter what fps value I entered (-f 25 or -f 50, PAL region), the resulting srt file were exactly the same. What am I missing here?
StainlessS
18th March 2015, 22:49
Dont know but just a daft suggestion, try eg -f 25.0 or -f 50.0 ie with .0
duedel
18th March 2015, 22:51
Thanks, your quick :)
Tried it, same result :(
StainlessS
18th March 2015, 22:58
Give the exact command that fails please.
xekon
18th March 2015, 23:00
Everything I have used it with so far is 23.976 fps.
This was the initial release and I may possibly still have the fps value hard coded in the code.
Unfortunately I am too busy to look at it now, but the source code trimsrt.cpp file was included in the zip, if anyone wants to make updates before I get the time to, feel free.
StainlessS
18th March 2015, 23:06
xekon, fps is defaulted to 23.976 FPS and then updated if -f flag used, but not used at all after that, ,seems to use 23.976 for everything.
I'll try to fix it but really dislike the CPP style lib funcs.
duedel
18th March 2015, 23:21
I'll try to fix it but really dislike the CPP style lib funcs.
This would be beyond awesome!! Can't wait :thanks:
StainlessS
18th March 2015, 23:28
Ok, made changes but getting error
char* myFile;
string myFileb;
char* myFrames;
vector<string> v;
double fps=23.976024;
for (int i = 1; i < argc; i++) { //We will iterate over argv[] to get the parameters stored inside.
string param = argv[i];
if (param == "-i") {
myFile = argv[i + 1];
myFileb = string(myFile).substr(0,(string(myFile).length())-4);
myFileb.append("new.srt");
i=i++;//skip next param, its a value
} else if (param == "-f") {
fps = godouble(argv[i + 1]);
i=i++;//skip next param, its a value
} else if (param == "-t") {
myFrames = argv[i + 1];
i=i++;//skip next param, its a value
string s = myFrames;
split(s, ',', v);
if ((v.size( ) % 2) != 0) {
std::cout << "Not an even number of frames, please try again.\n";
system("Pause");
exit(0);
}
} else {
std::cout << "Not enough or invalid arguments, please try again.\n";
system("Pause");
exit(0);
}
}
ifstream a_file (myFile);
ofstream a_file_out (myFileb);
Error line in red
Compiling...
trimsrt.cpp
N:\SJ\SOURCE ARCHIVE\VC\AVISYNTH FILTERS\25\_NOTMINE\trimsrt\trimsrt.cpp(123) : error C2664: '__thiscall
std::basic_ofstream<char,struct std::char_traits<char> >::std::basic_ofstream<char,struct std::char_traits<char> >(const char *,int)' :
cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
trimsrt.exe - 1 error(s), 0 warning(s)
I never really used CPP libraries for at least 20 years (and only a little bit back then), anybody suggest what is required, some kind of cast ?
EDIT: xekon, what was it originally compiled with ?
StainlessS
18th March 2015, 23:39
Tried with VS6 originally, re-tried with VS2008 and still same error.
What was it originally compiled with ? (non modded source produces error too).
duedel
19th March 2015, 00:03
I really wish I could help, StainlessS.
Let's hope xekon sees this.
StainlessS
19th March 2015, 00:06
OK, managed to get it to compile by adding myFileb.c_str() stuff in blue.
VS2008 compiles OK, but VS6 produces Linker errors about "__security_check_cookie", no idea what that is.
Anyways, heres the fixed (I hope) version together with original source.
http://www.mediafire.com/download/8ok81ev89bjaayv/trimsrt.zip
EDIT:
libcp.lib(xlocale.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
duedel
19th March 2015, 00:38
Yep, working fine now. Again, thank you so much!
StainlessS
19th March 2015, 00:41
OK, I'll attach the zip here.
EDIT: No runtimes required.
xekon
22nd January 2016, 10:32
Thanks for the update StainlessS! I figured i must forgot to swap out the hard coded values for the variable, strange about those compiler problems, I believe i originally used VS2008, but it could have been VS2010 i really cant remember. Need to remember to put stuff like that in the comments :)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.