https://bugs.kde.org/show_bug.cgi?id=485502

            Bug ID: 485502
           Summary: Recorder incorrectly resizes stages with different
                    aspect ratios
    Classification: Applications
           Product: krita
           Version: nightly build (please specify the git hash!)
          Platform: Kubuntu
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: Dockers/Recorder
          Assignee: krita-bugs-n...@kde.org
          Reporter: i...@ralek.art
  Target Milestone: ---

Created attachment 168470
  --> https://bugs.kde.org/attachment.cgi?id=168470&action=edit
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.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to