Skip to content

Commit 445d759

Browse files
committed
Preserve log level
1 parent 95a8c55 commit 445d759

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

av/filter/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from .filter import Filter, FilterFlags, filter_descriptor, filters_available
22
from .graph import Graph
3+
from .loudnorm import stats

av/filter/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from .context import *
22
from .filter import *
33
from .graph import *
4+
from .loudnorm import *

av/filter/loudnorm.pyx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ from av.audio.codeccontext cimport AudioCodecContext
88
from av.audio.stream cimport AudioStream
99
from av.container.core cimport Container
1010
from av.stream cimport Stream
11+
from av.logging import get_level, set_level
1112

1213

1314
cdef extern from "libavcodec/avcodec.h":
@@ -51,6 +52,9 @@ cpdef bytes stats(str loudnorm_args, AudioStream stream):
5152
cdef const char* c_args = py_args
5253
cdef char* result
5354

55+
# Save log level since C function overwrite it.
56+
level = get_level()
57+
5458
with nogil:
5559
result = loudnorm_get_stats(format_ptr, stream_index, c_args)
5660

@@ -60,4 +64,6 @@ cpdef bytes stats(str loudnorm_args, AudioStream stream):
6064
py_result = result[:] # Make a copy of the string
6165
free(result) # Free the C string
6266

67+
set_level(level)
68+
6369
return py_result

av/filter/loudnorm_impl.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <libavfilter/avfilter.h>
44
#include <libavfilter/buffersink.h>
55
#include <libavfilter/buffersrc.h>
6-
#include <libavutil/opt.h>
76
#include <string.h>
87

98
#ifdef _WIN32
@@ -154,22 +153,11 @@ char* loudnorm_get_stats(
154153
av_frame_unref(filt_frame);
155154
}
156155

157-
// Force stats print
158-
if (loudnorm_ctx) {
159-
av_log_set_level(AV_LOG_INFO);
160-
av_opt_set(loudnorm_ctx, "print_format", "json", AV_OPT_SEARCH_CHILDREN);
161-
av_opt_set(loudnorm_ctx, "measured_i", NULL, AV_OPT_SEARCH_CHILDREN);
162-
av_opt_set(loudnorm_ctx, "measured_lra", NULL, AV_OPT_SEARCH_CHILDREN);
163-
av_opt_set(loudnorm_ctx, "measured_tp", NULL, AV_OPT_SEARCH_CHILDREN);
164-
av_opt_set(loudnorm_ctx, "measured_thresh", NULL, AV_OPT_SEARCH_CHILDREN);
165-
avfilter_init_str(loudnorm_ctx, NULL);
166-
}
167-
168-
avfilter_graph_request_oldest(filter_graph);
156+
// Pushes graph
157+
avfilter_graph_free(&filter_graph);
169158

170159
end:
171160
avcodec_free_context(&codec_ctx);
172-
avfilter_graph_free(&filter_graph);
173161
avformat_close_input(&fmt_ctx);
174162
av_frame_free(&filt_frame);
175163
av_frame_free(&frame);

0 commit comments

Comments
 (0)