mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-20 11:35:56 +00:00
add:Rescale packet timestamp to container time base
Some containers force their own time base. For example, matroska overwrite time_base to (AVRational) {1, 1000}. Therefore, rescale our packet timestamps to the output stream time base.
This commit is contained in:
parent
247f8eb1d1
commit
cf459bbd32
2 changed files with 11 additions and 4 deletions
|
@ -12,6 +12,8 @@
|
|||
# define LAVF_NEW_CODEC_API
|
||||
#endif
|
||||
|
||||
static const AVRational SCRCPY_TIME_BASE = {1, 1000000}; // timestamps in us
|
||||
|
||||
Recorder::Recorder(const QString& fileName)
|
||||
: m_fileName(fileName)
|
||||
{
|
||||
|
@ -68,10 +70,7 @@ bool Recorder::open(AVCodec *inputCodec)
|
|||
outStream->codec->pix_fmt = AV_PIX_FMT_YUV420P;
|
||||
outStream->codec->width = m_declaredFrameSize.width();
|
||||
outStream->codec->height = m_declaredFrameSize.height();
|
||||
#endif
|
||||
// timestamps in us
|
||||
outStream->time_base.num = 1;
|
||||
outStream->time_base.den = 1000000;
|
||||
#endif
|
||||
|
||||
int ret = avio_open(&m_formatCtx->pb, m_fileName.toUtf8().toStdString().c_str(),
|
||||
AVIO_FLAG_WRITE);
|
||||
|
@ -112,6 +111,7 @@ bool Recorder::write(AVPacket *packet)
|
|||
}
|
||||
m_headerWritten = true;
|
||||
}
|
||||
recorderRescalePacket(packet);
|
||||
return av_write_frame(m_formatCtx, packet) >= 0;
|
||||
}
|
||||
|
||||
|
@ -161,3 +161,9 @@ bool Recorder::recorderWriteHeader(AVPacket *packet)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Recorder::recorderRescalePacket(AVPacket *packet)
|
||||
{
|
||||
AVStream *ostream = m_formatCtx->streams[0];
|
||||
av_packet_rescale_ts(packet, SCRCPY_TIME_BASE, ostream->time_base);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ public:
|
|||
private:
|
||||
const AVOutputFormat* findMp4Muxer();
|
||||
bool recorderWriteHeader(AVPacket* packet);
|
||||
void recorderRescalePacket(AVPacket *packet);
|
||||
|
||||
private:
|
||||
QString m_fileName = "";
|
||||
|
|
Loading…
Add table
Reference in a new issue