AWS Thinkbox Discussion Forums

Codec / videoEncoder for Draft?

Hi Drafters

Wondering if there’s any documentation in one place for using different codecs with Draft? I’ve seen references around the forum about h264, DNxHD, MJPEG, and the possibility of ProRes. I’m guessing there are intricate and obscure gamma and color issues with each one. Civilian friendly (ie. not a programmer) explanation of the videoEncoder function would also be super useful. Any way we could compile all of this information in one place?

Here’s to it

Bill

Regarding color and gamma: I understand Jon got gamma working consistently in Quicktime. Beyond that I don’t think we’ve put much work into it. Please let us know if you run into any issues, or if you have any feature requests.

We’re working on improving our documentation now. This seems like a good place to figure out what we need for VideoEncoder.

The VideoEncoder class should be documented here, but it is currently incomplete and a bit out of date.

Class: Draft.VideoEncoder

Constructors

There are two functions for creating a VideoEncoder:

[b]Draft.VideoEncoder/b
Return a new VideoEncoder that will save a video to the specified filename. Default values are used for the frame rate, frame size, etc.
Arguments:
[list]filename – the filename where the video should be saved.[/list:u]

Draft.VideoEncoder( filename, fps, width, height, kbitRate, codec )
Return a new VideoEncoder that will save a video to the specified filename.
Arguments:
[list]filename – the filename where the video should be saved.
fps – the video frame rate, in frames per second. This can be:
[list]* An integer such as 24,
[]a float such as 29.97, or
[
]a fraction. To specify a fraction, you can use the Rational class:from fractions import Fraction fps = Fraction(30000, 1001)

width – the video frame width. This must be an integer. To convert a floating-point number to an integer, you can use the int() function, for example: int(800.0). If you encode an image with a different size, it will be automatically resized to match this width.
height – the video frame height. This must be an integer. If you encode an image with a different size, it will be automatically resized to match this height.
kbitRate – the target bit rate for the encoded video. Measured in kilobits per second.
codec – the video encoder to use. This is must be a string. Valid options are: ‘MPEG4’, ‘MJPEG’, ‘DNXHD’, ‘H264’, ‘PRORES’, ‘RAWVIDEO’[/:m][/list:u][/:m][/list:u]

I think the one weird parameter here is the kbitRate. I think it should be optional, and Draft should choose a sensible default based on the fps, width, height, and codec. I think it will require some trial and error, and I don’t have any suggestions for now. However I would suggest that you base your tests on an equation such as:bitsPerPixel = 0.2 # try changing this kbitRate = int(fps * width * height * bitsPerPixel / 1000.0) # leave this fixedand change only the bitsPerPixel.

Methods

[b]EncodeNextFrame[/b]
[i]Description[/i]: Encodes a given draft image as the next frame in the video.
[i]Arguments[/i]:
	[list]Image -- The image to encode into the next frame of the video
[i]Usage[/i]:

defaultEncoder = Draft.VideoEncoder( "//path/to/video/save.mov" ) defaultEncoder.EncodeNextFrame( Draft.Image.CreateImage( 800, 600 ) )

[b]FinalizeEncoding[/b]
[i]Description[/i]: Finalizes the encoding process, completing the video.
[i]Arguments[/i]: (none)
[i]Usage[/i]:

encoder = Draft.VideoEncoder( "//path/to/video.mov", 29, 800, 600, 5120, "MJPEG" ) #encode some frames here... encoder.FinalizeEncoding()
[/list:u]

Is there anything in particular you’re wondering about, or anything we should explain better?

Do each of the codecs need different inputs? When I changed ‘codec’ from “MJPEG” for “PRORES,” the script worked, but when I subbed out “DNXHD”, it broke.

0: STDOUT: [dnxhd @ 0x10900cc00] video parameters incompatible with DNxHD
0: STDOUT: Traceback (most recent call last):
0: STDOUT: File “/Local/Farm13/jobsData/1K_1_movieProxyDNXHD.py”, line 187, in
0: STDOUT: videoEncoder = VideoEncoder( movPattern, fps, 1024, 778, kBitRate, codec )
0: STDOUT: RuntimeError: could not open codec
0: INFO: Process exit code: 1

Gamma and color are looking good though!

I’m guessing the kbitRate is too high.

There was an error in the kbitRate equation in my post – I had a “1000 *”, but it should be “/ 1000.0” instead. In other words the resulting kbitRate was way too high. I have fixed it in my original post.

here’s the line I’m using to calculate kBitRate:

kBitRate = int(proxyWidthproxyHeightfps*3/1000)

Seems reasonable, yeah?

So just confirming, every codec takes the same 6 input variables?

Yes, currently every codec takes the same 6 input variables.

Yes, I’d use something like that, but I’m not sure about the value of bitsPerPixel (3 in your example). An appropriate value for bitsPerPixel will depend on the codec.

Just thought I’d jump in here since I noticed you mentioned DNXHD. The DNXHD codec actually requires very specific combinations of bitrate, resolution, and framerate for it to work. Here’s a table of them, taken from one of my previous posts (which was in turn borrowed from the interwebs):

Project Format Resolution Frame Size Bits FPS <bitrate> 1080i / 59.94 DNxHD 220 1920 x 1080 8 29.97 220Mb 1080i / 59.94 DNxHD 145 1920 x 1080 8 29.97 145Mb 1080i / 50 DNxHD 185 1920 x 1080 8 25 185Mb 1080i / 50 DNxHD 120 1920 x 1080 8 25 120Mb 1080p / 25 DNxHD 185 1920 x 1080 8 25 185Mb 1080p / 25 DNxHD 120 1920 x 1080 8 25 120Mb 1080p / 25 DNxHD 36 1920 x 1080 8 25 36Mb 1080p / 24 DNxHD 175 1920 x 1080 8 24 175Mb 1080p / 24 DNxHD 115 1920 x 1080 8 24 115Mb 1080p / 24 DNxHD 36 1920 x 1080 8 24 36Mb 1080p / 23.976 DNxHD 175 1920 x 1080 8 23.976 175Mb 1080p / 23.976 DNxHD 115 1920 x 1080 8 23.976 115Mb 1080p / 23.976 DNxHD 36 1920 x 1080 8 23.976 36Mb 1080p / 29.7 DNxHD 45 1920 x 1080 8 29.97 45Mb 720p / 59.94 DNxHD 220 1280 x 720 8 59.94 220Mb 720p / 59.94 DNxHD 145 1280 x 720 8 59.94 145Mb 720p / 50 DNxHD 175 1280 x 720 8 50 175Mb 720p / 50 DNxHD 115 1280 x 720 8 50 115Mb 720p / 23.976 DNxHD 90 1280 x 720 8 23.976 90Mb 720p / 23.976 DNxHD 60 1280 x 720 8 23.976 60Mb
Keep in mind that the bitrates listed here are in Mb/s (=1,000 kb/s), so you’ll have to multiply these values by 1,000 when passing them to Draft.

So, for example, for 1080p DNxHD 185 the encoder would look like this:

Draft.VideoEncoder( filename, 25, 1920, 1080, 185000, "DNXHD" )

Hope this helps,

  • Jon

Hi Jon

Thanks for reposting this… and your patience. Now I know why DNxHD has the settings it does… I always wondered what 175 vs 115 meant!

Yours

Bill

I’m looking at the ffmpeg documentation and it seems to suggest you need an extra flag for interlaced. Is that true/exposed? Or does it automagically figure it out?

I don’t think we expose any way to encode interlaced video. Shall I add this to our wish list?

Privacy | Site terms | Cookie preferences