Bug 481727

Summary: Recording a rectangular region with libx264 fails 75% of the time with "not divisible by 2" error
Product: [Frameworks and Libraries] KPipeWire Reporter: Adam Fontenot <adam.m.fontenot+kde>
Component: generalAssignee: Plasma Bugs List <plasma-bugs-null>
Status: CONFIRMED ---    
Severity: normal CC: aleixpol, kde, luis.buechi, nate, ncnmyxel, noahadvs
Priority: NOR Keywords: qt6
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Adam Fontenot 2024-02-23 15:17:10 UTC
SUMMARY

At first, as originally reported in Bug 481390, I thought H.264 recording always fails. Turns out, I was just unlucky and it failed the first half dozen times I tested it.

I didn't realize debugging information was provided when you run Spectacle in the terminal, but I did so and immediately found the issue:

[libx264 @ 0x75f4302e9400] width not divisible by 2 (573x365)
kpipewire_record_logging: Could not open codec Generic error in an external library
kpipewire_record_logging: No encoder could be created

STEPS TO REPRODUCE
1. Select a rectangular region of the screen for recording, with H.264 selected as your codec. Make sure that one or both of the dimensions is not divisible by two (e.g. 573x365 in my example).
2. Try to start recording video.

OBSERVED RESULT

Nothing is ever recorded or output, Spectacle minimizes itself to the taskbar (red recording icon), but clicking on this icon does nothing. Spectacle has to be killed from the task manager or terminal.

EXPECTED RESULT

Spectacle should prevent selecting unacceptable rectangular regions for the current video codec.

**Moreover**, Spectacle should respond to errors from Pipewire in a way that is (a) visible to the user, and (b) does not make Spectacle unusable until it is killed and restarted.

My guess is that this sort-of affects VP9 as well, in that this is why the recording is usually one pixel *wider* than expected and includes the dashed rectangular outline that shows the recording region. This is in part what I reported in Bug 481391, although there are other issues here too.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 5.93.0
KDE Frameworks Version: 5.249.0
Qt Version: 6.7.0
Kernel Version: 6.7.4-arch1-1 (64-bit)
Graphics Platform: Wayland
Comment 1 Noah Davis 2024-02-24 06:48:38 UTC
I can reproduce this. Since my GPU supports H.264 encoding, I have to run `KPIPEWIRE_FORCE_ENCODER=libx264 spectacle` to test this.
Comment 2 Noah Davis 2024-02-24 06:50:01 UTC
Moved the report to KPipeWire since that's what actually uses the libx264 encoder.
Comment 3 ncnmyxel 2024-07-13 14:20:17 UTC
I've recently started running into this issue. I originally thought it was related to bug 485733 because of the error I'm getting, but seems like that one is concerned with VP9, not H.264. I do not experience this error with VP9, although it's otherwise not usable for me due to bug 488896.

To add to the report, it seems like it also depends on the position of the capture area: the same rectangle might fail in one place and succeed in the other. I've both triggered the error with an [even * even] rectangle and avoided it with [odd * odd]. Whether the capture succeeds or fails in a given position appears to be consistent. Tested on a 1080p display at 100% scaling.

Operating System: EndeavourOS 
KDE Plasma Version: 6.1.2
KDE Frameworks Version: 6.3.0
Qt Version: 6.7.2
Kernel Version: 6.9.8-arch1-1 (64-bit)
Graphics Platform: Wayland