Saturday, June 9, 2012

Tutorial: How to encode Digital Cinema Package (DCP )

As filmmakers we will at some point want to exhibit our films on the large screen, to a packed theater (hopefully... though I've been to a festical screening or two of Archon Defender where I was the only one in the theater) Most film fests will be capable of screening a DVD version (this format is getting old... but in a worse case scenario it's good to have as a fallback) or directly from a computer into a digital projector using an .avi .mp4 or .mov file.

For the occasional holdout festicals still stuck in the technological dark ages, they may insist on an actual 35 mm print (this can cost upwards of $10,000 for a single print, for a feature film, give or take a few grand 'pocket change') For 3D films (of which Origin: A Call to Minds is...) the only real option for theatrical screening in 3D is a Digital Cinema Package or DCP

A DCP is designed to keep all the expense and hassle of an actual film print while minimizing any actual benefit that a digital file would permit in terms of bringing ease of creation and access to the independent filmmaker. DCP allows for optional encryption, which prevents theater staff from sneaking in and copying a 2K or 4K perfect copy of a film onto a usb drive and uploading it to The Pirate Bay. Which is one reason why we're all still stuck with crappy cam versions of pirated films which in some cases are just as bad a watching the actual film in the theater... but I digress...

For the last couple of weeks (more on this later...) I've been using the freeware / open source application OpenDCP to create a 3D DCP in anticipation of upcoming film festival entries:

Software used:
Hardware required:
  • 2 TB or so of free harddrive

Step 1: Lossless AVI Master

The master for Origin is a sequence of .avi files using the lossless HuffYUV codec, 720p HD resolution, separated into "chapters" for convenience, and consisting of Left and Right eye streams, plus an audio soundtrack in .wav format.


There's a pile of these sequences and I use an avisynth script to join them all together into a master comp for both the Left and Right eye stream. From here I can do any encoding I want using *this* script as the input for another avisynth script, changing the resolution and comping the streams for:
  • DVD
  • Divx / mp4 @ 720p HD
  • 3D anaglyph 'optimized' for color
  • 3D Side by side or over-under for 3D monitors / TV's
  • Image sequence output
Avisynth will let you write out an image file sequence of your streams. OpenDCP requires a sequence of .tiff images in any of several 'compliant' resolutions, I used 2k resolution which is 1998x1080 'flat' aspect ratio. I mastered Origin in 24fps, OpenDCP accepts frame rates of 24,25,30,48,50,60 fps.

Step 2: Writing the .tiff files
Here's the Avisynth script I use to write the .tiff image sequence. This is the part that is going to eat your harddrive.

# Convert to 1.85:1 aspect 2K projection image
# which is apparently 1998 x 1080
# from 1280 x 640 2:1 aspect

# Load and prepare source files

# avisource( "ACM000 All Comps R.avs" )
avisource( "ACM000 All Comps L.avs" )

# process crop and scale
#
# X Y PAD Y
# source 1280 640
# target 1998 999 81 (40 top , 41 bottom)

BilinearResize (1998, 999)
AddBorders (0, 40, 0, 41, $000000)

# info

# ImageWriter(file = "H:\DCP\1 Source TIFF and AUDIO\Right
\OriginACM_R_", start = 0, end = 0, type = "tiff"
, info = true)
ImageWriter(file = "H:\DCP\1 Source TIFF and AUDIO\Left\
OriginACM_L_", start = 0, end = 0, type = "tiff",
info = true)

Origin is 80 minutes long. 3D means that there's twice that amount of actual footage to encode. At this point you now have 1.56 TB of images in two directories, one for the Left and one for the Right stream (folder 3 is for the audio...more on that later...):


Luckily the rest of this process is not nearly as data intensive.

Step 3: Encoding the jpeg2000 files
Now we use OpenDCP to convert the .tiff image sequence into jpeg2000 images. OpenDCP coverts these from the RGB format that a normal computer uses to one called XYZ which the engineers of digital cinema projectors came up with to make life more complicated than it needs to be:
Notice how I've circled the nice option where you can restart the encoding if the power goes out, and not have to start over from the beginning... this is handy because encoding will take you a while:

Step 4: Encoding jpeg2000 files is finished...
How long of a while, you say? Funny you should ask:

Apparently Jpeg2000 encoding is really slow... must be why nobody ever uses it for anything, ever, except the DCP bunch... meh.. w/e this is something that you just have to put up with and be patient with... having a faster computer than a Core2duo might help... splitting up your frames to multiple computers to convert in parallel might help, but it'd be something that you'd have to babysit... This is one place where OpenDCP could benefit from some network enabled task sharing...

Step 5: Packing up the Jpeg2000 images into an MXF file
The next step is to take all the converted images and pack them into a single file called an MXF file. For 3D films, this stores the left and right streams, alternating the frames, so the projector will effectively project at twice your frame rate, 48 fps for a 24 fps source.

This step kept giving me an error at about 4%: Turns out that when the power went out the *first* time during encoding, it wrote a Jpeg2000 with a bad header. So, when this happens it's always a good idea to check the last few frames that got written before restarting the convert process.

I did a 3D and a 2D version at this point.

Step 6: Converting the Audio stream into a separate MXF file:
OpenDCP can encode stereo or 5.1 channel sound. These have to be 48 khz 24 bit wav files, mono, so one wav for Left, Right, (stereo sound mix) etc... I used an Avisynth script to extract each sound channel, then I used VirtualDub to write the sound file as a wav. The bitrate conversion is handled by the Avisynth script.


Step 7: Creating the DCP file
At this point you're ready to make the final product. The DCP spec has a standardized naming convention which gives the projectionists the most amount of information that you can possibly squeeze onto the tiny el-cheapo LCD character displays which grace these multi-thousand dollar pieces of hardware. Luckily, OpenDCP has a little tool, the Title Generator that handles all this for you, just enter the appropriate data and hit OK


Now it sits there for a while, and then spits out all the files you'll need to get onto a harddrive to take to your film festival:

Now at this point I haven't checked this on an actual DCP server (I used to have one kicking around collecting dust, but I just can't for the life of me remember where I put it... oh well, easy come easy go... oshi~~~ I think I left it in the trunk of my second rolls royce...) So at this point I'm still going to have to see if a normal usb harddrive will suffice to transport this, or if (probably) there's some ridiculous and more expensive hardware requirement... :/

Step 8: Checking the DCP:
Stereoscopic Player will play DCP's.. and more importantly it will play 3D DCP's The trial version only plays back a low res version, and you're limited to 5 minutes of playback at a time. Enough to check and make sure that everything has worked:

The final product... I set up the player to show "Cross Eyed" freeview, the easiest way to check this on a flat monitor... At this point you want to make sure the audio is synced, and the colors are played back correctly. The Jpeg2000 decoder here automatically converts back from XYZ to RGB color space.

So now it's on to the film festivals...
In eye-popping 3D:

11 comments:

Anonymous said...

Hi very useful tutorial i was wandering if this method will work for a polarize lens filter and projector for cinemas and if all theaters can play it this way or by using the side by side squeeze image

thank you

Anonymous said...

Hi very useful tutorial i was wandering if this method will work for a polarize lens filter and projector for cinemas and if all theaters can play it this way or by using the side by side squeeze image

David T. Krupicz said...

For theatrical projection (using a digital cinema server and a 3D projector) you have to encode as a DCP, using the 3D settings. This creates a 48 fps dcp, twice the frame rate as 24 fps, so each eye gets the full resolution frame.

For a home 3D tv or monitor, you want to convert to "L/R side" by side or "over /under" format

Anonymous said...

wow thank you man you are very kind. but in the case that i needed a 2k final output then what? should i render 2 images half the 2k resolution so at the end combined play a 2k or i just render 2 cameras
2k each one and then opendcp will overlap them and create for my a final 2k image or it will put them side by side 2k each one again having a 4k image and then the projector will divide each 2k images and project them separately. like for example the vray stereo helper that give you a 2 images twice the resolution you gave it and side by side is that what open opendcp does? delivers 2 images together side by side or just one combined final .mxf sequence hope make my self clear i am not a native English speaker

David T. Krupicz said...

You want 2 cameras at full 2k resolution (or upscale to 2k like I did...)

Keep the left and right streams in separate folders, then tell opendcp where each folder is, it'll put the images wherever they need to be in the final dcp.

Anonymous said...

well a very simple answers to a very large question hahaha!!! thank any way, i am more clear now very useful blog you got there

Anonymous said...

well sorry to bother you again, but i tried my new and very short test of my dcp in the stereocopic player and run well also i have a dcp that was tested before in a dolby dss 100 my dcp has the exact files, except for the other one, that has a.DS_Store file. thing is mine didn't run it recognize it as a stereo file, but with and error,and still could be loaded but couldn't be played i read that maybe that server has particular problems with drivers since is a old server and also that maybe need a powered usb drive and not a not powered one any clues about this ? thank yo..

David T. Krupicz said...

Side by side won't work for theatrical projection, you need the full 2k or 4k dcp encode which the projector then does it's thing to get it projected properly.

Anonymous said...

Great tutorial, still converting thou! Hopefully everything will go fine :-)

Victoria@Digital Cinema Destinations Corp said...

Wow, surprisingly I never knew this. I have been reading your blog a lot over the past few days and it has earned a place in my bookmarks.Thanks for sharing with us.

TheReviewersClub said...

Hey, man! Thanks for sharing. :)
I seem to have some issues with the quality of the picture when I check it with Stereoscopic Player. Do you have any idea why this might be?

I have a pretty powerful computer at hand, so I think this is not the cause of the problem.
Also, the colors seem quite different on my screen...

Thanks for the tutorial! :)