Improve:time stamp bug.

This commit is contained in:
Fancy code 2024-07-12 16:12:18 +08:00
parent 19aa5e1599
commit da5aa894c7
2 changed files with 11 additions and 8 deletions

View File

@ -225,7 +225,7 @@ int FfmpegEncoder::EncodeData(AVFrame *frame, AVStream *stream, std::function<vo
// LogInfo("Write stream->time_base.num: %d\n", stream->time_base.num);
// LogInfo("Write stream->time_base.den: %d\n", stream->time_base.den);
mTmpPkt->stream_index = stream->index;
LogInfo("Write frame mTmpPkt->pts: %llu\n", mTmpPkt->pts);
LogInfo("aaaaaaaaaaaaaaaaaaaaaaa Write frame mTmpPkt->pts: %llu\n", mTmpPkt->pts);
if (callback) {
// save_code_stream_file(mTmpPkt->data, mTmpPkt->size);
@ -355,10 +355,12 @@ AVFrame *FfmpegEncoder::ConvertAudioFrame(AVFrame *decodeFrame, struct SwrContex
LogError("Error while converting\n");
return nullptr;
}
mFrame->pts = av_rescale_q(decodeFrame->pts, (AVRational){1, SOURCE_AUDIO_SAMPEL_RATE}, mCodecCtx->time_base);
LogInfo("decodeFrame->pts = %d\n", decodeFrame->pts);
LogInfo("mFrame->pts = %d\n", mFrame->pts);
LogInfo("mCodecCtx->time_base.num = %d, mCodecCtx->time_base.den=%d\n",
mCodecCtx->time_base.num,
mCodecCtx->time_base.den);
mFrame->pts = av_rescale_q(decodeFrame->pts, (AVRational){1, 1000000}, mCodecCtx->time_base);
// LogInfo("decodeFrame->pts = %d\n", decodeFrame->pts);
// LogInfo("mFrame->pts = %d\n", mFrame->pts);
mSamplesCount += dst_nb_samples;
return mFrame;
}

View File

@ -68,7 +68,7 @@ bool FfmpegOutputStream::Init(AVFormatContext *outputFormat)
* @brief There is no need to set time_base here, time_base will be automatically corrected inside ffmpeg.
*
*/
// mStream->time_base = (AVRational){1, 15};
mStream->time_base = (AVRational){1, 15};
mStream->codecpar->codec_id = AV_CODEC_ID_H264;
mStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
mStream->codecpar->width = 1920;
@ -109,8 +109,9 @@ void FfmpegOutputStream::WriteSourceData(const void *data, const size_t &size, c
constexpr int64_t ZERO_MEANS_UNKNOWN = 0;
tmpPkt->duration = ZERO_MEANS_UNKNOWN;
// tmpPkt->pts = u64Interval * 1000; // ת<><D7AA><EFBFBD><EFBFBD> us
tmpPkt->pts = av_rescale_q(pts, (AVRational){1, 15}, mStream->time_base);
// LogInfo("pts:%llu, duration:%d\n", tmpPkt->pts, tmpPkt->duration);
tmpPkt->pts = av_rescale_q(pts, (AVRational){1, 1000000}, mStream->time_base);
LogInfo("vvvvvvvvvvvvvvvvvvvvvvvvv num:%d, den:%d\n", mStream->time_base.num, mStream->time_base.den);
LogInfo("vvvvvvvvvvvvvvvvvvvvvvvvv pts:%llu, duration:%d\n", tmpPkt->pts, tmpPkt->duration);
// tmpPkt->pts = pts;
u64Interval++;
tmpPkt->dts = tmpPkt->pts;