如何将视频拆分为多个部分,然后将其与FileStream C#合并

时间:2015-10-01 15:11:07

标签: c#-4.0 merge split filestream slice

我在拆分文件时遇到一些问题,我现在不知道该怎么办。我必须拆分电影,然后将拆分的元素合并为一个。我必须使用FileStream。如果你能帮助我,我将非常高兴:)

using System;
using System.Collections.Generic;
using System.IO;

class Program
{
    static void Main()
    {
        string source = "../../movie.avi";
        string destination;
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        { 
            destination = "Part-" + i +".avi";
            Slice(source, destination, n);
        }

        List<int> files = new List<int>();
        //Assemble(, destination);
    }

    static void Slice(string sourceFile, string destinationDirectory, int parts)
    {
        using (var source = new FileStream(sourceFile, FileMode.Open))
        {
            for (int i = 0; i < parts; i++)
            {
                using (var destination = new FileStream(destinationDirectory, FileMode.CreateNew))
                {
                    double fileLength = source.Length;
                    byte[] buffer = new byte[4096];
                    while (true)
                    {
                        int readBytes = source.Read(buffer, 0, buffer.Length);
                        if (readBytes == 0)
                        {
                            break;
                        }
                        destination.Write(buffer, 0, readBytes);
                    }
                }
            }
        }
    }
    static void Assemble(List<string> files, string destinationDirectory)
    {

    }
}

0 个答案:

没有答案