diff --git a/.gitignore b/.gitignore index e99d69a..0a9749d 100755 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,8 @@ bin/* passphrase.bin s_lockValue.bin release-configs/* +appData/* +ffmpeg-coder/usr/* ### CMake ### CMakeLists.txt.user @@ -55,4 +57,4 @@ CMakeUserPresets.json build/* ### CMake Patch ### # External projects -*-prefix/ \ No newline at end of file +*-prefix/ diff --git a/.vscode/settings.json b/.vscode/settings.json index eabf409..f36add2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -41,5 +41,7 @@ "stdexcept": "cpp", "streambuf": "cpp", "typeinfo": "cpp" - } + }, + // clang-format extension settings + "editor.formatOnSave": false, } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ad2237..b3a54bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # Use cmake -G "Mingw Makefiles" before using Cmake on windows with g++ (mingw) compiler cmake_minimum_required(VERSION 3.12) -project(ffmpeg-coder VERSION 1.0.0) +project(ffmpeg-coder VERSION 2.0.0) message("FFMPEG CODER BUILD PROCESS") message("--------------------------") diff --git a/Makefile.own b/Makefile.own index f7fed73..2a6768c 100644 --- a/Makefile.own +++ b/Makefile.own @@ -17,7 +17,7 @@ all: build run .PHONY: build build: - ${CC} ${CFLAG} ${SRCDIR}/${APPNAME}.cpp ${SRCDIR}/quickConvertSettings.cpp ${INC} -o ${BUILDDIR}/${APPNAME}.o + ${CC} ${CFLAG} src/ffmpeg-coder.cpp src/frontend_funcs.cpp src/main.cpp src/quickConvertSettings.cpp src/utils.cpp ${INC} -o ${BUILDDIR}/${APPNAME}.o .PHONY: clean clean: @@ -48,9 +48,14 @@ debpackage: build # Windows Configs for make .PHONY: winbuild winbuild: - ${CC} ${CFLAG} ${SRCDIR}/${APPNAME}.cpp ${SRCDIR}/quickConvertSettings.cpp ${INC} -o ${BUILDDIR}/${APPNAME}.exe + ${CC} ${CFLAG} src\ffmpeg-coder.cpp src\frontend_funcs.cpp src\main.cpp src\quickConvertSettings.cpp src\utils.cpp ${INC} -o ${BUILDDIR}/${APPNAME}.exe .PHONY: winrun winrun: echo Running the built program.... ./${BUILDDIR}/${APPNAME}.exe + +.PHONY: winProductionBuild +winProductionBuild: + echo Building release version..... + ${CC} ${CFLAG} src\ffmpeg-coder.cpp src\frontend_funcs.cpp src\main.cpp src\quickConvertSettings.cpp src\utils.cpp ${INC} -static-libgcc -static-libstdc++ -o ${BUILDDIR}/${APPNAME}.exe \ No newline at end of file diff --git a/appData/s_lockValue.bin b/appData/s_lockValue.bin deleted file mode 100644 index c227083..0000000 --- a/appData/s_lockValue.bin +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 97a4996..9ba2d68 100755 --- a/docs/README.md +++ b/docs/README.md @@ -41,11 +41,13 @@ The user should have really basic knowledge about ffmpeg like how to run ffmpeg - The installer will start & then just follow the onscreen instructions and ffmpeg-coder will be installed on your machine - After installation, from the start menu search for **_ffmpeg-coder_** and open the tool. -## Linux (Debian based distros) +## Linux + +### Debian based distros This installation process works on ubuntu, kali linux, linux mint, debian and other debian based distros. -### Automatic One Click Process +#### Automatic One Click Process - Just copy and paste this script below and **_voila_** @@ -53,7 +55,7 @@ This installation process works on ubuntu, kali linux, linux mint, debian and ot wget https://raw.githubusercontent.com/Abir-Tx/ffmpeg-coder/main/scripts/debian_install.sh && chmod +x debian_install.sh &&./debian_install.sh ``` -### Manual Download Process +#### Manual Download Process - First download the **ffmpeg-coder_1.0_all.deb** from the release or from [here](https://github.com/Abir-Tx/ffmpeg-coder/releases/download/v1.0/ffmpeg-coder_1.0_all.deb). - Then open terminal to the folder where the .deb file is downloaded. @@ -66,6 +68,16 @@ sudo apt install ./ffmpeg-coder_1.0_all.deb - **_ffmpeg-coder_** should be installed now. Now run `ffmpeg-coder` in your terminal. Sometime if running just after installation the tool might not start. In that case run `ffmpeg-coder` in terminal twice. +### Arch Linux + +If you are on Arch Linux you can install ffmpeg-coder from the AUR using a AUR helper easily + +```bash +yay -S ffmpeg-coder +``` + + + ## Install from source Users other than Debian based distro can use the tool by compiling the tool from the source code easily. Also any distro or windows users can compile and use the tool if they are having problems using the binary packages provided in the release. @@ -88,17 +100,17 @@ cd ffmpeg-coder - **Linux** -Now if you are in linux & have build-essentian installed then just run - +Now if you are in linux & have build-essentials installed then just run - ```bash -make dir -make build +make -f Makefile.own dir +make -f Makefile.own build ``` The tool will be compiled to the `bin` folder inside ffmpeg-coder folder. You can also run `make run` to run the tool from there - ```bash -make run +make -f Makefile.own run ``` - **Windows** @@ -106,14 +118,14 @@ make run If you are windows user and have **\*GNU Make** installed or configured in your system then run - ```batch -make dir -make winbuild +make -f Makefile.own dir +make -f Makefile.own winbuild ``` The tool will be compiled to the `bin` folder inside ffmpeg-coder folder. You can also run `make winrun` to run the tool from there - ```batch -make winrun +make -f Makefile.own winrun ``` ## Using G++ diff --git a/ffmpeg-coder/DEBIAN/changelog b/ffmpeg-coder/DEBIAN/changelog index 775344a..158ae3d 100644 --- a/ffmpeg-coder/DEBIAN/changelog +++ b/ffmpeg-coder/DEBIAN/changelog @@ -1,3 +1,10 @@ +ffmpeg-coder (1.9.0) unstable: urgency=low + +* New quick convert menu entry +* New quick convert settings added +* Bug fixes +* Upgrade the source code base + ffmpeg-coder (1.0) stable: urgency=low * Initial release. diff --git a/ffmpeg-coder/DEBIAN/control b/ffmpeg-coder/DEBIAN/control index 22e8cec..14adb84 100644 --- a/ffmpeg-coder/DEBIAN/control +++ b/ffmpeg-coder/DEBIAN/control @@ -3,10 +3,10 @@ Section: misc Priority: optional Maintainer: abir-tx Build-Depends: g++, make -Standard-Version: 1.0 +Standard-Version: 1.0.0 Homepage: http://www.github.com/abir-tx/ffmpeg-coder Package: ffmpeg-coder -Version: 1.0 +Version: 1.9.0 Architecture: all Essential: no Size: 20 diff --git a/include/ffmpeg-coder/ffmpeg_coder.hpp b/include/ffmpeg-coder/ffmpeg_coder.hpp index e307308..312eaff 100644 --- a/include/ffmpeg-coder/ffmpeg_coder.hpp +++ b/include/ffmpeg-coder/ffmpeg_coder.hpp @@ -9,7 +9,6 @@ // The FFMPEG class which will hold all kinds of encode options as methods class ffmpeg { private: - std::vector encodes; std::vector crf; std::vector audiobitrate; std::vector videobitrate; @@ -23,6 +22,7 @@ class ffmpeg { bool is_ab_selected = false; int selected_videoBitrate; bool is_vb_selected = false; + std::vector encodes; // Methods ffmpeg(); diff --git a/include/ffmpeg-coder/quickConvertSettings.hpp b/include/ffmpeg-coder/quickConvertSettings.hpp index 291c43e..8a867df 100644 --- a/include/ffmpeg-coder/quickConvertSettings.hpp +++ b/include/ffmpeg-coder/quickConvertSettings.hpp @@ -8,6 +8,9 @@ class QC_Settings{ int setted_crf = 26; int userChoice; std::string default_encoding = "h264"; + + // Private methods + void settingsDataWriter(std::string filePath, std::string settings); public: @@ -20,6 +23,7 @@ class QC_Settings{ void showOptions(); void default_encoding_configurer(); void default_crf_configurer(); + void optionsRouter(); }; #endif \ No newline at end of file diff --git a/lib/alib.hpp b/lib/alib.hpp new file mode 100644 index 0000000..b4b5c39 --- /dev/null +++ b/lib/alib.hpp @@ -0,0 +1,195 @@ +/* +alib is a header only library which offers many usefull and frequently used C++ +functions which are not present in standard c++ library. The library is under +GPL3 license and is open for others to contribute to this project. This library +supports multi platform. It works on both windows and Linux operating system. + +The project is inspired from the rang project. + +The project is maintained by Mushfiqur Rahman Abir aka Abir-Tx. + + +Current Version: v1.0 +Maintainer: Mushfiqur Rahman Abir +Developer Profile https://www.github.com/Abir-Tx +*/ + +#if !defined(ALIB_DOT_HPP) +#define ALIB_DOT_HPP + +// Defining the different platforms +#if defined(__unix__) || defined(__unix) || defined(__linux__) +#define LINUX +#elif defined(WIN32) || defined(_WIN32) || defined(_WIN64) +#define WINDOWS +#elif defined(__APPLE__) || defined(__MACH__) +#define MAC +#else +#error Unknown +#endif + +// Including platform specific files +#if defined(LINUX) || defined(MAC) +#include /* For getting terminal height and width. See consoleWidth() & consoleHeight() */ +#include +#elif defined(WINDOWS) +#include +#endif + +// Including platform independent files +#include +#include +#include + +#include "rang.hpp" /* A third party library for console text styling and coloring */ + +// Functions +namespace alib { +// Function for dynamically decorating a text +void decorateMe(std::string textToDecor) { + using namespace rang; + + int charSize = textToDecor.capacity(); + std::cout << std::endl; + std::cout << fg::red; + for (int i = 0; i < (charSize * 2); i++) { std::cout << "_"; } + std::cout << fg::reset; + std::cout << std::endl; + + std::cout << fg::blue << style::bold << textToDecor << style::reset + << fg::reset; + + std::cout << std::endl; + std::cout << fg::red; + for (int i = 0; i < (charSize * 2); i++) { std::cout << "_"; } + std::cout << fg::reset; + std::cout << std::endl; + std::cout << std::endl; +} + +void decorateMe(std::string textToDecor, unsigned short int lineBreaksNumber) { + using namespace rang; + + int charSize = textToDecor.capacity(); + std::cout << std::endl; + std::cout << fg::red; + for (int i = 0; i < (charSize * 2); i++) { std::cout << "_"; } + std::cout << fg::reset; + for (int i = 1; i <= lineBreaksNumber; i++) { std::cout << std::endl; } + std::cout << fg::blue << style::bold << textToDecor << style::reset + << fg::reset; + + for (int i = 1; i <= lineBreaksNumber; i++) { std::cout << std::endl; } + std::cout << fg::red; + for (int i = 0; i < (charSize * 2); i++) { std::cout << "_"; } + std::cout << fg::reset; + std::cout << std::endl; + std::cout << std::endl; +} + +void decorateMe(std::string textToDecor, unsigned short int lineBreaksNumber, + std::string decorator) { + using namespace rang; + + int charSize = textToDecor.capacity(); + std::cout << std::endl; + std::cout << fg::red; + for (int i = 0; i < (charSize * 2); i++) { std::cout << decorator; } + std::cout << fg::reset; + for (int i = 1; i <= lineBreaksNumber; i++) { std::cout << std::endl; } + std::cout << fg::blue << style::bold << textToDecor << style::reset + << fg::reset; + + for (int i = 1; i <= lineBreaksNumber; i++) { std::cout << std::endl; } + std::cout << fg::red; + for (int i = 0; i < (charSize * 2); i++) { std::cout << decorator; } + std::cout << fg::reset; + std::cout << std::endl; + std::cout << std::endl; +} + +/* Clears the screen depending on OS */ +void clrscr() { +#if defined(LINUX) || defined(MAC) + system("clear"); +#elif defined(WINDOWS) + system("cls"); +#endif +} + +// Return the console's width and height respectively +unsigned int consoleWidth() { +#if defined(LINUX) || defined(MAC) + winsize conSize; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &conSize); + return conSize.ws_col; +#elif defined(WINDOWS) + int width; + CONSOLE_SCREEN_BUFFER_INFO csbi; + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); + width = (int)(csbi.dwSize.X); + return width; +#endif +} + +unsigned int consoleHeight() + +{ +#if defined(LINUX) || defined(MAC) + winsize conSize; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &conSize); + return conSize.ws_row; +#elif defined(WINDOWS) + int height; + CONSOLE_SCREEN_BUFFER_INFO csbi; + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); + height = (int)(csbi.dwSize.Y); + return height; +#endif +} +// Alias for the consoleWidth & consoleHeight funcs +#define terminalWidth consoleWidth +#define terminalHeight consoleHeight + +// Another overload of decorateMe function with print to center ability +void decorateMe(std::string textToDecor, unsigned short int lineBreaksNumber, + std::string decorator, bool isCenter) { + if (isCenter) { + using namespace rang; + + int charSize = textToDecor.capacity(); + + // Getting the terminal center value & starting point of the decorations + unsigned int termCenter = consoleWidth() / 2; + int startingPoint = termCenter - (charSize / 2); + int textToDecor_StartingPoint = startingPoint + ((charSize * 2) - charSize); + + std::cout << std::endl; + std::cout << fg::red; + std::cout << std::setw(startingPoint) << std::setfill(' '); + for (int i = 0; i < (charSize * 2); i++) { std::cout << decorator; } + std::cout << fg::reset; + for (int i = 1; i <= lineBreaksNumber; i++) { std::cout << std::endl; } + std::cout << fg::blue << style::bold << std::setw(textToDecor_StartingPoint) + << std::setfill(' ') << textToDecor << style::reset << fg::reset; + + for (int i = 1; i <= lineBreaksNumber; i++) { std::cout << std::endl; } + std::cout << fg::red; + std::cout << std::setw(startingPoint) << std::setfill(' '); + for (int i = 0; i < (charSize * 2); i++) { std::cout << decorator; } + std::cout << fg::reset; + std::cout << std::endl; + std::cout << std::endl; + } else { + decorateMe(textToDecor, lineBreaksNumber, decorator); + } +} + +} // end of namespace alib + +// Undefining different platforms +#undef LINUX +#undef WINDOWS +#undef MAC + +#endif // ALIB_DOT_HPP diff --git a/src/frontend_funcs.cpp b/src/frontend_funcs.cpp index d9d63db..839cf30 100644 --- a/src/frontend_funcs.cpp +++ b/src/frontend_funcs.cpp @@ -55,7 +55,7 @@ void settings() { QC_Settings *qc = new QC_Settings(); qc->showOptions(); - qc->default_encoding_configurer(); + qc->optionsRouter(); delete qc; } @@ -71,7 +71,7 @@ void settings() { void homepage() { using namespace std; - ffmpeg ffmpeg; // Creating ffmpeg object + int choice; /* The char goBack variable is used for navigating to the main screen using @@ -103,13 +103,17 @@ void homepage() { // Entering into selected option funcs if (choice == 1) { + ffmpeg *fmpg = new ffmpeg(); // Creating ffmpeg object clear_screen(); - ffmpeg.load_encodes(); - ffmpeg.show_encodes(); - ffmpeg.select_encodes(); - ffmpeg.selected_action(); + fmpg->load_encodes(); + fmpg->show_encodes(); + fmpg->select_encodes(); + fmpg->selected_action(); + delete fmpg; } else if (choice == 2) { - ffmpeg.quickConvert(); + ffmpeg *fmpg = new ffmpeg(); // Creating ffmpeg object + fmpg->quickConvert(); + delete fmpg; } else if (choice == 3) { about(); } else if (choice == 4) { diff --git a/src/quickConvertSettings.cpp b/src/quickConvertSettings.cpp index 4ab6b4a..ee596f8 100644 --- a/src/quickConvertSettings.cpp +++ b/src/quickConvertSettings.cpp @@ -1,73 +1,150 @@ -// #include "ffmpeg_coder.hpp" -#include +#include "rang.hpp" +#include "quickConvertSettings.hpp" +#include "alib.hpp" +#include "ffmpeg_coder.hpp" #include +#include +#include #include -#include "quickConvertSettings.hpp" -void QC_Settings::set_setted_crf(){ - - } +void QC_Settings::set_setted_crf() { + std::fstream qcsData; + qcsData.open("appData/qcs_crf.bin", std::ios::in); + + if (qcsData.is_open()) { + std::string def_crf; + while (getline(qcsData, def_crf)) { def_crf = def_crf; } + + if (def_crf == "20") + setted_crf = 20; + else if (def_crf == "24") + setted_crf = 24; + else if (def_crf == "26") + setted_crf = 26; + else if (def_crf == "28") + setted_crf = 28; + else + setted_crf = 26; -int QC_Settings::get_setted_crf(){ + } else { + setted_crf = 26; + } +} + +int QC_Settings::get_setted_crf() { + set_setted_crf(); return setted_crf; } -void QC_Settings:: setDefault_encoding(){ - std::fstream qcsData; - qcsData.open("appData/qc_settingsData.bin", std::ios::in); - - if (qcsData.is_open()){ - std::string def_encoding; - while (getline(qcsData, def_encoding)) - { - default_encoding = def_encoding; - } - }else{ - default_encoding = "h264"; - } - std::cout< options; + options.push_back("Set Default Encoding"); + options.push_back("Set default CRF"); + + // Showing the options + for (int i = 0; i < options.size(); i++) { + std::cout << (i + 1) << ". " << options[i] << std::endl; + } + + // Taking user input + std::cout << rang::style::bold << rang::fg::blue + << "\nChoose your option: " << rang::style::reset + << rang::fg::reset; + std::cin >> userChoice; +} + +void QC_Settings::settingsDataWriter(std::string filePath, + std::string settings) { + try { + std::fstream qcsData; + qcsData.open(filePath, std::ios::out); + + if (qcsData.is_open()) { + qcsData << settings; - std::vector options; - options.push_back("Set Default Encoding"); - options.push_back("Set default CRF"); + std::cout + << "\n|You preferred settings have been saved for future|"; + } else + throw 501; + } catch (...) { std::cerr << "Error occured while openning data file!"; } +} + +void QC_Settings::default_encoding_configurer() { + clear_screen(); + std::string givenEncoding; + int selectedOption; + // Showing the current default encoding + std::string currentDef = "The current default is: " + default_encoding; + alib::decorateMe(currentDef, 1, " ", true); - // Showing the options - for (int i =0; i < options.size(); i++){ - std::cout << (i+1) << ". " << options[i] << std::endl; - } + // Taking new encoding from user + ffmpeg *fmpg = new ffmpeg(); + fmpg->load_encodes(); + fmpg->show_encodes(); + selectedOption = fmpg->select_encodes(); - // Taking user input - std::cout<< "Choose your option:"; - std::cin >> userChoice; + if (selectedOption == 1) { + settingsDataWriter("appData/qcs_encoding.bin", fmpg->encodes[0]); + } else if (selectedOption == 2) { + settingsDataWriter("appData/qcs_encoding.bin", fmpg->encodes[1]); + } else + std::cerr << "\nInvalid Option Selected ! Try again"; } -void QC_Settings::default_encoding_configurer(){ - // std::string givenEncoding; - // int selectedOption; - - // // Showing the current default encoding - // std::cout<< "The current default is: "<< default_encoding; - // std::cout<load_encodes(); - // fmpg->show_encodes(); - // selectedOption = fmpg->select_encodes(); - - // if (selectedOption == 1) - // std::cout<<"hey"; - // else - // std::cout<<"HOO"; -} \ No newline at end of file +void QC_Settings::default_crf_configurer() { + clear_screen(); + std::string givenCrf; + int selectedOption; + + // Showing the current default encoding + // std::string currentDef = "The default is: 26"; + // alib::decorateMe(currentDef, 1, " ", true); + + // Taking new encoding from user + ffmpeg *fmpg = new ffmpeg(); + fmpg->select_crf(); + selectedOption = fmpg->selected_crf; + + if (selectedOption == 20) + settingsDataWriter("appData/qcs_crf.bin","20"); + else if (selectedOption == 24) + settingsDataWriter("appData/qcs_crf.bin","24"); + else if (selectedOption == 26) + settingsDataWriter("appData/qcs_crf.bin","26"); + else if (selectedOption == 28) + settingsDataWriter("appData/qcs_crf.bin","28"); + else + settingsDataWriter("appData/qcs_crf.bin","26"); +} + +void QC_Settings::optionsRouter() { + if (userChoice == 1) + default_encoding_configurer(); + else if (userChoice == 2) + default_crf_configurer(); + else + std::cout << "\nInvalid choice. Try again\n"; +}