+ /* The film AR is the source's display width / cropped source height.
+ The output display width is the output height * film AR.
+ The output PAR is the output display width / output storage width. */
+ pixel_aspect_width = height * source_display_width / cropped_height;
+ pixel_aspect_height = width;
+
+ /* While x264 is smart enough to reduce fractions on its own, libavcodec
+ needs some help with the math, so lose superfluous factors. */
+ hb_reduce( &pixel_aspect_width, &pixel_aspect_height,
+ pixel_aspect_width, pixel_aspect_height );
+
+ /* Pass the results back to the caller */
+ *output_width = width;
+ *output_height = height;
+ *output_par_width = pixel_aspect_width;
+ *output_par_height = pixel_aspect_height;
+}
+
+/**
+ * Calculates job width, height, and cropping parameters.
+ * @param job Handle to hb_job_t.
+ * @param aspect Desired aspect ratio. Value of -1 uses title aspect.
+ * @param pixels Maximum desired pixel count.
+ */
+void hb_set_size( hb_job_t * job, int aspect, int pixels )
+{
+ hb_title_t * title = job->title;
+
+ int croppedWidth = title->width - title->crop[2] - title->crop[3];
+ int croppedHeight = title->height - title->crop[0] - title->crop[1];
+ int croppedAspect = title->aspect * title->height * croppedWidth /
+ croppedHeight / title->width;
+ int addCrop;