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.

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.

6 thoughts on “How to Convert Multi-Frame Cine Loops to AVI or MP4 Format Using PHP

  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.

  3. Hi Dean, thanks for sharing this wonderful class.

    I tried to convert the sample.dcm but got the following log:

    ./dcm2mp4.php sample.dcm
    20170720 15:08:39: Working with -> sample.dcm
    20170720 15:08:39: sample.dcm has frames running at 24 fps.
    20170720 15:08:39: sample.dcm does not have multiple frames, creating JPEG.

    Is there anything I am doing wrong?


Leave a Reply

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