Wednesday, September 17, 2014

A short one on MPEG to DICOM

This is a quick post referencing our new release of RZDCX 2.0.4.2 that adds the option to convert MPEG to DICOM. I will post a longer article with all the information about MPEG and DICOM, video streams and audio hopefully by the end of this month. Meanwhile, check out this post on our web site and download the latest version of RZDCX DICOM SDK.
Here's a short C++ code snippet that creates a DICOM encapsulated MPEG to start with:

static void CreateVideo(string filename)
{
    /// Create a DCXOBJ
    IDCXOBJPtr obj(__uuidof(DCXOBJ));

    /// Create an element pointer to place in the object for every tag
    IDCXELMPtr el(__uuidof(DCXELM));

IDCXUIDPtr id(__uuidof(DCXUID));

rzdcxLib::ENCAPSULATED_VIDEO_PROPS videoProps;
videoProps.width = 352;
videoProps.Height = 288;
videoProps.PixelAspectRatioX = 4;
videoProps.PixelAspectRatioY = 3;
videoProps.FrameDurationMiliSec; // 40 msec = 25 FPS
videoProps.NumberOfFrames = 1600; // 1600 frames
videoProps.VideoFormat = rzdcxLib::MPEG2_AT_MAIN_LEVEL;
obj->SetVideoStream(filename.c_str(), videoProps);


obj->TransferSyntax = rzdcxLib::TS_MPEG2_MAIN_PROFILE_AT_HIGH_LEVEL;
    /// You don't have to create an element every time, 
    /// just initialize it.
char pn[]="John^Doe";
    el->Init(rzdcxLib::PatientsName);
    el->PutCStringPtr((int)pn);
    obj->insertElement(el);

el->Init(rzdcxLib::patientID);
    el->Value = "123765";
    obj->insertElement(el);

el->Init(rzdcxLib::studyInstanceUID);
el->Value = id->CreateUID(UID_TYPE_STUDY);
obj->insertElement(el);

el->Init(rzdcxLib::seriesInstanceUID);
el->Value = id->CreateUID(UID_TYPE_SERIES);
obj->insertElement(el);
el->Init(rzdcxLib::sopInstanceUID);
el->Value = id->CreateUID(UID_TYPE_INSTANCE);
obj->insertElement(el);

el->Init(rzdcxLib::sopClassUid);
el->Value = "1.2.840.10008.5.1.4.1.1.77.1.4.1"; // Video Photographic Image Storage
obj->insertElement(el);

el->Init(rzdcxLib::NumberOfFrames);
el->Value = (short)1600;
obj->insertElement(el);

el->Init(rzdcxLib::FrameIncrementPointer);
el->Value = rzdcxLib::FrameTime;
obj->insertElement(el);

filename += ".dcm";
obj->saveFile(filename.c_str());

}

One last note: You should know your video properties because we don't open or validate the MPEG file. More on "why is it this way" in the longer post soon.

No comments:

Post a Comment