Trying to convert MP4 video file DICOM VIdeo File

360 views
Skip to first unread message

Sushrut Deo

unread,
Aug 26, 2020, 9:45:43 AM8/26/20
to Fellow Oak DICOM
Hi,

I am trying to convert MP4 video file to DICOM video file. Has anyone done this previously? I need some help. When I add metadata to this file, it gets corrupted. 

geert.e.va...@gmail.com

unread,
Aug 26, 2020, 10:53:02 AM8/26/20
to Fellow Oak DICOM
Hi,

Make sure you pad the MP4 when uneven length.

Sushrut Deo

unread,
Aug 26, 2020, 11:08:17 AM8/26/20
to Fellow Oak DICOM
Thanks for your reply. I am not sure how I can do that. I am quite new in the field of image processing and DICOM. I am using .Net Framework. An example will be useful.

geert.e.va...@gmail.com

unread,
Aug 26, 2020, 11:52:12 AM8/26/20
to Fellow Oak DICOM
of course you need to add the necessary tags that are required by the IOD, but for padding I used this:
    ...
    //----add video bytes
        byte[] videoBytes = getVideoBytes(videoFile);
        MemoryByteBuffer buffer = new MemoryByteBuffer(videoBytes);
        
        pixelData.AddFrame(buffer);
 
        DicomFile dicomfile = new DicomFile(dataset);        
        dicomfile.Save("mp4.dcm");
    }
 
 
 
    private static byte[] getVideoBytes(string videoFile)
    {
        //FileInputStream fis = new FileInputStream(videoFile);
        //ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
        //byte[] buf = new byte[1024];
        //int n;
        //while (-1 != (n = fis.Read(buf)))
        //    baos.Write(buf, 0, n);
        //byte[] videoBytes = baos.ToByteArray();
        //return videoBytes;
        byte[] buff = null;
        FileStream fs = new FileStream(videoFile, 
                                   FileMode.Open, 
                                   FileAccess.Read);
        BinaryReader br = new BinaryReader(fs);
        long numBytes = new FileInfo(videoFile).Length;
        Console.WriteLine(numBytes);
        if (numBytes % 2 != 0)
        {
            //System.Array.CreateInstance<byte>(ref buff, numBytes+1);
            buff = br.ReadBytes((int) numBytes);
            Console.WriteLine(buff.Length);
            System.Array.Resize<Byte>(ref buff, buff.Length+1);
            Console.WriteLine(buff.Length);
            buff[buff.Length-1] = 0x00;
        }
        else
        {
            buff = br.ReadBytes((int) numBytes);
        }
        return buff;
    }

Sushrut Deo

unread,
Aug 26, 2020, 1:44:30 PM8/26/20
to Fellow Oak DICOM
Thank you very much.
Reply all
Reply to author
Forward
0 new messages