-1

I have multiple videos segments created by CCTV camera after every 5 mins and I want a program which accept time range as input and join all videos, created between that range by CCTV camera. How can I achieve this?

Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
Nirmal
  • 161
  • 15

2 Answers2

0

This function reads your files and append them together , you can extend this function to accept time range :

    public void AppendFiles2(string SavePath)
    {
        int bytesRead;
        byte[] buffer = new byte[1024];
        string[] files = Directory.GetFiles(@"path").ToArray(); // Array of files to be appended
        FileStream fswrite = new FileStream(SavePath + @"\FileName" + Path.GetExtension(files[0]), FileMode.Append, FileAccess.Write);
        for (int i = 0; i < files.Length; i++) //for each file in the files array reasd them and append
        {
            FileStream fsread = new FileStream(files[i], FileMode.Open, FileAccess.Read);
            bytesRead = 1;
            while (bytesRead != 0)//while not at the end of file
            {
                bytesRead = fsread.Read(buffer, 0, buffer.Length); //read file
                fswrite.Write(buffer, 0, bytesRead); //write ( append ) it to the target file
            }
            fsread.Close();
        }
        fswrite.Close();
    }
ako
  • 2,000
  • 2
  • 28
  • 34
  • Thanks, this code creates target file with size of summation of multiple files but when we watch video it plays only one video, first one. – Nirmal Feb 11 '16 at 09:00
  • your files must be in a manner named that all of them can be appended in order . Try to rename them from for example file1.mp4 , file2.mp4 and so on ... . – ako Feb 11 '16 at 10:34
  • They are in proper ordered but when I play that new final file, file that created by program by merging all videos, it just play one video, for example file1.mp4, it should play all videos one after another. Hope I am making sense to you. – Nirmal Feb 11 '16 at 10:44
  • @Nirmal in the code above put a BreadPoint after files go into the array and see into the array if they are in that manner of there is no problem wiht them and see inside for loop also using BrakPoint to see if there is not somethig wrog with it.....it works for me properly...i have used it many times with no problem – ako Feb 11 '16 at 10:48
  • I have V1.mp4(3.71 MB), v2.mp4(2.65 MB), v3.mp4(2.86 MB) and v4.mp4(5.25 MB), when I run program it creates file V1234.mpz(14.4 MB - Total size of all small files.) and when I try to play player plays only video of V1.mp4. This is the issue it should play V1, V2, V3 and V4. – Nirmal Feb 11 '16 at 11:09
  • @Nimal sorry the above code works when all files are different parts of a single file and then you want to merger them together ( i used it when downloading a file using multiple parts and then append them together , it works fine in that case ) see [here](http://stackoverflow.com/questions/6890699/how-to-merge-2-video-files-together-in-c) to a better answer – ako Feb 11 '16 at 12:47
0

Video files contain a Header (with details about the length of the video clip and the resolution) and then the video data.

When you add the join the files you need to create a new header that has the new length of all the video. This needs software that can identify and change video headers.

The best tool for this is the 'ffmpeg' program which can concatenate video files. There are instructions on the ffmpeg web site https://trac.ffmpeg.org/wiki/Concatenate

RogerH
  • 31
  • 3