[FFmpeg-trac] #10447(ffmpeg:new): On macOS ffmpeg should create a power assertion to prevent system sleep while job runs
FFmpeg
trac at avcodec.org
Wed Jul 5 19:27:36 EEST 2023
#10447: On macOS ffmpeg should create a power assertion to prevent system sleep
while job runs
--------------------------------+---------------------------------------
Reporter: porg | Type: enhancement
Status: new | Priority: normal
Component: ffmpeg | Version: unspecified
Keywords: | Blocked By:
Blocking: | Reproduced by developer: 0
Analyzed by developer: 0 |
--------------------------------+---------------------------------------
== Problem
- Started a long encoding job, CPU was at 540% on my 8 cores, fans on,
encoding speed showed as circa 2.5x.
- Left MacBookPro unattended in good spirit to come back to a finished
result.
- Came back some 30min later or so. Screen was dimmed: Expected. But: Fans
silent...
- Touched keyboard (to wake it from sleep or at least dimmed screen with
the system running in a reduced power state, not sure which of the two it
was)
- ffmpeg encoding speed now showed at a crawling 0.05x or similar
(accumulated average over time).
- Conclusion: The system has been in sleep or reduced power state and the
encoding had came to a halt or slowdown.
== Reproduction
- Start a long ffmpeg job
- Check macOS power assertions with `pmset -g assertions`
- There is no power assertion by ffmpeg which would prevent system sleep.
== Competition & Best Practices
[https://handbrake.fr HandBrake] on macOS automatically sets a user
requested power assertion:
{{{
$ pmset -g assertions
[...]
pid 1234(HandBrake): [0x0003118f00019293] 00:00:15
PreventUserIdleSystemSleep named: "HandBrake is currently scanning and/or
encoding"
[...]
}}}
== Proposed Solution
- Offer "prevent-sleep" as an argument or config.
- Ideally on macOS to be compliant with conventions this is ON as a
default and needs to be opted out.
- This should not re-invent the wheel but utilized the proper mechanism
for this on the respective platform. (macOS in my case).
== macOS I/O Kit power assertions
- On macOS processes can create a power assertion to prevent system sleep
until they are done and the assertion gets revoked.
- This is great to start long jobs (like video encodings) unattended and
be sure that this job runs uninterrupted and unthrottled until done. Then
the system may go to sleep (according to your setup).
- See manpage and its chapters/keywords
- [https://ss64.com/osx/pmset.html pmset] -- manipulate power management
settings
- `-g assertions`
- [https://ss64.com/osx/caffeinate.html caffeinate] -- prevent the
system from sleeping on behalf of a utility
- `-i` Create an assertion to prevent the system from idle sleeping.
- caffeinate -i ffmpeg ...
== Environment
- ffmpeg 5.1.2 (installed via brew)
- macOS 11.7.7 Big Sur
== Workaround
- Invoke `ffmpeg` yourself via `caffeinate -i ffmpeg ...`.
- After 10 secs I checked pmset -g assertions and saw that it had created
a corresponding assertion indeed:
{{{
pid 12345(caffeinate): [0x0003105200019286] 00:00:10
PreventUserIdleSystemSleep named: "caffeinate command-line tool"
Details: caffeinate asserting on behalf of 'ffmpeg' (pid 12345)
Localized=THE CAFFEINATE TOOL IS PREVENTING SLEEP.
}}}
--
Ticket URL: <https://trac.ffmpeg.org/ticket/10447>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list