Bug 485502 - Recorder incorrectly resizes stages with different aspect ratios
Summary: Recorder incorrectly resizes stages with different aspect ratios
Status: RESOLVED DUPLICATE of bug 429326
Alias: None
Product: krita
Classification: Applications
Component: Dockers/Recorder (show other bugs)
Version: nightly build (please specify the git hash!)
Platform: Kubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-04-13 19:17 UTC by Ralek Kolemios
Modified: 2024-04-15 13:32 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Showing how canvas aspect ratio squishes the image when exported. (123.07 KB, video/webm)
2024-04-13 19:17 UTC, Ralek Kolemios
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ralek Kolemios 2024-04-13 19:17:22 UTC
Created attachment 168470 [details]
Showing how canvas aspect ratio squishes the image when exported.

When exporting timelapses, Krita squishes and stretches my timelapse to fit the final resolution (Which is not always the resolution or ratio I start with). This causes weird distortion in exported timelapses with a final resolution aspect ratio different than the starting canvas aspect ratio. See attached.
To fix this, some extra arguments in the complex filter are necessary.

This is an example complex filter Krita currently uses: 
```

-filter_complex "
 [0]loop=$LAST_FRAME_SEC*$IN_FPS:size=1:start=$FRAMES[main1];
 [main1]scale=$WIDTH:$HEIGHT[main2];
 [main2]loop=1:size=1:start=0[main3];
 [main3]setpts=PTS-STARTPTS[main4];
 [1]split [first1][transition1];
 [transition1]scale=$WIDTH:$HEIGHT [transition2];
 [transition2]loop='if(gte($FIRST_FRAME_SEC, 1), 1*$IN_FPS, 0)':size=1:start=1[transition3];
 [transition3]setpts=PTS-STARTPTS[transition4];
 [transition4][main4]xfade=transition=smoothright:duration=0.5:offset=0[v1];
 [v1]setpts=PTS-STARTPTS[v2];
 [v2]trim=start_frame=1[v3];
 [first1]loop='if(gte($FIRST_FRAME_SEC, 1), ($FIRST_FRAME_SEC*$IN_FPS) - 0.5*$IN_FPS, $FIRST_FRAME_SEC*$IN_FPS)':size=1:start=1[preview1];
 [preview1]scale=$WIDTH:$HEIGHT[preview2];
 [preview2]setpts=PTS-STARTPTS[preview3];
 [preview3][v3] concat [final1];
 [final1] setpts=PTS-STARTPTS[final2];
 [final2] trim=start_frame=1
"
```

This is my modified complex filter that maintains aspect ratio:

```
-filter_complex "
 [0]loop=$LAST_FRAME_SEC*$IN_FPS:size=1:start=$FRAMES[main1];
 [main1]scale=$WIDTH:$HEIGHT:force_original_aspect_ratio=decrease,pad=$WIDTH:$HEIGHT:(ow-iw)/2:(oh-ih)/2[main2];
 [main2]loop=1:size=1:start=0[main3];
 [main3]setpts=PTS-STARTPTS[main4];
 [1]split [first1][transition1];
 [transition1]scale=$WIDTH:$HEIGHT:force_original_aspect_ratio=decrease,pad=$WIDTH:$HEIGHT:(ow-iw)/2:(oh-ih)/2[transition2];
 [transition2]loop='if(gte($FIRST_FRAME_SEC, 1), 1*$IN_FPS, 0)':size=1:start=1[transition3];
 [transition3]setpts=PTS-STARTPTS[transition4];
 [transition4][main4]xfade=transition=smoothright:duration=0.5:offset=0[v1];
 [v1]setpts=PTS-STARTPTS[v2];
 [v2]trim=start_frame=1[v3];
 [first1]loop='if(gte($FIRST_FRAME_SEC, 1), ($FIRST_FRAME_SEC*$IN_FPS) - 0.5*$IN_FPS, $FIRST_FRAME_SEC*$IN_FPS)':size=1:start=1[preview1];
 [preview1]scale=$WIDTH:$HEIGHT:force_original_aspect_ratio=decrease,pad=$WIDTH:$HEIGHT:(ow-iw)/2:(oh-ih)/2[preview2];
 [preview2]setpts=PTS-STARTPTS[preview3];
 [preview3][v3] concat [final1];
 [final1] setpts=PTS-STARTPTS[final2];
 [final2] trim=start_frame=1
"
```

This fixes the issue by ensuring each step of the filter is scaled down to fit in the final resolution, using `force_original_aspect_ratio=decrease` after each stage to maintain aspect ratio.
On top of that, to prevent errors from transition stages having different resolutions, I then pad the output with black pixels. This creates letterboxing sometimes, but I believe nearly every artist would prefer black lines occasionally over a completely squashed and stretched timelapse. 

If the letterbox could be a blurred and scaled version of the image itself instead of black boxes that could be cool, but I don't know how feasible that is with ffmpeg and the amount of processing it'd take.

I believe all that's needed to fix this would be changing all scale filters to have the extra force ratio/pad
scale=$WIDTH:$HEIGHT
To
scale=$WIDTH:$HEIGHT:force_original_aspect_ratio=decrease,pad=$WIDTH:$HEIGHT:(ow-iw)/2:(oh-ih)/2

But I wouldn't know the specifics of how Krita does this, I'm just an artist. This is the fix I apply to every timelapse to fix the weird distortion that happens so I figured I'd report the bug.
Comment 1 Freya Lupen 2024-04-15 13:32:53 UTC

*** This bug has been marked as a duplicate of bug 429326 ***