- id->p_encoder->fmt_out.video.i_width =
- id->p_encoder->fmt_out.video.i_height / (double)i_height * i_width;
- }
-
- if( p_sys->i_maxwidth
- && id->p_encoder->fmt_out.video.i_width > p_sys->i_maxwidth )
- id->p_encoder->fmt_out.video.i_width = p_sys->i_maxwidth;
- if( p_sys->i_maxheight
- && id->p_encoder->fmt_out.video.i_height > p_sys->i_maxheight )
- id->p_encoder->fmt_out.video.i_height = p_sys->i_maxheight;
-
- /* Make sure the size is at least a multiple of 2 */
- id->p_encoder->fmt_out.video.i_width =
- (id->p_encoder->fmt_out.video.i_width + 1) >> 1 << 1;
- id->p_encoder->fmt_out.video.i_height =
- (id->p_encoder->fmt_out.video.i_height + 1) >> 1 << 1;
-
- id->p_encoder->fmt_in.video.i_width =
- id->p_encoder->fmt_out.video.i_width;
- id->p_encoder->fmt_in.video.i_height =
- id->p_encoder->fmt_out.video.i_height;
-
+ /* Only height specified */
+ f_scale_height = (float)id->p_encoder->fmt_out.video.i_height/i_src_height;
+ f_scale_width = f_scale_height;
+ }
+ else if( id->p_encoder->fmt_out.video.i_width > 0 &&
+ id->p_encoder->fmt_out.video.i_height > 0 )
+ {
+ /* Width and height specified */
+ f_scale_width = (float)id->p_encoder->fmt_out.video.i_width/i_src_width;
+ f_scale_height = (float)id->p_encoder->fmt_out.video.i_height/i_src_height;
+ }
+
+ /* check maxwidth and maxheight
+ */
+ if( p_sys->i_maxwidth && f_scale_width > (float)p_sys->i_maxwidth /
+ i_src_width )
+ {
+ f_scale_width = (float)p_sys->i_maxwidth / i_src_width;
+ }
+
+ if( p_sys->i_maxheight && f_scale_height > (float)p_sys->i_maxheight /
+ i_src_height )
+ {
+ f_scale_height = (float)p_sys->i_maxheight / i_src_height;
+ }
+
+
+ /* Change aspect ratio from source pixel to scaled pixel */
+ f_aspect = f_aspect * f_scale_height / f_scale_width;
+ msg_Dbg( p_stream, "scaled pixel aspect is %f:1", f_aspect );
+
+ /* f_scale_width and f_scale_height are now final */
+ /* Calculate width, height from scaling
+ * Make sure its multiple of 2
+ */
+ i_dst_width = 2 * (int)(f_scale_width*i_src_width/2+0.5);
+ i_dst_height = 2 * (int)(f_scale_height*i_src_height/2+0.5);
+
+ /* Change aspect ratio from scaled pixel to output frame */
+ f_aspect = f_aspect * i_dst_width / i_dst_height;
+
+ /* Store calculated values */
+ id->p_encoder->fmt_out.video.i_width =
+ id->p_encoder->fmt_out.video.i_visible_width = i_dst_width;
+ id->p_encoder->fmt_out.video.i_height =
+ id->p_encoder->fmt_out.video.i_visible_height = i_dst_height;
+
+ id->p_encoder->fmt_in.video.i_width =
+ id->p_encoder->fmt_in.video.i_visible_width = i_dst_width;
+ id->p_encoder->fmt_in.video.i_height =
+ id->p_encoder->fmt_in.video.i_visible_height = i_dst_height;
+
+ msg_Dbg( p_stream, "source %ix%i, destination %ix%i",
+ i_src_width, i_src_height,
+ i_dst_width, i_dst_height
+ );
+
+ /* Handle frame rate conversion */