I'm trying to convert a 4:3 mp4 video into a 16:9 mp4 video with left and right padding. I've created a preset (attached) and no matter what option I select for the Aspect mode, the converted video is still 4:3 even though the codec info in VLC states that it's 16:9. When I look at the command sent to ffmpeg, there are no aspect or padding parameters.

Is this a bug or am I forgetting something?

Any help greatly appreciated.
Thanks

Comments

Jorrit’s picture

It seems that the aspect mode setting isn't passed to FFmpeg so that setting doesn't change the video at all. I will look into a fix, but it seems it will not be easy to add it.

Digitalier’s picture

I could really do with getting this working. Is there anything I can do to help?

Jorrit’s picture

Please try the next 7.x-2.x-dev release.

Jorrit’s picture

The changes are also in the 7.x-2.10 release that I just made.

Digitalier’s picture

StatusFileSize
new158.56 KB
new22.46 KB

Not quite right - I converted a 720x576 (4:3) video to 854x480 (16:9) using a preset with "Pad" for the aspect mode and the resulting video has some left/right padding added to it but not enough and picture seem slightly stretched horizontally - it comes out at 854x525 which is not 16:9.

I've attached copies of my TranscoderAbstractionFactoryFfmpeg.inc and phpvideotoolkit.php5.php which I believe add the padding correctly based on the calculation methods below. The files are from a previous dev version of the module but I hope this helps.

OW = Width of original uploaded video (must be integer)
OH = Height of original uploaded video (must be integer)
SAR = Source Aspect Ratio = OW/OH (floating number)
DW = Width of destination (Preset) Output video (must be integer)
DH = Height of destination (Preset) Output video (must be integer)
DAR = Destination Aspect Ratio = DW/DH (floating number)

STEP 1: Calculate SAR & DAR
SAR = OW / OH
DAR = DW / DH

STEP 2: SAR and DAR are the same
If SAR = DAR (i.e. source and output video have the same aspect ratio)
Then NO –vf parameter is required and using the existing –s parameter generated by the module.

STEP 3: SAR is smaller than DAR
IF SAR < DAR ( i.e. going from SD to HD, therefore left and right pad is required)
Then
First we scale the original video – height is the determining factor
Syntax for scale is WIDTHxHEIGHT and WIDTH and HEIGTH must both be whole integers.
SCALE = round(DH*SAR) .’x’. DH

Then we add padding
Syntax for pad is A:B:C:D where A,B,C and D must all be whole integers.
PAD = DW .’:’. DH .’:’. floor[ (DW-OW) / 2 ] .’:’. floor[ (DH-OH)/2 ]

Construct the –vf parameter:
-vf “scale=SCALE,pad=PAD,setdar=DAR”
Note that setdar accepts a floating point string.

Finally, stop –s parameter from being added
suppress the module from adding the –s paratmeter.

STEP 3: SAR is larger than DAR
IF SAR > DAR ( i.e. going from HD to Cinematic, therefore top and bottom pad is required)
Then

First we scale the original video – width is the determining factor
Syntax for scale is WIDTHxHEIGHT and WIDTH and HEIGTH must both be whole integers.
SCALE = DW .’x’. round(DW / SAR)

Then we add padding
Syntax for pad is A:B:C:D where A,B,C and D must all be whole integers.
PAD = DW .’:’. DH .’:’. floor[ (DW-OW) / 2 ] .’:’. floor[ (DH-OH)/2 ]

Construct the –vf parameter:
-vf “scale=SCALE,pad=PAD,setdar=DAR”
Note that setdar accepts a floating point string.

Finally, stop –s parameter from being added
suppress the module from adding the –s paratmeter.

Digitalier’s picture

StatusFileSize
new29.3 KB

I am still having issues with converting a 720x576 video to 640x360 (16:9) format using the "Pad" aspect mode. I compared the output with videos converted using Adobe Media Encoder and it seems some stretching is creeping in.

Here's my modified code for TranscoderAbstractionFactoryFfmpeg.inc - It solves the the issue going from SD to Widescreen but haven't had a chance to test the other way around. Also fixed the order of the filters so the video is scaled and then padded and also added parameter to set DAR.

Digitalier’s picture

StatusFileSize
new3.11 KB

There was a slight issue with -ve padding when Source Aspect Ratio was greater than Target Aspect Ratio. Here's the patch to fix the stretching issue and set the correct DAR when using the "Pad" aspect mode setting. Would be good to get feedback.

Digitalier’s picture

Just to confirm the issue:
When I convert a 720x576 video to 640x360 (16:9) widescreen video using the "Pad" aspectmode setting:
vf part of the command line generated by the stock dev version is:
-vf 'pad=810:576:45:0,scale=640:360'

First off, it is trying to pad the video to 16:9 and then scale it to the required 640x360 dimensions, but it should be the other way around - scale it (keeping source aspect ratio) and then pad it to required target aspect ratio.

Next, the calculated padding of (810:576:45:0) is not correct (not 16:9)

So the patch fixes two things:
1. Correct order of scale and then pad
2. Correct calculation of padding
3. Setting the DAR (aspect ratio) to keep things clean

Jorrit’s picture

Thanks for the patch and my apologies that I did not respond earlier.
You have many lines of commented code in your patch. Can you clean that up?

Jorrit’s picture

Status: Active » Needs work
Digitalier’s picture

StatusFileSize
new2.24 KB

Yep. Patch for "7.x-2.10+6-dev" version attached.

Digitalier’s picture

Status: Needs work » Needs review
StatusFileSize
new2.24 KB

Forgot to update Issue status. Patch for "7.x-2.10+6-dev" version attached.
Let me know if it works for you.

hypertext200’s picture

Component: Video Transcoding » General
Issue summary: View changes
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.