FPS convertor
-
Hy I want to create a FPS convertor in c#. input FPS =[24] to output FPS = [23] -it will show. it will ONLY work with *.srt files, meaning it will have to hunt and modify this type of line: [00:00:11,409 --> 00:00:14,548] ...(from inside that file). I want a formula for converting ANY FPS into ANY FPS. (A general formula). 4^789*242/1131(rad45*cons321)/5453+122-vect453E-453/34.23=x__<(something like this, i suppose) It will NOT work with movie files---only with txt files in *.srt format. That's it. Thanks.
-
Hy I want to create a FPS convertor in c#. input FPS =[24] to output FPS = [23] -it will show. it will ONLY work with *.srt files, meaning it will have to hunt and modify this type of line: [00:00:11,409 --> 00:00:14,548] ...(from inside that file). I want a formula for converting ANY FPS into ANY FPS. (A general formula). 4^789*242/1131(rad45*cons321)/5453+122-vect453E-453/34.23=x__<(something like this, i suppose) It will NOT work with movie files---only with txt files in *.srt format. That's it. Thanks.
_q12_ wrote:
I want to create a FPS convertor in c#.
_q12_ wrote:
It will NOT work with movie files
Your question does not make sense. FPS conversion actually means you are going to work with the video itself. If you mean subtitle converter and not a FPS converter, it would be best if you first have a basic understanding of the different subtitle formats. A SRT file is just a text file so you can open and be able to modify it the same way you would open a .txt file. See below for an example. Subtitle Synchronization with C#[^]
Signature construction in progress. Sorry for the inconvenience.
-
_q12_ wrote:
I want to create a FPS convertor in c#.
_q12_ wrote:
It will NOT work with movie files
Your question does not make sense. FPS conversion actually means you are going to work with the video itself. If you mean subtitle converter and not a FPS converter, it would be best if you first have a basic understanding of the different subtitle formats. A SRT file is just a text file so you can open and be able to modify it the same way you would open a .txt file. See below for an example. Subtitle Synchronization with C#[^]
Signature construction in progress. Sorry for the inconvenience.
subtitle converter, yes. So, the conversion idea is to Add or Extract seconds and/or milliseconds from existing time. Hmmm.
DateTime.Parse(m.Groups["start"]).AddSeconds(offset);
//and offset can be: +1.1(add), -2.75(extract); example values.But if I need to change from a predefined input FPS 23.978 to output FPS 23.976, then the difference is -0.002 ? or from 30 into 24, the difference is -06.000 ? . I did not made something like this ever, its my first time, so I appreciate a straight answer, please. And I know it sound stupid, but I want to be sure before start anything, because can rapidly become a time consuming process. And also, it will be good for others too. :) Thanks walterhevedeich! Excellent example.
-
subtitle converter, yes. So, the conversion idea is to Add or Extract seconds and/or milliseconds from existing time. Hmmm.
DateTime.Parse(m.Groups["start"]).AddSeconds(offset);
//and offset can be: +1.1(add), -2.75(extract); example values.But if I need to change from a predefined input FPS 23.978 to output FPS 23.976, then the difference is -0.002 ? or from 30 into 24, the difference is -06.000 ? . I did not made something like this ever, its my first time, so I appreciate a straight answer, please. And I know it sound stupid, but I want to be sure before start anything, because can rapidly become a time consuming process. And also, it will be good for others too. :) Thanks walterhevedeich! Excellent example.
I still don't get your question. What exactly are you having problems with? Is it on retrieving the date time stamps from the file? Or on the subtracting part? By the way, once you've put the date time stamps on a collection class(a
List
, for example), I'm sure you won't have a problem on the subtraction/addition part because you already have some code for it.Signature construction in progress. Sorry for the inconvenience.
-
subtitle converter, yes. So, the conversion idea is to Add or Extract seconds and/or milliseconds from existing time. Hmmm.
DateTime.Parse(m.Groups["start"]).AddSeconds(offset);
//and offset can be: +1.1(add), -2.75(extract); example values.But if I need to change from a predefined input FPS 23.978 to output FPS 23.976, then the difference is -0.002 ? or from 30 into 24, the difference is -06.000 ? . I did not made something like this ever, its my first time, so I appreciate a straight answer, please. And I know it sound stupid, but I want to be sure before start anything, because can rapidly become a time consuming process. And also, it will be good for others too. :) Thanks walterhevedeich! Excellent example.
Adding the same offset to all entries does not change the speed of the subtitles, it just shifts them in time. To change the speed, add a different offset depending on the number of nanoseconds (or some other unit) from the start, or stated differently, multiply the time by something. For example, to convert 23.978 FPS to 23.976, multiply each time by 23.978 / 23.976, or perhaps slightly more accurately (due to rounding), multiply the time by 23.978, then divide it by 23.976. You can factor out the fact that those are not integers by multiplying by 23978 (make sure there is no overflow) and then dividing by 23976, but if you use integer division, the division always rounds downwards and you get no chance to round To Nearest (so you'd get when using doubles and then rounding). If you're now thinking "what does multiplying a time even mean", it means taking the number of nanoseconds (or some other unit) that the time represents (it's just an offset from the beginning of course), do the math on that number, and convert it back to a time-thing again (with rounded as necessary).
-
Adding the same offset to all entries does not change the speed of the subtitles, it just shifts them in time. To change the speed, add a different offset depending on the number of nanoseconds (or some other unit) from the start, or stated differently, multiply the time by something. For example, to convert 23.978 FPS to 23.976, multiply each time by 23.978 / 23.976, or perhaps slightly more accurately (due to rounding), multiply the time by 23.978, then divide it by 23.976. You can factor out the fact that those are not integers by multiplying by 23978 (make sure there is no overflow) and then dividing by 23976, but if you use integer division, the division always rounds downwards and you get no chance to round To Nearest (so you'd get when using doubles and then rounding). If you're now thinking "what does multiplying a time even mean", it means taking the number of nanoseconds (or some other unit) that the time represents (it's just an offset from the beginning of course), do the math on that number, and convert it back to a time-thing again (with rounded as necessary).
Extraordinary explanation Harold ! Well done. But if I have to set that time, not knowing the initial time (i will test some predefined values) but if i am not so lucky in finding that value, how I can proceed?
ex of testing pseudocode :
inputTime=? outputTime=23.976 (i check movie properties);
if inputTime = 30, outputting to 23.976 will have the desired effect?
no?
then, if inputTime = 25, outputting to 23.976 will have the desired effect?
no?
then, if inputTime = 23, ...etcThis i will do manually from a list of defaults (30,25,23,etc) -Or writing it myself in a textbox whatever value i feel is right - but orbiting the default values. My question is: if I will have 0 for inputTime, How I will do the math then? Your solution is: t=t*outputTime/inputTime; if inputTime >0, t will have some specific duration. if inputTime = 0 (I don't know what encoding can have that subtitle), t =0 and all my sub time will be 0. Subtitle file ruined. I must make my program to guess the subtitle encoding (Its FPS encoded time) ? Or go on manually set the inputTime? (from list of defaults and/or textbox with custom values) Thank you! ~q12~
-
Extraordinary explanation Harold ! Well done. But if I have to set that time, not knowing the initial time (i will test some predefined values) but if i am not so lucky in finding that value, how I can proceed?
ex of testing pseudocode :
inputTime=? outputTime=23.976 (i check movie properties);
if inputTime = 30, outputting to 23.976 will have the desired effect?
no?
then, if inputTime = 25, outputting to 23.976 will have the desired effect?
no?
then, if inputTime = 23, ...etcThis i will do manually from a list of defaults (30,25,23,etc) -Or writing it myself in a textbox whatever value i feel is right - but orbiting the default values. My question is: if I will have 0 for inputTime, How I will do the math then? Your solution is: t=t*outputTime/inputTime; if inputTime >0, t will have some specific duration. if inputTime = 0 (I don't know what encoding can have that subtitle), t =0 and all my sub time will be 0. Subtitle file ruined. I must make my program to guess the subtitle encoding (Its FPS encoded time) ? Or go on manually set the inputTime? (from list of defaults and/or textbox with custom values) Thank you! ~q12~
I don't know, I can't think of anything except a manual test that probably doesn't even work well: See what at time the last line from the subs appears (in the sub file), and compare that with the time in the movie that the last line in the subs should appear. Then, assuming the beginning isn't shifted, you could get an approximate ratio with videotime/subtime, or the approximate old FPS with newfps*videotime/subtime.
-
I don't know, I can't think of anything except a manual test that probably doesn't even work well: See what at time the last line from the subs appears (in the sub file), and compare that with the time in the movie that the last line in the subs should appear. Then, assuming the beginning isn't shifted, you could get an approximate ratio with videotime/subtime, or the approximate old FPS with newfps*videotime/subtime.