Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ---------------------------------------------------------------------------
- ** This software is in the public domain, furnished "as is", without technical
- ** support, and with no warranty, express or implied, as to its usefulness for
- ** any purpose.
- **
- ** MicroDVD Subtitles' FPS Converter.cpp
- ** This file contains the very whole code. Developed using the Dev-C++ IDE.
- **
- ** Author: jaggi
- ** Version: 1.0.0.0
- ** contact: [email protected]
- ** -------------------------------------------------------------------------*/
- #include <iostream>
- #include <conio.h>
- #include <fstream>
- #include <string>
- #include <cmath>
- #include <cstdlib>
- #include <sstream>
- using namespace std;
- void convert(int& frame, float fps_s, float fps_d) { frame=ceil(frame*fps_d/fps_s); }
- template <typename T> string tostr(const T& t) { ostringstream os; os<<t; return os.str(); }
- int count(const char* name)
- {
- string temp;
- int x=0;
- ifstream file1(name);
- while(getline(file1, temp)) x++;
- x++;
- file1.close();
- return x;
- }
- float menu(string msg)
- {
- cout<<msg<<"\n1. 12 \n2. 15 \n3. 18\n4. 20\n5. 23.976 \n6. 24 \n7. 25 \n8. 29.97 \n9. 30\n";
- char choice=getch();
- switch(choice)
- {
- case '1':return 12;
- case '2':return 15;
- case '3':return 18;
- case '4':return 20;
- case '5':return 23.976;
- case '6':return 24;
- case '7':return 25;
- case '8':return 29.97;
- case '9':return 30;
- default: return 0;
- }
- }
- void modify(string& line, float fps_s, float fps_d)
- {
- string sf1, sf2, temp="";
- int f1,f2. i=0;
- for(;i<line.length();i++)
- {
- if(line[i]=='{')
- {
- i++;
- while (line[i]!='}')
- {
- temp+=line[i];
- i++;
- }
- break;
- }
- }
- f1=atoi(temp.c_str());
- temp="";
- for(;i<line.length();i++)
- {
- if(line[i]=='{')
- {
- i++;
- while (line[i]!='}')
- {
- temp+=line[i];
- i++;
- }
- break;
- }
- }
- f2=atoi(temp.c_str());
- convert(f1, fps_s, fps_d);
- convert(f2, fps_s, fps_d);
- sf1=tostr(f1);
- sf2=tostr(f2);
- line="{"+sf1+"}"+"{"+sf2+"}"+line.erase(0, i+1);
- }
- void file(const char* name, int x)
- {
- ifstream file1(name);
- string tmp;
- string* tab=new string[x];
- for (int i=0;i<=x;i++)
- getline(file1, tab[i]);
- float fps_s, fps_d;
- fps_s=menu("Source file FPS");
- fps_d=menu("Destination file FPS");
- for (int i=0;i<x;i++)
- modify(tab[i], fps_s, fps_d);
- tmp=name;
- tmp=tmp.insert(tmp.length()-4, "_");
- tab[0]="{1}{1}";
- tab[0]+=tostr(fps_d);
- ofstream file2(tmp.c_str());
- for (int i=0;i<x;i++)
- file2<<tab[i]<<endl;
- file1.close();
- file2.close();
- }
- int main(int argc, char** argv)
- {
- cout<<"MicroDVD Subtitles' FPS Converter by jaggi.\nNo rights reserved :)\nEnjoy ;)\n";
- cout<<"contact ==> jaggi"<<"@"<<"interia.eu\n\n";
- if(argc==1)
- {
- cout<<"!Note!\nYou may drag your subtitles & drop on the converter's icon \nto skip typing filename.\n\n";
- cout<<"Enter filename (with extension). Be sure it is spelled correctly.\n";
- string name;
- cin>>name;
- int x=count(name.c_str());
- file(name.c_str(), x);
- cout<<"\nDone :)\nOutput file is named "<<name.insert(name.length()-4, "_")<<".\nPress any key to exit.";
- getch();
- return 0;
- }
- int x=count(argv[1]);
- file(argv[1], x);
- string name=argv[1];
- cout<<"\nDone :)\nOutput file is named "<<name.insert(name.length()-4, "_")<<".\nPress any key to exit.";
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment