Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to merge 8 byte arrays belong to an MKV file into one byte array,so into original file. When I try this with normal methods such as Buffer.BlockCopy() mkv file does have no sound. I have no problem with mp4,mp3 or some media files I tried. Is it necessary any class file or dll to do this?

EDIT : So I am trying to explain more clearly.
My code can download any file that supports range property dividing filesize into 8 same sized byte array part and using HttpWebRequest.AddRange(int from,int to) method. When all download threads finished I combine all byte array into one byte array in the correct order and then I write it to file with right filename and extension. But as I said just mkv videos have no sound. I have no problem any other file extension.And that's right I don't know much about media file encoding.I hope I can be understandable. Here is my combine code:
C#
byte[] combineDATAS()
{
    byte[] fileDataArray = new byte[contentLength];
    int dstOffset = 0;
    foreach (byte[] array in downloadedDataArrays)
    {
        Buffer.BlockCopy(array, 0, fileDataArray, dstOffset, array.Length);
        dstOffset += array.Length;
    }
    return fileDataArray;
}

void writeDataToFile(byte[] fileDataArray)
{
    Stream fileStr = File.Create(FileName);
    Stream byteStream = new MemoryStream(fileDataArray);

    byte[] buffer = new byte[1024];
    int readBytes = 0;
    int offSet = 0;
    while ((readBytes = byteStream.Read(buffer, 0, buffer.Length)) > 0)
    {
        fileStr.Write(buffer, 0, readBytes);
        offSet += readBytes;
        writingPercentage = (int)((offSet / 1.0 / byteStream.Length) * 100);
    }
    fileStr.Close();
    byteStream.Close();
}
Posted
Updated 20-Nov-14 11:02am
v3
Comments
Sergey Alexandrovich Kryukov 19-Nov-14 17:25pm    
Not clear.
—SA
[no name] 19-Nov-14 18:04pm    
8 Byte Arrays e.g.
1. Maybe 10 Bytes
2. Maybe 20 Bytes
...
7. Maybe 50 Bytes
8. Maybe 2 Bytes

should go to one array?
And then you do not have Sound? and what is about Video? mka=mk_audio, mkv=mk_video.

Anyway I can't believe that you really know i.e. mp3, because mp3 is a coded bit stream and if you simply try to "copy some Bytes from anywhere" you will fail.
[no name] 20-Nov-14 18:37pm    
Do you have the original file? If not I suggest you are wasting your time. Have you compared this with your resulting file?
Amt-Coder 21-Nov-14 16:49pm    
I tested it comparing my download program and IDM.If a youtube mkv video is downloaded by clicking IDM's green bar to download video that appears on video frame while a video is streaming,the downloaded file extension is .MKV and it has both sound and image . But if I copy the video source URL from IDM and paste to my download program and to IDM using IDM's "Add Url" option both of downloaded file extension is .WEBM and video has no sound. What may be the reason?
[no name] 21-Nov-14 17:36pm    
Now it becomes interesting ;)
Read this (i will not do it for you), maybe it helps: http://en.wikipedia.org/wiki/WebM[^]

1 solution

I recommend calling out to FFMpeg[^].  Maybe this[^] CP article will help.

/ravi
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900