Making ffmpeg / javacv less verbose in java

I have a Java application that uses the ffmpeg and javacv to download and process video files.

I am currently using the following code to upload a videofile to a data container.

 public boolean add(String videofile) { FrameGrabber g = new OpenCVFrameGrabber( videofile ); try{ g.start(); } catch(Exception e){ g = new FFmpegFrameGrabber( videofile ); try { g.start(); }catch(Exception x){ return false; } } grabbers.add( new Pair(videofile, g) ); frames.add( 0 ); preprocessed=false; return true; } 

Each time a video is uploaded, the library displays a lot of meta-information regarding the video itself:

Input # 0, mov, mp4, m4a, 3gp, 3g2, mj2, from '/home/lejlot/data/test.mp4': Metadata: major_brand: isom minor_version: 512 compatible_brands: isomiso2mp41 encoder: Lavf53.21.1 Duration: 00: 04: 36.27, start: 0.000000, bit: 305 kb / s Stream # 0: 0 (und): video: mpeg4 (simple profile) (mp4v / 0x7634706D), yuv420p, 1280x720 [SAR 1: 1 DAR 16 : 9], 303 kb / s, 20.85 fps, 30 tbr, 1k tbn, 1k tbc Metadata: handler name: VideoHandler

which, obviously, I do not want to see. I cannot (do not want) change the source code of the libraries, but rather change my own so that he can intercept this journal and drop it.

While I was trying to temporarily block stdout / stderr threads through

 private static final devnull = new PrintStream(new OutputStream() { @Override public void write(int b) { //DO NOTHING } @Override public void write(byte[] b,int x,int y){ } }); /** * Blocks messages to stdout */ public static void silentStdOut(){ System.setOut(devnull); } /** * Blocks messages to stderr */ public static void silentStdErr(){ System.setErr(devnull); } 

but it doesn't seem to help, the log message is still displayed

 public boolean add(String videofile) { Utils.silentStdErr(); Utils.silentStdOut(); FrameGrabber g = new OpenCVFrameGrabber( videofile ); try{ g.start(); } ,,, 

"Raw" ffmpeg can be set as less verbose using

 ffmpeg -loglevel panic 

but neither OpenCVFrameGrabber not FFmpegFrameGrabber gives access to tool parameters.

To summarize - how can I drop these log messages without changing the source code of the libraries?

+4
source share
2 answers

there was the same problem a few minutes ago, and also looked online, nothing but your question. Then I started digging into ffmpeg sources and found a solution by adding import:

 import com.googlecode.javacv.cpp.avutil; 

and then just call:

 avutil.av_log_set_level(avutil.AV_LOG_QUIET); 

before you create FFmpegFrameGrabber -> There is no more ffmpeg message form.

Yours faithfully
Daniel

+5
source

This is an updated solution (wrt javacv from github)

add the import statement below

 import static org.bytedeco.javacpp.avutil.AV_LOG_PANIC; import static org.bytedeco.javacpp.avutil.av_log_set_level; 

call the instruction below before creating FFmpegFrameGrabber -> No more ffmpeg form posts.

 av_log_set_level(AV_LOG_PANIC); 
0
source

Source: https://habr.com/ru/post/1497636/


All Articles