Skip to content

Commit

Permalink
Fix bug where samples_out was being flushed before flushing the swr_c…
Browse files Browse the repository at this point in the history
…ontext.
  • Loading branch information
Josh Bultman committed Dec 5, 2024
1 parent 8b85ac1 commit d3fe0b7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/java/org/bytedeco/javacv/FFmpegFrameRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1170,13 +1170,6 @@ public synchronized boolean recordSamples(int sampleRate, int audioChannels, Buf
throw new Exception("start() was not called successfully!");
}

if (samples == null && samples_out[0].position() > 0) {
// Typically samples_out[0].limit() is double the audio_input_frame_size --> sampleDivisor = 2
double sampleDivisor = Math.floor((int)Math.min(samples_out[0].limit(), Integer.MAX_VALUE) / audio_input_frame_size);
writeSamples((int)Math.floor((int)samples_out[0].position() / sampleDivisor));
return writeFrame((AVFrame)null);
}

if (samples == null && samples_convert_ctx == null) {
// We haven't tried to record any samples yet so we don't need to flush.
return false;
Expand Down Expand Up @@ -1322,6 +1315,14 @@ public synchronized boolean recordSamples(int sampleRate, int audioChannels, Buf
writeSamples(audio_input_frame_size);
}
}

if (samples == null && samples_out[0].position() > 0) {
// Typically samples_out[0].limit() is double the audio_input_frame_size --> sampleDivisor = 2
double sampleDivisor = Math.floor((int)Math.min(samples_out[0].limit(), Integer.MAX_VALUE) / audio_input_frame_size);
writeSamples((int)Math.floor((int)samples_out[0].position() / sampleDivisor));
return writeFrame((AVFrame)null);
}

return samples != null ? frame.key_frame() != 0 : writeFrame((AVFrame)null);

}
Expand Down

0 comments on commit d3fe0b7

Please sign in to comment.