public WriteToVideo(String[] filelistin, Tracker[] trackerlistin, String outputfolderin, String ffmpegLocationin, Boolean hiddenIn)
 {
     filelist = filelistin;
     trackerlist = trackerlistin;
     outputfolder = outputfolderin;
     ffmpegLocation = ffmpegLocationin;
     hidden = hiddenIn;
 }
 // create command
 // add to txt
 // remove files that will be created
 // execute command
 private int cutParts(String file, Tracker tracker, StreamWriter txtfile)
 {
     String[] outputFiles;
     List < int[] > timelist = tracker.getList();
     // check if tracker empty
     if (timelist == null)
     {
         return 2; // make it return 2 instead of 0, so we can detect if no movement in whole file
     }
     // loop over all elements and create command string and add to txt
     outputFiles = new String[timelist.Count];
     for (int i = 0; i < timelist.Count; i++)
     {
         String outputfile = outputfolder + "\\" + Path.GetFileNameWithoutExtension(file) + "_" + i + ".mp4";
         outputFiles[i] = outputfile;
         temporaryFiles.Add(outputfile);
         // Command = ffmpeg -i testvid.avi -ss 00:01:34 -to 00:02:22 -c:v libx264 -preset ultrafast newStream1.mp4
         String command = "/C "; // quit terminal after executing
         //command += ffmpegLocation; // add ffmpeglocation
         command += "cd \"" + Path.GetDirectoryName(ffmpegLocation) + "\" && ";
         command += Path.GetFileName(ffmpegLocation);
         command += " -i " + "\"" + file + "\""; // add file location
         command += " -ss " + convertLength(timelist[i][0]);
         command += " -to " + convertLength(timelist[i][1]);
         //command += " -vcodec copy -preset ultrafast "; -- use this for speed but lower accuracy
         command += " -preset ultrafast ";
         command += "\"" + outputfile + "\""; // add outputfile
         // add to txt: "file 'C:\Users\michael\Documents\newtestvids\newStream1.mp4'"
         String toAddToTxt = "file '" + outputfile + "'";
         txtfile.WriteLine(toAddToTxt);
         // execute command
         clearFile(outputfile);
         int result = runCommand(command);
         if(result != 0)
         {
             return 1;
         }
     }
     // add outputfiles to the temporaryfiles list
     temporaryFiles.AddRange(outputFiles);
     return 0; // 0 for succes, 1 for fail
 }
 // Function to process the file
 public int doProcess(ProgressStorage progressStorage)
 {
     currentFrame = 0;
     reader = new VideoFileReader();
     try
     {
         reader.Open(file);
     }
     catch
     {
         return 1;
     }
     int frameCount = (int)reader.FrameCount;
     tracker = new Tracker(movementWindow);
     int nrofiterations = frameCount / 200;
     int i = 0;
     int nrofframes = 0;
     while (i < nrofiterations)
     {
         nrofframes = 200;
         loadinPart(nrofframes, area);
         if(i == 0) // store first frame as background frame
         {
             backgroundFrame = imageStack[0].Clone(new Rectangle(0, 0, imageStack[0].Width, imageStack[0].Height), imageStack[0].PixelFormat);
         }
         processFilePart();
         progressStorage.incrementProgress(currentFrame);
         i++;
     }
     nrofframes = frameCount - currentFrame;
     loadinPart(nrofframes, area);
     if (nrofiterations == 0) // store first frame as background frame if nrofiterations is 0
     {
         backgroundFrame = imageStack[0].Clone(new Rectangle(0, 0, imageStack[0].Width, imageStack[0].Height), imageStack[0].PixelFormat);
     }
     processFilePart();
     progressStorage.incrementProgress(currentFrame);
     tracker.closeList(currentFrame);
     reader.Close(); // close the file
     return 0;
 }