diff --git a/av/filter/__init__.py b/av/filter/__init__.py index 207d6e15e..5dd4430d4 100644 --- a/av/filter/__init__.py +++ b/av/filter/__init__.py @@ -1,2 +1,3 @@ from .filter import Filter, FilterFlags, filter_descriptor, filters_available from .graph import Graph +from .loudnorm import stats diff --git a/av/filter/__init__.pyi b/av/filter/__init__.pyi index 8a6b5a59b..5be1326c9 100644 --- a/av/filter/__init__.pyi +++ b/av/filter/__init__.pyi @@ -1,3 +1,4 @@ from .context import * from .filter import * from .graph import * +from .loudnorm import * diff --git a/av/filter/loudnorm.pyx b/av/filter/loudnorm.pyx index 662bbd230..78f320a9e 100644 --- a/av/filter/loudnorm.pyx +++ b/av/filter/loudnorm.pyx @@ -8,6 +8,7 @@ from av.audio.codeccontext cimport AudioCodecContext from av.audio.stream cimport AudioStream from av.container.core cimport Container from av.stream cimport Stream +from av.logging import get_level, set_level cdef extern from "libavcodec/avcodec.h": @@ -51,6 +52,9 @@ cpdef bytes stats(str loudnorm_args, AudioStream stream): cdef const char* c_args = py_args cdef char* result + # Save log level since C function overwrite it. + level = get_level() + with nogil: result = loudnorm_get_stats(format_ptr, stream_index, c_args) @@ -60,4 +64,6 @@ cpdef bytes stats(str loudnorm_args, AudioStream stream): py_result = result[:] # Make a copy of the string free(result) # Free the C string + set_level(level) + return py_result diff --git a/av/filter/loudnorm_impl.c b/av/filter/loudnorm_impl.c index e8d56ddba..79f960080 100644 --- a/av/filter/loudnorm_impl.c +++ b/av/filter/loudnorm_impl.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #ifdef _WIN32 @@ -154,22 +153,11 @@ char* loudnorm_get_stats( av_frame_unref(filt_frame); } - // Force stats print - if (loudnorm_ctx) { - av_log_set_level(AV_LOG_INFO); - av_opt_set(loudnorm_ctx, "print_format", "json", AV_OPT_SEARCH_CHILDREN); - av_opt_set(loudnorm_ctx, "measured_i", NULL, AV_OPT_SEARCH_CHILDREN); - av_opt_set(loudnorm_ctx, "measured_lra", NULL, AV_OPT_SEARCH_CHILDREN); - av_opt_set(loudnorm_ctx, "measured_tp", NULL, AV_OPT_SEARCH_CHILDREN); - av_opt_set(loudnorm_ctx, "measured_thresh", NULL, AV_OPT_SEARCH_CHILDREN); - avfilter_init_str(loudnorm_ctx, NULL); - } - - avfilter_graph_request_oldest(filter_graph); + // Pushes graph + avfilter_graph_free(&filter_graph); end: avcodec_free_context(&codec_ctx); - avfilter_graph_free(&filter_graph); avformat_close_input(&fmt_ctx); av_frame_free(&filt_frame); av_frame_free(&frame);