Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dump rejected ffmpeg options to console #2301

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

* Add `FFmpegLogCallback.logRejectedOptions()` for debugging purposes ([pull #2301](https://github.com/bytedeco/javacv/pull/2301))

### November 16, 2024 version 1.5.11
* Fix memory leak in `FFmpegFrameGrabber` when decoding from `InputStream` ([pull #2214](https://github.com/bytedeco/javacv/pull/2214))
* Upgrade dependencies for OpenBLAS 0.3.28, OpenCV 4.10.0, FFmpeg 7.1, Leptonica 1.85.0, Tesseract 5.5.0
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ public synchronized void startUnsafe(boolean findStreamInfo) throws Exception {
throw new Exception("avformat_open_input() error " + ret + ": Could not open input \"" + filename + "\". (Has setFormat() been called?)");
}
}
FFmpegLogCallback.logRejectedOptions(options, "avformat_open_input");
av_dict_free(options);

oc.max_delay(maxDelay);
Expand Down Expand Up @@ -1072,6 +1073,7 @@ public synchronized void startUnsafe(boolean findStreamInfo) throws Exception {
if ((ret = avcodec_open2(video_c, codec, options)) < 0) {
throw new Exception("avcodec_open2() error " + ret + ": Could not open video codec.");
}
FFmpegLogCallback.logRejectedOptions(options, "avcodec_open2");
av_dict_free(options);

// Hack to correct wrong frame rates that seem to be generated by some codecs
Expand Down Expand Up @@ -1123,6 +1125,7 @@ public synchronized void startUnsafe(boolean findStreamInfo) throws Exception {
if ((ret = avcodec_open2(audio_c, codec, options)) < 0) {
throw new Exception("avcodec_open2() error " + ret + ": Could not open audio codec.");
}
FFmpegLogCallback.logRejectedOptions(options, "avcodec_open2");
av_dict_free(options);

// Allocate audio samples frame
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/bytedeco/javacv/FFmpegFrameRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ public synchronized void startUnsafe() throws Exception {
av_dict_free(options);
throw new Exception("avcodec_open2() error " + ret + ": Could not open video codec.");
}
FFmpegLogCallback.logRejectedOptions(options, "avcodec_open2");
av_dict_free(options);

video_outbuf = null;
Expand Down Expand Up @@ -879,6 +880,7 @@ public synchronized void startUnsafe() throws Exception {
av_dict_free(options);
throw new Exception("avcodec_open2() error " + ret + ": Could not open audio codec.");
}
FFmpegLogCallback.logRejectedOptions(options, "avcodec_open2");
av_dict_free(options);

audio_outbuf_size = 256 * 1024;
Expand Down Expand Up @@ -962,6 +964,7 @@ public synchronized void startUnsafe() throws Exception {
av_dict_free(options);
throw new Exception(errorMsg);
}
FFmpegLogCallback.logRejectedOptions(options, "avio_open2");
oc.pb(pb);
}

Expand All @@ -976,6 +979,7 @@ public synchronized void startUnsafe() throws Exception {
av_dict_free(options);
throw new Exception(errorMsg);
}
FFmpegLogCallback.logRejectedOptions(options, "avformat_write_header");
av_dict_free(options);

if (av_log_get_level() >= AV_LOG_INFO) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/bytedeco/javacv/FFmpegLogCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ public static void setLevel(int level) {
av_log_set_level(level);
}

/** Logs the given rejected options regarding the given command */
public static void logRejectedOptions(final AVDictionary options, final String command) {
if (getLevel() >= AV_LOG_INFO && av_dict_count(options) > 0) {
final StringBuilder sb = new StringBuilder(command + " rejected some options:");
AVDictionaryEntry e = null;
while ((e = av_dict_iterate(options, e)) != null) {
sb.append("\tOption: ").append(e.key().getString()).append(", value: ").append(e.value().getString());
}
logger.info(sb.toString());
}
}

@Override public void call(int level, BytePointer msg) {
switch (level) {
case AV_LOG_PANIC:
Expand Down
Loading