Skip to content

Commit

Permalink
* Set pts and dts for AVPacket in `FFmpegFrameRecorder.recordP…
Browse files Browse the repository at this point in the history
…acket()` (pull #1097)
  • Loading branch information
eguid authored and saudet committed Dec 2, 2018
1 parent d86bea1 commit 2010fa1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
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

0 comments on commit 2010fa1

Please sign in to comment.