Skip to content

Commit

Permalink
* Add asetpts=N to input of FFmpegFrameFilter to make filters li…
Browse files Browse the repository at this point in the history
…ke `afade` behave as expected (issue #1171)
  • Loading branch information
saudet committed Apr 7, 2019
1 parent 35b59ca commit bfaeb87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Add `asetpts=N` to input of `FFmpegFrameFilter` to make filters like `afade` behave as expected ([issue #1171](https://github.com/bytedeco/javacv/issues/1171))
* Use `AVFormat.format()` from `Frame.opaque` when available in `FFmpegFrameFilter` and `FFmpegFrameRecorder` ([issue #1173](https://github.com/bytedeco/javacv/issues/1173))
* Enable multithreading for all codecs by default in `FFmpegFrameGrabber` and `FFmpegFrameRecorder` ([issue #1163](https://github.com/bytedeco/javacv/issues/1163))
* Improve thread safety of `FFmpegFrameRecorder` and `Java2DFrameConverter` by relying less on `Buffer.position` ([pull #1166](https://github.com/bytedeco/javacv/pull/1166))
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/org/bytedeco/javacv/FFmpegFrameFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public void releaseUnsafe() throws Exception {
avfilter_graph_free(afilter_graph);
abuffersink_ctx = null;
abuffersrc_ctx = null;
asetpts_ctx = null;
afilter_graph = null;
}
if (image_frame != null) {
Expand Down Expand Up @@ -185,6 +186,7 @@ public void releaseUnsafe() throws Exception {

AVFilterContext abuffersink_ctx;
AVFilterContext[] abuffersrc_ctx;
AVFilterContext[] asetpts_ctx;
AVFilterGraph afilter_graph;

AVFrame image_frame;
Expand Down Expand Up @@ -374,6 +376,7 @@ void startAudioUnsafe() throws Exception {
int ret;
AVFilter abuffersrc = avfilter_get_by_name("abuffer");
AVFilter abuffersink = avfilter_get_by_name("abuffersink");
AVFilter asetpts = avfilter_get_by_name("asetpts");
AVFilterInOut[] aoutputs = new AVFilterInOut[audioInputs];
AVFilterInOut ainputs = avfilter_inout_alloc();
int sample_fmts[] = { sampleFormat, AV_PIX_FMT_NONE };
Expand All @@ -385,6 +388,7 @@ void startAudioUnsafe() throws Exception {
}

abuffersrc_ctx = new AVFilterContext[audioInputs];
asetpts_ctx = new AVFilterContext[audioInputs];
for (int i = 0; i < audioInputs; i++) {
String name = audioInputs > 1 ? i + ":a" : "in";
aoutputs[i] = avfilter_inout_alloc();
Expand All @@ -398,6 +402,17 @@ void startAudioUnsafe() throws Exception {
throw new Exception("avfilter_graph_create_filter() error " + ret + ": Cannot create audio buffer source.");
}

ret = avfilter_graph_create_filter(asetpts_ctx[i] = new AVFilterContext(), asetpts, audioInputs > 1 ? "asetpts" + i : "asetpts",
"N", null, afilter_graph);
if (ret < 0) {
throw new Exception("avfilter_graph_create_filter() error " + ret + ": Cannot create asetpts filter.");
}

ret = avfilter_link(abuffersrc_ctx[i], 0, asetpts_ctx[i], 0);
if (ret < 0) {
throw new Exception("avfilter_graph_create_filter() error " + ret + ": Cannot link asetpts filter.");
}

/*
* Set the endpoints for the filter graph. The filter_graph will
* be linked to the graph described by filters_descr.
Expand All @@ -410,7 +425,7 @@ void startAudioUnsafe() throws Exception {
* default.
*/
aoutputs[i].name(av_strdup(new BytePointer(name)));
aoutputs[i].filter_ctx(abuffersrc_ctx[i]);
aoutputs[i].filter_ctx(asetpts_ctx[i]);
aoutputs[i].pad_idx(0);
aoutputs[i].next(null);
if (i > 0) {
Expand Down

0 comments on commit bfaeb87

Please sign in to comment.