mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix rotation reading in FFmpeg.
This commit is contained in:
parent
615f4b1d1c
commit
046803dbed
1 changed files with 11 additions and 9 deletions
|
@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <libavutil/opt.h>
|
#include <libavutil/opt.h>
|
||||||
|
#include <libavutil/display.h>
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
namespace FFmpeg {
|
namespace FFmpeg {
|
||||||
|
@ -503,16 +504,17 @@ int DurationByPacket(const Packet &packet, AVRational timeBase) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int ReadRotationFromMetadata(not_null<AVStream*> stream) {
|
int ReadRotationFromMetadata(not_null<AVStream*> stream) {
|
||||||
const auto tag = av_dict_get(stream->metadata, "rotate", nullptr, 0);
|
const auto displaymatrix = av_stream_get_side_data(
|
||||||
if (tag && *tag->value) {
|
stream,
|
||||||
const auto string = QString::fromUtf8(tag->value);
|
AV_PKT_DATA_DISPLAYMATRIX,
|
||||||
auto ok = false;
|
nullptr);
|
||||||
const auto degrees = string.toInt(&ok);
|
auto theta = 0;
|
||||||
if (ok && (degrees == 90 || degrees == 180 || degrees == 270)) {
|
if (displaymatrix) {
|
||||||
return degrees;
|
theta = -round(av_display_rotation_get((int32_t*)displaymatrix));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
theta -= 360 * floor(theta / 360 + 0.9 / 360);
|
||||||
|
const auto result = int(base::SafeRound(theta));
|
||||||
|
return (result == 90 || result == 180 || result == 270) ? result : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVRational ValidateAspectRatio(AVRational aspect) {
|
AVRational ValidateAspectRatio(AVRational aspect) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue