0

I want to split my videos (my videos from 10GB To 100GB) to smaller part by size (not time). For example, convert a 20GB video to 10 * 2GB Video And each of these videos can be played and used.

I used this example but the videos made are not playable

private static void ReadFile(string filePath)
{
    const int MAX_BUFFER = 1048576; //1MB 
    byte[] buffer = new byte[MAX_BUFFER];
    int bytesRead;
    int noOfFiles = 0;
    using (FileStream fs = File.Open(filePath, FileMode.Open, FileAccess.Read))
    using (BufferedStream bs = new BufferedStream(fs))
    {
        while ((bytesRead = bs.Read(buffer, 0, MAX_BUFFER)) != 0) //reading 1mb chunks at a time
        {
            noOfFiles++;
            //Let's create a small size file using the data. Or Pass this data for any further processing.

            File.WriteAllBytes($"Test{noOfFiles}.txt", buffer);
        }
    }
}

I also saw this: Splitting a video in four files in C# but this cut a video by time/sec.

So how can I do this with C# ?

Alexander van Oostenrijk
  • 4,644
  • 3
  • 23
  • 37
oooa s
  • 35
  • 1
  • 7
  • 3
    The example you have doesn't understand what the file is. It just splits the data into chunks without understanding it. An analogy would be a human cutting an A4 document into paragraphs, vs a shredder just making cuts at predefined intervals (in mm or inches). – ProgrammingLlama Aug 17 '21 at 09:04
  • Perhaps you could use ffmpeg (I would): https://stackoverflow.com/questions/38259544/using-ffmpeg-to-split-video-files-by-size – ProgrammingLlama Aug 17 '21 at 09:05
  • Easiest is probably to split the file at the closest available i-frame. But that require tools that can unpack/repack the video-file. You could also re-compress the video, but then you have to determine the desired quality and average bitrate to reach that quality somehow. – JonasH Aug 17 '21 at 09:40

0 Answers0