Last active
June 5, 2023 09:07
-
-
Save ArmanTaheriGhaleTaki/61f3bebca8b4886e0eb7d88f990dcd36 to your computer and use it in GitHub Desktop.
automation of the process of the naming the output file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sys/stat.h> | |
#include <fstream> | |
void compress( char** input); | |
unsigned long long int fileSize(std::string fileNameWithextensionSTR); | |
void diffsize(std::string fileNameWithextensionSTR1,std::string fileNameWithextensionSTR2); | |
inline bool IsMP4FileExists (const std::string& name); | |
using namespace std; | |
int *argcGlobal=0; | |
int main(int argc, char **argv) { | |
argcGlobal = &argc; | |
compress(argv); | |
return 0; | |
} | |
void compress( char** input) | |
{ | |
if(IsMP4FileExists(input[1])) | |
{ | |
std::string command ="ffmpeg -i "; | |
std::string fileNameWithoutextensionSTR1 =input[1]; | |
std::string fileNameWithoutextensionSTR2 =""; | |
command +=input[1]; | |
command +=".mp4 -vcodec libx265 -crf 28 -f mp4 "; | |
if(*argcGlobal>2) | |
{ | |
command +=input[2]; | |
fileNameWithoutextensionSTR2=input[2]; | |
command+= ".mp4"; | |
} | |
else | |
{ | |
command +=input[1]; | |
fileNameWithoutextensionSTR2=fileNameWithoutextensionSTR1+"_compressed"; | |
command+= "_compressed.mp4"; | |
} | |
const char * c = command.c_str(); | |
system(c); | |
system("cls"); | |
std::cout<< "compressing is done \n\n\n"; | |
diffsize(fileNameWithoutextensionSTR1,fileNameWithoutextensionSTR2); | |
} | |
else | |
{ | |
std::cout<< input[1]<<".mp4 does not exit "; | |
} | |
} | |
unsigned long long int fileSize(std::string fileNameWithextensionSTR) | |
{ | |
fileNameWithextensionSTR+=".mp4"; | |
struct stat sb{}; | |
if (!stat(fileNameWithextensionSTR.c_str(), &sb)) { | |
} else { | |
perror("stat"); | |
} | |
return sb.st_size; | |
} | |
void diffsize(std::string fileNameWithextensionSTR1,std::string fileNameWithextensionSTR2) | |
{ | |
std::cout<< fileNameWithextensionSTR1<<".mp4"<<" - "<<fileNameWithextensionSTR2<<".mp4"<<" = "<<(fileSize(fileNameWithextensionSTR1) - | |
(fileSize(fileNameWithextensionSTR2))>>20)<<"MB"; | |
} | |
inline bool IsMP4FileExists (const std::string& name) { | |
std::string temp = name +".mp4"; | |
std::ifstream f(temp.c_str()); | |
return f.good(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used to compress my video files for uploading with command-line ffmpeg tool ; I've just automate the process of naming the files if you compile this code and give the executable file the name of the mp4 file (without .mp4) it will name the output of process the name of file + _compressed and if you give the executable file two arguments it will name the output the second argument . and at the end it's shows how many MB the size of file reduced .