Search code examples
androidffmpegandroid-ffmpeg

ffmpeg reverse video resolution after compression


I'm trying to compress a video to mp4 format with ffmpeg.

With scale filter:

cmd = "-i, "+in+" -vf scale=480:-2,setsar=1:1, "+out;

Or as simple as this:

cmd = "-i, "+in+" "+out;

If I try this command, the outPut will be fine in many players like potPlayer(win) or mxPlayer(android), But in some players like kmPlayer.v3(win) it's stretched. with or without scale filter.

I tried the same video compression with Handbrake so I find out there is nothing wrong with my player.

The result is the same with all videos that I compressed with ffmpeg library

And there is another problem which is more annoying, the outPut video resolution gets reversed. for Example:

Input : w1280 h720

Output : w720 h1280

I googled a lot but I found nothing.


Solution

  • When you record video in portrait mode on, it may have rotation metadata set, and ffmpeg cannot use it correctly with scale filter.

    You can add -noautorotate option to ffmpeg command line, or maybe there is a way to correct the metadata.