[BUG] Portrait video previews are upscaled instead of downscaled #346

Closed
opened 2026-02-04 19:55:19 +03:00 by OVERLORD · 1 comment
Owner

Originally created by @raisinbear on GitHub (Oct 8, 2022).

Hi,

wanted to report another minor inconsistency I stumbled upon with the transcoded videos.

Describe the bug
I'll try and describe both the bug and a possible solution. Wanted to try change this myself but am afraid am not knowledgable enough to do so.
/server/apps/microservices/src/processors)/video-transcode.processor.ts passes -vf scale=1280:-2 to ffmpeg, which in case of landscape videos correctly resizes the largest dimension to 1280 px. In case of (full hd) portrait, you rather end up with an upscaled version, since the smaller 1080 px dimension is set to 1280 px while keeping the aspect ratio. For my test videos, this usually yielded files of roughly the same size as the input (i.e. ~12 MB original to ~11 MB transcoded).
A quick search brought up that ffmpeg can handle the logic to resize the maximum dimension to 1280 px when passing -vf 'scale=if(gte(iw\,ih)\,min(1280\,iw)\,-2):if(lt(iw\,ih)\,min(1280\,ih)\,-2)'. This worked with the cli version. I couldn't test with the fluent-ffmpeg package. I verified that the so generated mp4 file doesn't cause any issues with in neither web interface nor iOS app, just boldly replacing the immich-transcoded file with my cli-transcoded file.

Task List

Please complete the task list below. We need this information to help us reproduce the bug or point out problems in your setup. You are not providing enough info may delay our effort to help you.

  • [ x ] I have read thoroughly the README setup and installation instructions.
  • [ x ] I have included my docker-compose file.
  • [ x ] I have included my redacted .env file.
  • [ x ] I have included information on my machine, and environment.

docker-compose.yml.txt
env.txt

To Reproduce
Steps to reproduce the behavior:

  1. Upload 1080px * 1920px portrait video via web, cli or app
  2. Check dimensions of transcoded video file in [data]/[library-id]/encoded-video
  3. Observe dimensions of transcoded video are 1280px * 2276px, thus upscaled from original

Expected behavior
Portrait videos should also be downscaled to preview-friendly dimensions

Screenshots

System

  • Phone OS [iOS, Android]: iOS 16.0.2
  • Server OS: raspbian buster
  • Server Version: 1.31.0
  • Mobile App Version: 1.31.0 build.64

Additional context

Originally created by @raisinbear on GitHub (Oct 8, 2022). Hi, wanted to report another minor inconsistency I stumbled upon with the transcoded videos. **Describe the bug** I'll try and describe both the bug and a possible solution. Wanted to try change this myself but am afraid am not knowledgable enough to do so. `/server/apps/microservices/src/processors)/video-transcode.processor.ts` passes `-vf scale=1280:-2` to ffmpeg, which in case of landscape videos correctly resizes the largest dimension to 1280 px. In case of (full hd) portrait, you rather end up with an upscaled version, since the smaller 1080 px dimension is set to 1280 px while keeping the aspect ratio. For my test videos, this usually yielded files of roughly the same size as the input (i.e. ~12 MB original to ~11 MB transcoded). A quick search brought up that ffmpeg can handle the logic to resize the maximum dimension to 1280 px when passing `-vf 'scale=if(gte(iw\,ih)\,min(1280\,iw)\,-2):if(lt(iw\,ih)\,min(1280\,ih)\,-2)'`. This worked with the cli version. I couldn't test with the `fluent-ffmpeg` package. I verified that the so generated mp4 file doesn't cause any issues with in neither web interface nor iOS app, just boldly replacing the immich-transcoded file with my cli-transcoded file. **Task List** *Please complete the task list below. We need this information to help us reproduce the bug or point out problems in your setup. You are not providing enough info may delay our effort to help you.* - [ x ] I have read thoroughly the README setup and installation instructions. - [ x ] I have included my `docker-compose` file. - [ x ] I have included my redacted `.env` file. - [ x ] I have included information on my machine, and environment. [docker-compose.yml.txt](https://github.com/immich-app/immich/files/9738846/docker-compose.yml.txt) [env.txt](https://github.com/immich-app/immich/files/9738847/env.txt) **To Reproduce** Steps to reproduce the behavior: 1. Upload 1080px * 1920px portrait video via web, cli or app 2. Check dimensions of transcoded video file in `[data]/[library-id]/encoded-video` 3. Observe dimensions of transcoded video are 1280px * 2276px, thus upscaled from original **Expected behavior** Portrait videos should also be downscaled to preview-friendly dimensions **Screenshots** - **System** - Phone OS [iOS, Android]: `iOS 16.0.2` - Server OS: raspbian buster - Server Version: `1.31.0` - Mobile App Version: `1.31.0 build.64` **Additional context** -
Author
Owner

@raisinbear commented on GitHub (Nov 22, 2022):

I just noticed there is now a settings panel where you can set video transcode properties. This doesn't directly address the issue but it's now possible to easily adjust the relevant parameter. For anyone caring, I use [vf scale=]1280:1280:force_original_aspect_ratio=decrease for now. Be aware this may be problematic since it doesn't force any modulo constraint on the video dimensions, which - as far as I read - may not be supported by video players. I haven't found another solution that works, however, and have not encountered any issues yet.

@raisinbear commented on GitHub (Nov 22, 2022): I just noticed there is now a settings panel where you can set video transcode properties. This doesn't directly address the issue but it's now possible to easily adjust the relevant parameter. For anyone caring, I use `[vf scale=]1280:1280:force_original_aspect_ratio=decrease` for now. Be aware this may be problematic since it doesn't force any modulo constraint on the video dimensions, which - as far as I read - may not be supported by video players. I haven't found another solution that works, however, and have not encountered any issues yet.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#346