-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make FFmpeg log level configurable (#2439)
Summary: Undesired logs are one of the loudest UX complains we get. Yet, loading media files involves uncertainty which is difficult to debug without debug log. This commit introduces utility functions to configure logging level so that we can ask users to enable it when they encounter an issue, while defaulting to non-verbose option. Pull Request resolved: #2439 Reviewed By: hwangjeff, xiaohui-zhang Differential Revision: D36903763 Pulled By: mthrok fbshipit-source-id: f4ddd9915b13197c2a2eb97e965005b8b5b8d987
- Loading branch information
1 parent
3229fc5
commit 877a88c
Showing
6 changed files
with
85 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from torchaudio.utils import ffmpeg_utils | ||
from torchaudio_unittest.common_utils import PytorchTestCase, skipIfNoFFmpeg | ||
|
||
|
||
@skipIfNoFFmpeg | ||
class TestFFmpegUtils(PytorchTestCase): | ||
"""Smoke test for ffmpeg_utils module""" | ||
|
||
def tearDown(self): | ||
ffmpeg_utils.set_log_level(8) | ||
super().tearDown() | ||
|
||
def test_get_log_level(self): | ||
"""`get_log_level` does not exhibit abnormal behavior""" | ||
for _ in range(10): | ||
ffmpeg_utils.get_log_level() | ||
|
||
def test_set_log_level(self): | ||
"""`set_log_level` persists log level""" | ||
for i in range(-100, 100): | ||
ffmpeg_utils.set_log_level(i) | ||
assert ffmpeg_utils.get_log_level() == i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
from torchaudio._internal import module_utils as _mod_utils | ||
|
||
from . import sox_utils | ||
from . import ffmpeg_utils, sox_utils | ||
from .download import download_asset | ||
|
||
if _mod_utils.is_sox_available(): | ||
sox_utils.set_verbosity(0) | ||
|
||
|
||
__all__ = [ | ||
"download_asset", | ||
"sox_utils", | ||
"ffmpeg_utils", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import torch | ||
|
||
|
||
def get_log_level() -> int: | ||
"""Get the log level of FFmpeg. | ||
See :py:func:`set_log_level` for the detailo. | ||
""" | ||
return torch.ops.torchaudio.ffmpeg_get_log_level() | ||
|
||
|
||
def set_log_level(level: int): | ||
"""Set the log level of FFmpeg (libavformat etc) | ||
Arguments: | ||
level (int): Log level. The larger, the more verbose. | ||
The following values are common values, the corresponding ``ffmpeg``'s | ||
``-loglevel`` option value and desription. | ||
* ``-8`` (``quiet``): | ||
Print no output. | ||
* ``0`` (``panic``): | ||
Something went really wrong and we will crash now. | ||
* ``8`` (``fatal``): | ||
Something went wrong and recovery is not possible. | ||
For example, no header was found for a format which depends | ||
on headers or an illegal combination of parameters is used. | ||
* ``16`` (``error``): | ||
Something went wrong and cannot losslessly be recovered. | ||
However, not all future data is affected. | ||
* ``24`` (``warning``): | ||
Something somehow does not look correct. | ||
This may or may not lead to problems. | ||
* ``32`` (``info``): | ||
Standard information. | ||
* ``40`` (``verbose``): | ||
Detailed information. | ||
* ``48`` (``debug``): | ||
Stuff which is only useful for libav* developers. | ||
* ``56`` (``trace``): | ||
Extremely verbose debugging, useful for libav* development. | ||
""" | ||
torch.ops.torchaudio.ffmpeg_set_log_level(level) |