PyAV-Org / PyAV

Pythonic bindings for FFmpeg's libraries.
https://pyav.basswood-io.com/
BSD 3-Clause "New" or "Revised" License
2.38k stars 354 forks source link

Logging can't be disabled #711

Closed pohmelie closed 2 months ago

pohmelie commented 3 years ago

Overview

I want to shut up any logging from av and underlying ffmpeg. I tried all of this:

logging.basicConfig()
av.logging.set_level(av.logging.PANIC)
logging.getLogger('libav').setLevel(logging.ERROR)

Btw, docs said there is av.logging.QUIET, but it missed.

Expected behavior

No logs.

Actual behavior

I encode video frame by frame. I see tons of almost equal output like this:

[jpeg2000 @ 0x7f8408000940] End mismatch 3
[jpeg2000 @ 0x7f8408000940] End mismatch 4
[jpeg2000 @ 0x7f8408000940] End mismatch 4
[jpeg2000 @ 0x7f8408000940] End mismatch 3
[jpeg2000 @ 0x7f8408000940] End mismatch 3
[jpeg2000 @ 0x7f8408000940] End mismatch 3

Versions

Research

I have done the following:

ashat1701 commented 2 years ago

Hey! I faced same issue, anyone know how to fix it?

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

jlaine commented 2 years ago

Let's keep this issue alive, the logging framework is due for an overhaul.

d4l3k commented 2 years ago

Are the logging levels flipped?

I've been getting some ffmpeg logs that I wanted to silence to avoid spamming the console but I'm seeing some weird behavior.

av.logging.set_level(logging.INFO/DEBUG) silences the ffmpeg warnings but WARNING-CRITICAL show them. It seems like it should be the opposite. If you set log level CRITICAL it should only show CRITICAL and above logs. But it seems to be only X and below priority. So setting logging.INFO only shows INFO and DEBUG but not error/critical?

nilsh commented 1 year ago

Update on this for my tests:

jlaine commented 1 year ago

I'd still love to see this fixed, though I'm not sure I'll have time to do it myself.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

InkosiZhong commented 1 year ago

I'm trying to use PyAV to mux a lot of video, so I want to disable the log as below:

x265 [info]: HEVC encoder version 3.5+1-f0c1022b6
x265 [info]: build info [Linux][GCC 10.2.1][64 bit] 8bit+10bit+12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main profile, Level-4 (Main tier)
x265 [info]: Thread pool created using 16 threads
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 4 / wpp(17 rows)
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge         : hex / 57 / 2 / 3
x265 [info]: Keyframe min / max / scenecut / bias  : 25 / 250 / 40 / 5.00 
x265 [info]: Lookahead / bframes / badapt        : 20 / 4 / 2
x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 0
x265 [info]: References / ref-limit  cu / depth  : 3 / off / on
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 2 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress            : ABR-1024 kbps / 0.60
x265 [info]: tools: rd=3 psy-rd=2.00 early-skip rskip mode=1 signhide tmvp
x265 [info]: tools: b-intra strong-intra-smoothing lslices=6 deblock sao

encoded 0 frames

I have tried the methods in https://pyav.org/docs/develop/api/utils.html, but the log still exists. And I find this line in the doc:

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.

I think this log may be produced by ffmpeg. How can I disable it? Thank you very much.

hanl754 commented 1 year ago

same issue. mark

eerimoq commented 1 year ago

I implemented a "dirty" workaround in PR https://github.com/PyAV-Org/PyAV/pull/1133. It's obviously a proper solution, so if someone can figure out how to implement a proper fix, feel free to ignore my PR =)

eerimoq commented 1 year ago

Another workaround is to close stderr, given that your application does not write other information to it.

import os
import av
os.close(2)
av.logging.restore_default_callback()
zthorson commented 10 months ago

A slightly cleaner workaround is to pass arguments to ffmpeg itself to disable logging. This got rid of the chatty h265 encoder messages for me while leaving stderr untouched.

For example:

av_codec = av.CodecContext.create('hevc', 'r')
mp4 = av.open('./test.mp4', mode='w')
cur_mp4_stream = stream.mp4.add_stream('hevc', rate=30, options={'x265-params': 'log_level=none'})
gonzaloplaza commented 9 months ago

If you're still looking for a workaround, updating the log level to a higher one worked for us

More info here: https://pyav.org/docs/stable/api/utils.html

logging.getLogger("libav").setLevel(logging.FATAL)

Also they suggest to set this env variable to off, but it didn't work in our case:

export PYAV_LOGGING=off
WyattBlue commented 2 months ago

You can disable logs now in master. In fact, it's the default behaviour now.

import av

# turn off logs
av.logging.set_level(None)

# turn on logs
av.logging.set_level(av.logging.VERBOSE)
pohmelie commented 2 months ago

@WyattBlue should I close this then?