Change the Encoding of a Movie Clip

Problem

You want to change the encoding of a movie clip.

Solution

Use the VideoDecoder to decode your existing clip and then use the VideoEncoder to encode that clip into a different codec. For example, the following code converts an input QuickTime to h.264.

image = Draft.Image.CreateImage( 1, 1 )

decoder = Draft.VideoDecoder( "//path/to/existing/clip.mov" )

hasFrames = decoder.DecodeNextFrame( image )
if hasFrames:
    encoder = Draft.VideoEncoder( "//path/to/video/save.mov", codec='H264' )

    while hasFrames:
        encoder.EncodeNextFrame( image )
        hasFrames = decoder.DecodeNextFrame( image )

    encoder.FinalizeEncoding()

Discussion

Taking a movie clip and encoding it with a new codec is just a matter of decoding the existing clip and encoding it into a new clip. An important thing to remember is that the paths for the decoder and the encoder must be different. You can’t decode and encode the same file at the same time.

Draft will detect which decoder to use automatically so you do not need to specify when you are decoding.

Draft supports multiple codec options. They include:

  • MPEG4 (default)
  • MJPEG
  • DNxHD® (requires a “Draft Codec Pack” license)
  • H264
  • RAWVIDEO

It’s important to remember that when you’re encoding with Avid DNxHD® you must use a specific set of parameters. Here is a table of all the Avid DNxHD® settings that work with this version of Draft.

width height fps kbitRate
1920 1080 29.97 220000
1920 1080 29.97 145000
1920 1080 29.97 45000
1920 1080 25 185000 *
1920 1080 25 120000 *
1920 1080 25 36000 *
1920 1080 24 175000 *
1920 1080 24 115000 *
1920 1080 24 36000 *
1920 1080 23.976 175000
1920 1080 23.976 115000
1920 1080 23.976 36000
1280 720 59.94 220000
1280 720 59.94 145000
1280 720 50 180000
1280 720 50 120000
1280 720 29.97 110000
1280 720 29.97 75000
1280 720 25 90000
1280 720 25 60000
1280 720 23.976 90000
1280 720 23.976 60000

* Draft supports writing MXF files for these combinations only