Skip to content

Commit

Permalink
Fix framerate/timestamps in VideoWriter(Thread)
Browse files Browse the repository at this point in the history
  • Loading branch information
scotty007 committed Aug 26, 2020
1 parent 710e336 commit c477065
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/player/VideoWriterThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ void VideoWriterThread::open()
void VideoWriterThread::setupVideoStream()
{
m_pVideoStream = avformat_new_stream(m_pOutputFormatContext, 0);
m_pVideoStream->time_base.num = 1;
m_pVideoStream->time_base.den = m_FrameRate;

AVCodecContext* pCodecContext = m_pVideoStream->codec;
pCodecContext->codec_id = static_cast<AVCodecID>(m_pOutputFormat->video_codec);
Expand Down Expand Up @@ -287,10 +289,7 @@ void VideoWriterThread::writeFrame(AVFrame* pFrame)
if (!got_output) {
return;
}
if ((packet.pts) != (long long)AV_NOPTS_VALUE) {
packet.pts = av_rescale_q(packet.pts,
pCodecContext->time_base, m_pVideoStream->time_base);
}
av_packet_rescale_ts(&packet, pCodecContext->time_base, m_pVideoStream->time_base);
/* write the compressed frame in the media file */
ret = av_interleaved_write_frame(m_pOutputFormatContext, &packet);
av_free_packet(&packet);
Expand Down

0 comments on commit c477065

Please sign in to comment.