Utilities¶
Logging¶
FFmpeg has a logging system that it uses extensively. It’s very noisy so PyAV turns it off by default. This, unfortunately has the effect of making raised errors having less detailed messages. It’s therefore recommended to use VERBOSE when developing.
Enabling Logging¶
You can hook the logging system with Python by setting the log level:
import av
av.logging.set_level(av.logging.VERBOSE)
PyAV hooks into that system to translate FFmpeg logs into Python’s logging system.
If you are not already using Python’s logging system, you can initialize it quickly with:
import logging
logging.basicConfig()
Note that handling logs with Python sometimes doesn’t play nice multi-threads workflows.
An alternative is restore_default_callback()
.
This will restores FFmpeg’s logging default system, which prints to the terminal.
Like with setting the log level to None
, this may also result in raised errors
having less detailed messages.
API Reference¶
- class av.logging.Capture(bool local=True)¶
Bases:
object
A context manager for capturing logs.
- Parameters:
local (bool) – Should logs from all threads be captured, or just one this object is constructed in?
e.g.:
with Capture() as logs: # Do something. for log in logs: print(log.message)
- logs¶
- av.logging.adapt_level(int level)¶
Convert a library log level to a Python log level.
- av.logging.get_last_error()¶
Get the last log that was at least
ERROR
.
- av.logging.get_level()¶
Returns the current log level. See
set_level()
.
- av.logging.get_skip_repeated()¶
Will identical logs be emitted?
- av.logging.log(int level, unicode name, unicode message)¶
Send a log through the library logging system.
This is mostly for testing.
- av.logging.restore_default_callback()¶
Revert back to FFmpeg’s log callback, which prints to the terminal.
- av.logging.set_level(level)¶
Sets PyAV’s log level. It can be set to constants available in this module:
PANIC
,FATAL
,ERROR
,WARNING
,INFO
,VERBOSE
,DEBUG
, orNone
(the default).PyAV defaults to totally ignoring all ffmpeg logs. This has the side effect of making certain Exceptions have no messages. It’s therefore recommended to use:
av.logging.set_level(av.logging.VERBOSE)
When developing your application.
- av.logging.set_libav_level(level)¶
Set libav’s log level. It can be set to constants available in this module:
PANIC
,FATAL
,ERROR
,WARNING
,INFO
,VERBOSE
,DEBUG
.When PyAV logging is disabled, setting this will change the level of the logs printed to the terminal.
- av.logging.set_skip_repeated(v)¶
Set if identical logs will be emitted
Other¶
- av.utils.AVError¶
alias of
FFmpegError