mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Don't trust AVFormatContext duration in Webm video.
It reports some strange numbers like 1000, which is 1ms.
This commit is contained in:
parent
219ffd2c48
commit
2e39befd7c
1 changed files with 14 additions and 0 deletions
|
@ -18,6 +18,18 @@ namespace {
|
||||||
constexpr auto kMaxSingleReadAmount = 8 * 1024 * 1024;
|
constexpr auto kMaxSingleReadAmount = 8 * 1024 * 1024;
|
||||||
constexpr auto kMaxQueuedPackets = 1024;
|
constexpr auto kMaxQueuedPackets = 1024;
|
||||||
|
|
||||||
|
[[nodiscard]] bool UnreliableFormatDuration(
|
||||||
|
not_null<AVFormatContext*> format,
|
||||||
|
not_null<AVStream*> stream) {
|
||||||
|
return stream->codec
|
||||||
|
&& (stream->codec->codec_id == AV_CODEC_ID_VP9)
|
||||||
|
&& format->iformat
|
||||||
|
&& format->iformat->name
|
||||||
|
&& QString::fromLatin1(
|
||||||
|
format->iformat->name
|
||||||
|
).split(QChar(',')).contains(u"webm");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
File::Context::Context(
|
File::Context::Context(
|
||||||
|
@ -174,6 +186,8 @@ Stream File::Context::initStream(
|
||||||
result.timeBase = info->time_base;
|
result.timeBase = info->time_base;
|
||||||
result.duration = (info->duration != AV_NOPTS_VALUE)
|
result.duration = (info->duration != AV_NOPTS_VALUE)
|
||||||
? FFmpeg::PtsToTime(info->duration, result.timeBase)
|
? FFmpeg::PtsToTime(info->duration, result.timeBase)
|
||||||
|
: UnreliableFormatDuration(format, info)
|
||||||
|
? kTimeUnknown
|
||||||
: FFmpeg::PtsToTime(format->duration, FFmpeg::kUniversalTimeBase);
|
: FFmpeg::PtsToTime(format->duration, FFmpeg::kUniversalTimeBase);
|
||||||
if (result.duration == kTimeUnknown) {
|
if (result.duration == kTimeUnknown) {
|
||||||
result.duration = kDurationUnavailable;
|
result.duration = kDurationUnavailable;
|
||||||
|
|
Loading…
Add table
Reference in a new issue