How to Convert Multi-Frame Cine Loops to AVI or MP4 Format Using PHP

In this tutorial I’m going to post some example code and walk you through converting a DICOM multi-frame image (CINE Loop) into an mp4 video file. I chose MP4 because it works well with Apple and Microsoft products.

You’ll need ffmpeg installed with the ability to do x264. The ffmpeg site has many guides on how to do this. I used this guide for CentOS 6 for this tutorial.

You’ll need a copy of my PHP DICOM class installed.

You’ll need a copy of the example files.

Once you’ve got the prerequisites out of the way, run the commands below to download and run a copy of the example files.

wget http://www.deanvaughan.org/projects/multi-frame-to-mp4.tar.gz
tar zxvf multi-frame-to-mp4.tar.gz
cd Mutli-Frame_to_MP4/
./dcm2mp4.php sample.dcm

Your freshly created MP4 file is ./video_temp/sample.dcm.mp4, a copy is playing below:

Now take a look at dcm2mp4.php, it should be commented well enough to make it easy to understand what it is doing.

3 comments

  1. class_dicom.php didn’t produce a video! ./video_temp/IM_0001.dcm.mp4

    I am getting this kinf of error why is it can u help me?

  2. Hi,
    In class_dicom.php I had to change line ~328 to:
    $vid_cmd = “/usr/bin/ffmpeg -report -i %03d.jpg -r $framerate -b 5000k -vcodec libx264 $vid_file”;
    So the -i option (input file) is now before all other options.
    The option -report dumps (for debugging) a log file in the working directory.

Leave a Reply

Your email address will not be published. Required fields are marked *