0

Hi everyone i'm trying to resize width and height of certain input with fluent ffmpeg to 768x1366 (basically to show it in vertical mode), so i have to also change its display_aspect_ratio which i happen to know is 0.562225476. The issue here is that, according to fluent-ffmpeg doc, if i set a fix size, it wont change the aspect ratio, but it wont work either if I use ? to automatic mode. This is my code:

ffmpeg({source: req.file.path}) 
            .withFps(30)
            .toFormat('mp4')
            .size("768x?")
            .aspect(0.562225476)

Console command: ffmpeg -i tmp/video.mp4 -y -r 30 -filter:v scale=w=768:h=1366 -f mp4 ./src/internal/media/video.mp4

So when i check the display_aspect_ratio with ffprobe it's still 4:3 (as source file).

If I do not add the .aspect() option, the command is exactly the same...so it's not considering it.

I've also tried:

ffmpeg({source: req.file.path}) 
            .withFps(30)
            .toFormat('mp4')
            .size('768x1366')
            .addOptions('-vf setdar=0.562225476')

And command here ends up being ffmpeg -i tmp/video.mp4 -y -r 30 -filter:v scale=w=768:h=1366 -f mp4 -vf setdar=0.562225476 ./src/internal/media/video.mp4, so it seemed ok, but when I check with ffprobe it did not apply width and height changes.

The command I really need is some kind of : ffmpeg -i video.mp4 -vf scale=768:1766,"setdar=0.562225476" video2.mp4 which changes both, widthXheight and display_aspect_ratio

danronmoon
  • 3,814
  • 5
  • 34
  • 56
juanmac
  • 121
  • 1
  • 12

1 Answers1

1

Indeed, your last call is exactly what you need to do (except you don't need the double quotes around setdar).

[edit] Can't you just do this?

ffmpeg({source: req.file.path}) 
            .withFps(30)
            .toFormat('mp4')
            .addOptions('-vf scale=768:1766,setdar=0.562225476')

[/edit]

I don't know how to do that with fluent-ffmpeg, but once upon a time, I submitted kiss-ffmpeg to NPM to translate console ffmpeg command easier to JavaScript. It's no longer maintained (as I moved to Python since) but I see people are still downloading so should be still usable.

With kiss-ffmpeg, you can specify your vf option by

ffmpeg.outputs = [
  { url: "video2.mp4", options: { "vf": "scale=768:1766,setdar=0.562225476" } }
];

See the NPM readme for how to set up the rest of the call.

kesh
  • 4,515
  • 2
  • 12
  • 20
  • Thank's man, but i can not risk my app with package it's no longer maintained. – juanmac Feb 27 '22 at 18:14
  • 1
    Understand. Actually, now I looked at your code closely (should've done first) you may have an easy fix. See the edit to my answer. – kesh Feb 27 '22 at 18:29
  • Yes, you were right. I also didn't realize about that workaround. Either way, i will still keep the thread opened without solution in order to understand the library im using. Tanks a lot! – juanmac Feb 28 '22 at 15:01