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

Repair the problem of error decoding and playback caused by the absen… #1097

Merged
merged 3 commits into from
Dec 2, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Set `pts` and `dts` for `AVPacket` in `FFmpegFrameRecorder.recordPacket()` ([pull #1097](https://github.com/bytedeco/javacv/pull/1097))
* Prevent premature deallocations with `LeptonicaFrameConverter` ([issue bytedeco/javacpp#272](https://github.com/bytedeco/javacpp/issues/272))
* Fix `OpenCVFrameGrabber` from crashing when in `ImageMode.GRAY`
* Add support for multiple inputs to `FFmpegFrameFilter` ([issue #955](https://github.com/bytedeco/javacv/issues/955))
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/org/bytedeco/javacv/FFmpegFrameRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1203,23 +1203,28 @@ public boolean recordPacket(AVPacket pkt) throws Exception {
}

AVStream in_stream = ifmt_ctx.streams(pkt.stream_index());

pkt.dts(AV_NOPTS_VALUE);
pkt.pts(AV_NOPTS_VALUE);
/**
* Repair the problem of error decoding and playback caused by the absence of dts/pts
* in the output audio/video file or audio/video stream,
* Comment out this line of code so that PTS / DTS can specify the timestamp manually.
*/
// pkt.dts(AV_NOPTS_VALUE);
// pkt.pts(AV_NOPTS_VALUE);
pkt.pos(-1);

if (in_stream.codec().codec_type() == AVMEDIA_TYPE_VIDEO && video_st != null) {

pkt.stream_index(video_st.index());
pkt.duration((int) av_rescale_q(pkt.duration(), in_stream.codec().time_base(), video_st.codec().time_base()));

pkt.pts(av_rescale_q_rnd(pkt.pts(), in_stream.time_base(), video_st.time_base(),(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX)));//Increase pts calculation
pkt.dts(av_rescale_q_rnd(pkt.dts(), in_stream.time_base(), video_st.time_base(),(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX)));//Increase dts calculation
writePacket(AVMEDIA_TYPE_VIDEO, pkt);

} else if (in_stream.codec().codec_type() == AVMEDIA_TYPE_AUDIO && audio_st != null && (audioChannels > 0)) {

pkt.stream_index(audio_st.index());
pkt.duration((int) av_rescale_q(pkt.duration(), in_stream.codec().time_base(), audio_st.codec().time_base()));

pkt.pts(av_rescale_q_rnd(pkt.pts(), in_stream.time_base(), audio_st.time_base(),(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX)));//Increase pts calculation
pkt.dts(av_rescale_q_rnd(pkt.dts(), in_stream.time_base(), audio_st.time_base(),(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX)));//Increase dts calculation
writePacket(AVMEDIA_TYPE_AUDIO, pkt);
}

Expand Down