Skip to content

Commit

Permalink
Dump rejected ffmpeg options to console
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Wirger committed Nov 21, 2024
1 parent 24f36a1 commit 4c1764d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
import org.bytedeco.javacpp.Loader;
import org.bytedeco.javacpp.Pointer;
import org.bytedeco.javacpp.PointerScope;
import org.bytedeco.javacv.FFmpegFrameGrabber.ReadCallback;
import org.bytedeco.javacv.FrameGrabber.ImageMode;
import org.bytedeco.javacv.FrameGrabber.SampleMode;
import org.bytedeco.javacpp.PointerPointer;

import org.bytedeco.ffmpeg.avcodec.*;
Expand Down Expand Up @@ -989,6 +992,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?)");
}
}
logRejectedOptions(options, "avformat_open_input");
av_dict_free(options);

oc.max_delay(maxDelay);
Expand Down Expand Up @@ -1072,6 +1076,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.");
}
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 +1128,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.");
}
logRejectedOptions(options, "avcodec_open2");
av_dict_free(options);

// Allocate audio samples frame
Expand All @@ -1138,6 +1144,16 @@ public synchronized void startUnsafe(boolean findStreamInfo) throws Exception {
}
}

private void logRejectedOptions(final AVDictionary options, final String command) {
if (av_log_get_level() >= AV_LOG_INFO && av_dict_count(options) > 0) {
AVDictionaryEntry e = null;
System.out.println(command + " rejected some options:");
while ((e = av_dict_iterate(options, e)) != null) {
System.out.println("\tOption: " + e.key().getString() + ", value: " + e.value().getString());
}
}
}

private void initPictureRGB() {
int width = imageWidth > 0 ? imageWidth : video_c.width();
int height = imageHeight > 0 ? imageHeight : video_c.height();
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/org/bytedeco/javacv/FFmpegFrameRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
import org.bytedeco.javacpp.PointerScope;
import org.bytedeco.javacpp.PointerPointer;
import org.bytedeco.javacpp.ShortPointer;

import org.bytedeco.javacv.FFmpegFrameRecorder.WriteCallback;
import org.bytedeco.ffmpeg.avcodec.*;
import org.bytedeco.ffmpeg.avdevice.*;
import org.bytedeco.ffmpeg.avformat.*;
Expand Down 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.");
}
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.");
}
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);
}
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);
}
logRejectedOptions(options, "avformat_write_header");
av_dict_free(options);

if (av_log_get_level() >= AV_LOG_INFO) {
Expand Down Expand Up @@ -1311,6 +1315,16 @@ public synchronized boolean recordSamples(int sampleRate, int audioChannels, Buf
}
}

private void logRejectedOptions(final AVDictionary options, final String command) {
if (av_log_get_level() >= AV_LOG_INFO && av_dict_count(options) > 0) {
AVDictionaryEntry e = null;
System.out.println(command + " rejected some options:");
while ((e = av_dict_iterate(options, e)) != null) {
System.out.println("\tOption: " + e.key().getString() + ", value: " + e.value().getString());
}
}
}

private void writeSamples(int nb_samples) throws Exception {
if (samples_out == null || samples_out.length == 0) {
return;
Expand Down

0 comments on commit 4c1764d

Please sign in to comment.