piektdiena, 2021. gada 5. novembris

VIDEO EDITOR CONSOLE. *PSEUDO* CODE. (NOT FINISHED - MIGHT WORK!!)

IF YOU ALWAYS WANTED VIDEO EDITOR THAT JUST TRIMS AND MERGES CLIPS BASED ON CONSOLE INPUT - HERE IS THE C++ VERSION SOURCE CODE.
HOW TO COMPILE? INSTALL g++ AND ffmpeg (CODE IS FOR LINUX SO FAR!!!)
sudo apt install g++
then create new file editor.cpp
compile the file from command line -
g++ -std=c++17 editor.cpp -o editor

copy binary (editor) to /home/ and run the binary ./editor





#include <string>
#include <iostream>
#include <fstream>
#include <filesystem>
#include <algorithm>
#include <unistd.h>

//g++ -std=c++17 editor.cpp -o editor
namespace fs = std::filesystem;
bool in_array(const std::string & value,
  const std::vector < std::string > & array) {
  return std::find(array.begin(), array.end(), value) != array.end();
}
int main() {
//get username 
    std::string Username = getlogin();
//opens file list
  system((std::string("cat /home/") + Username + std::string("/renders/mylist.txt")).c_str());

//asks which folder should program choose
  std::string mape;
  std::cout << "Kura mape?" << "!\n";
  std::cin >> mape;
//asks which file name should final render choose
  std::cout << "Final faila nosaukums? !\n";
  std::string finalnosaukums;
  std::cin >> finalnosaukums;
  std::string path = "/home/" + Username + mape;
  std::vector < std::string > arr;

int guesses = 0;





//counts how many files are in choosed directory
auto dirIter = std::filesystem::directory_iterator(mape);
int fileCount = 0;
for (auto& entry : dirIter)
{
    if (entry.is_regular_file())
    {
        ++fileCount;
    }
}





  for (const auto & entry: fs::directory_iterator(path)) {
    std::string name;
    std::cout << "Kurais video? !\n";
    std::cout << entry.path() << std::endl;
    std::cin >> name;
    if (in_array(name, arr)) {
      //std::cerr << "Found at position " << std::distance(std::array, foo) << endl;
      std::cout << "Kurais video? !\n";
      std::cin >> name;
      std::cout << "Masīva garums. jeb cik video jau pievienoti:" << sizeof(arr) << "!\n";
      std::cout << entry.path() << std::endl;
    } else {
      std::cout << "Not found" << std::endl;
      arr.push_back(name);
    }
    std::cout << entry.path() << name << "!\n";
  }
  for (const auto & entry2: fs::directory_iterator(path)) {
    guesses++;

    std::string name2;
    std::cout << "Kurais video?" << name2 << "!\n";
    std::cout << entry2.path() << std::endl;
    std::cin >> name2;
    if (in_array(name2, arr)) {
      //std::cerr << "Found at position " << std::distance(garumi, foo) << endl;
      std::cout << "Kurais video?" << name2 << "!\n";
      std::cin >> name2;
      //std::cout << "Masīva garums. jeb cik video jau pievienoti:" << size << "!\n";
      std::cout << entry2.path() << std::endl;
    } else {
      std::cout << "Not found" << std::endl;
      if (in_array(name2, arr)) {
        system("ffprobe -i name2 -show_entries format=duration -v quiet -of csv='p=0'");
        int vienav = system("ffprobe -i name2 -show_entries format=duration -v quiet -of csv='p=0'");
        std::cout << "No kuras sekundes sākt? !\n";
        int sakums;
        std::cin >> sakums;
        std::cout << "No kuras sekundes beigt? !\n";
        int beigas;
        std::cin >> beigas;
        if (vienav > beigas) {
          system((std::string("ffmpeg -i name2 -ss") + std::to_string(sakums) + std::string("to") + std::to_string(beigas) + std::string("-c:v libx264 -crf 30 trim_opseek") + name2).c_str());
        } else {
          system("ffprobe -i name2 -show_entries format=duration -v quiet -of csv='p=0'");
          std::cout << "PARSNIEDZI LIMITU ... No kuras sekundes beigt" << beigas << "!\n";
        }
      }
    }
    std::cout << entry2.path() << name2 << "!\n";
  }





if(fileCount === guesses){


  system((std::string("ffmpeg -f concat -safe 0 -i mylist.txt -c copy /home/") + Username + std::string("/renders"), finalnosaukums).c_str());


}


}