Example #1
0
        // 0: succes, 1: error, 2: no movement in file
        public int WriteVideo(ProgressStorage progressStorage)
        {
            int movementSomewhere = 1;

            // create txt file that will be used to join all videos
            temporaryFiles = new List <String>();
            String txtPath = outputfolder + "\\output_temptxtfile.txt";

            temporaryFiles.Add(txtPath); // add to files that will be removed after execution
            StreamWriter outputtxt = new StreamWriter(txtPath, false);

            // convert to mp4 in original quality, create subparts and add then to the outputtxt
            for (int i = 0; i < filelist.Length; i++)
            {
                String toDeleteFile = convertPart(filelist[i]); // no result needed, because if this failed, next one will fail as well
                int    result       = cutParts(toDeleteFile, trackerlist[i], outputtxt);
                if (result == 1)                                // it failed
                {
                    // remove all temporary objects here (close txt first)
                    outputtxt.Close();
                    clearFiles(temporaryFiles);
                    progressStorage.resetGeneration(); // update progressStorage
                    return(1);                         // something failed
                }
                else if (result == 0)
                {
                    // if we get in to this part at least once, it means there is movement in some of the files
                    movementSomewhere = 0;
                }
                clearFile(toDeleteFile);                  // delete temp file
                progressStorage.generationFileFinished(); // update progressStorage
            }
            int result2;

            outputtxt.Close();
            if (movementSomewhere == 0)
            {
                // execute the command to join the subfiles
                result2 = joinParts(txtPath);
            }
            else
            {
                result2 = 2;
            }
            // remove all temporary files
            clearFiles(temporaryFiles);
            if (result2 != 1)
            {
                progressStorage.generationFileFinished(); // update progressStorage
            }
            else
            {
                progressStorage.resetGeneration(); // update progressStorage
            }
            return(result2);
        }
 // 0: succes, 1: error, 2: no movement in file
 public int WriteVideo(ProgressStorage progressStorage)
 {
     int movementSomewhere = 1;
     // create txt file that will be used to join all videos
     temporaryFiles = new List<String>();
     String txtPath = outputfolder + "\\output_temptxtfile.txt";
     temporaryFiles.Add(txtPath); // add to files that will be removed after execution
     StreamWriter outputtxt = new StreamWriter(txtPath, false);
     // convert to mp4 in original quality, create subparts and add then to the outputtxt
     for (int i = 0; i < filelist.Length; i++)
     {
         String toDeleteFile = convertPart(filelist[i]); // no result needed, because if this failed, next one will fail as well
         int result = cutParts(toDeleteFile, trackerlist[i], outputtxt);
         if(result == 1) // it failed
         {
             // remove all temporary objects here (close txt first)
             outputtxt.Close();
             clearFiles(temporaryFiles);
             progressStorage.resetGeneration(); // update progressStorage
             return 1; // something failed
         } else if (result == 0)
         {
             // if we get in to this part at least once, it means there is movement in some of the files
             movementSomewhere = 0;
         }
         clearFile(toDeleteFile); // delete temp file
         progressStorage.generationFileFinished(); // update progressStorage
     }
     int result2;
     outputtxt.Close();
     if(movementSomewhere == 0)
     {
         // execute the command to join the subfiles
         result2 = joinParts(txtPath);
     } else
     {
         result2 = 2;
     }
     // remove all temporary files
     clearFiles(temporaryFiles);
     if(result2 != 1)
     {
         progressStorage.generationFileFinished(); // update progressStorage
     }
     else
     {
         progressStorage.resetGeneration(); // update progressStorage
     }
     return result2;
 }
        // 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);
        }
        private String resultFolder; // folder where the result will be outputted

        // Constructor
        public Brain()
        {
            Status          = 0;
            progressStorage = new ProgressStorage();
        }
        private String resultFolder; // folder where the result will be outputted

        // Constructor
        public Brain() 
        {
            Status = 0;
            progressStorage = new ProgressStorage();
        }
 // 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;
 }