carrierwave-video
carrierwave-video copied to clipboard
Aspect ratio distorted with newer Samsung Galaxy videos
After upgrading a Samsung Galaxy phone, all my newer videos made in portrait mode have the wrong aspect ratio after transcoding (any target format), e.g.:
I have a fix that works for my videos now:
- I've forked the Gem and removed the default resolution (640x360) and preserve_aspect_ratio attributes (:width), as those interfer with the solution
- I've replaced the resizing with a decrease as written in the ffmpeg docs in the last paragraph here (https://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20with%20ffmpeg)
- When transcoding a video, I've moved the resolution parameters together with the solution in the custom block, as otherwise streamio-ffmpeg will add a nasty aspect-param that distorts the image again
# old video->jpg
# process encode_video: [:jpg, resolution: '500x500', preserve_aspect_ratio: :width]
process encode_video: [:jpg, custom: '-vf scale=w=500:h=500:force_original_aspect_ratio=decrease']
# old video->mp4
# process encode_video: [:mp4, resolution: '640x360', preserve_aspect_ratio: :width, audio_codec: 'aac']
process encode_video: [:mp4, custom: '-s 640x360 -vf scale=w=640:h=360:force_original_aspect_ratio=decrease', audio_codec: 'aac']
I am aware, that Carrierwave Video can't do to much but just change the default resolution/preserve_aspect_ratio params to allow override. There seem to be a problem in combination with the streamio-ffmpeg Gem. Just leaving this here to help other people with the same problem!
Difference between Samsung's meta data:
I've compared a "new" and a "old" video. Most params are similar, but one stood out.It seems, that the old format didn't specify the aspect ratio, but the new one specify it:
// NEW format (output from ffprobe)
{
///...
"sample_aspect_ratio": "1:1",
"display_aspect_ratio": "16:9",
}
// OLD format (output from ffprobe)
{
///...
"sample_aspect_ratio": "0:1",
"display_aspect_ratio": "0:1",
}