Let you specified the result video size as 320×0 – to make the width to be calculated based on the source aspect ratio. Then let you need to know what the exact frame size of result is.
First, you can find out the source media aspect ratio. Just send GetMediaInfo API request, and locate <display_aspect_ratio> property. If it is not present, just calculate the ratio from the frame size (<size> property) dividing width by height.
Let's now calculate result frame height. Divide the result width by the obtained ratio, round it to nearest integer, and then, if it is not even, add 1.
For example if source ratio is 1.333 (4:3).
320/1.333 = 240.06
So, the height will be 240.
For the source ratio 1.777 (16:9):
320/1.777 = 180.07
So, the height will be 180.