Utilities¶
Logging¶
FFmpeg has a logging system that it uses extensively. 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()
Disabling Logging¶
You can disable hooking the logging system with an environment variable:
export PYAV_LOGGING=off
or at runtime with restore_default_callback()
.
This will leave (or restore) the FFmpeg logging system, which prints to the terminal. 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()¶
Return current FFmpeg logging threshold. See
set_level()
.
- av.logging.get_print_after_shutdown()¶
Will logging continue to
stderr
after Python shutdown?
- av.logging.get_skip_repeated()¶
Will identical logs be emitted?
- av.logging.log(int level, str name, str 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 logging threshold when converting from FFmpeg’s logging system to Python’s. It is recommended to use the constants available in this module to set the level:
PANIC
,FATAL
,ERROR
,WARNING
,INFO
,VERBOSE
, andDEBUG
.While less efficient, it is generally preferable to modify logging with Python’s
logging
, e.g.:logging.getLogger('libav').setLevel(logging.ERROR)
PyAV defaults to translating everything except
AV_LOG_DEBUG
, so this function is only nessesary to use if you want to see those messages as well.AV_LOG_DEBUG
will be translated to a level 5 message, which is lower than any builtin Python logging level, so you must lower that as well:logging.getLogger().setLevel(5)
- av.logging.set_print_after_shutdown(v)¶
Set if logging should continue to
stderr
after Python shutdown.
- av.logging.set_skip_repeated(v)¶
Set if identical logs will be emitted
Other¶
- av.utils.AVError¶
alias of
av.error.FFmpegError