Problem: Receiving a stream of command line warnings as video plays - deprecated pixel format used, make sure you did set range correctly
Question: How can I stop the warnings from happening or being displayed?
Update - Fixed: The solution was too override the logging callback and don't do anything in the logging call method. FFmpeg logging is then disabled.
The reason for the message from FFmpeg is because it is grabbing frames from an old video format so is unavoidable if playing older videos.
NOTE: This solution completely disables all output from FFmpeg. Even FFmpeg errors are muted.
Code below (just frame grabbing, not timed playback).
package test.javacv;
import java.io.File;
import org.bytedeco.javacv.CanvasFrame;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.CustomLogCallback;
public class TestPlay implements Runnable {
private static String video_loc = null;
private static CanvasFrame canvas = new CanvasFrame("Test JavaCV player");
public static void main(String[] args) { new Thread(new TestPlay(args[0])).start(); }
static {
CustomLogCallback.set();
}
public void run() { play_video(video_loc); }
public TestPlay(String loc) {
video_loc = loc;
canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}
public static final void play_video(String vid_loc) {
try {
File file = new File(vid_loc);
FFmpegFrameGrabber ffmpeg_fg = new FFmpegFrameGrabber(file.getAbsolutePath());
Frame frm;
ffmpeg_fg.setAudioChannels(0);
ffmpeg_fg.start();
for(;;)
if((frm = ffmpeg_fg.grab()) != null) canvas.showImage(frm);
else {
ffmpeg_fg.setTimestamp(0);
break;
}
ffmpeg_fg.stop();
} catch(Exception ex) { ex("play_video vid_loc:" + vid_loc, ex); }
}
public static final void ex(String txt, Exception ex) {
System.out.println("EXCEPTION: " + txt + " stack..."); ex.printStackTrace(System.out); }
}
Logging class
// custom logger to override all logging output
package org.bytedeco.javacv;
import org.bytedeco.javacpp.BytePointer;
import static org.bytedeco.javacpp.avutil.LogCallback;
import static org.bytedeco.javacpp.avutil.setLogCallback;
public class CustomLogCallback extends LogCallback {
static final CustomLogCallback instance = new CustomLogCallback();
public static CustomLogCallback getInstance() { return instance; }
public static void set() { setLogCallback(getInstance()); }
@Override
public void call(int level, BytePointer msg) {}
}
You can adjust the logging level in JavaCV using org.bytedeco.javacpp.avutil.av_log_set_level()
.
calling avutil.av_log_set_level(avutil.AV_LOG_QUIET);
will probably get you what you want.