Go to the documentation of this file.
8 #include <exiv2/exiv2.hpp>
12 #include "libavformat/avformat.h"
18 #define LOC QString("ImageMetaData: ")
49 QStringList
vals = QStringList()
50 <<
"0 1 2 3 4 5 6 7 8"
51 <<
"0 1 2 3 4 5 6 7 8"
52 <<
"0 2 1 4 3 8 7 6 5"
53 <<
"0 3 4 1 2 7 8 5 6"
54 <<
"0 4 3 2 1 6 5 8 7"
55 <<
"0 5 6 7 8 1 2 3 4"
56 <<
"0 8 7 6 5 2 1 4 3"
57 <<
"0 7 8 5 6 3 4 1 2"
58 <<
"0 6 5 8 7 4 3 2 1";
60 for (
int row = 0; row <
vals.size(); ++row)
62 QStringList rowVals =
vals.at(row).split(
' ');
63 for (
int col = 0; col < rowVals.size(); ++col)
64 matrix[row][col] = rowVals.at(col).toInt();
95 LOG(VB_FILE, LOG_DEBUG,
LOC +
96 QString(
"Adjusted orientation %1 to %2 for Qt 5.4.1")
212 if (degrees ==
"0")
return 1;
213 if (degrees ==
"90")
return 6;
214 if (degrees ==
"180")
return 3;
215 if (degrees ==
"270")
return 8;
244 case 1:
return tr(
"1 (Normal)");
245 case 2:
return tr(
"2 (H Mirror)");
246 case 3:
return tr(
"3 (Rotate 180°)");
247 case 4:
return tr(
"4 (V Mirror)");
248 case 5:
return tr(
"5 (H Mirror, Rot 270°)");
249 case 6:
return tr(
"6 (Rotate 90°)");
250 case 7:
return tr(
"7 (H Mirror, Rot 90°)");
251 case 8:
return tr(
"8 (Rotate 270°)");
252 default:
return tr(
"%1 (Undefined)").arg(orientation);
274 std::string
GetTag(
const QString &key,
bool *
exists =
nullptr);
290 m_image = Exiv2::ImageFactory::open(filePath.toStdString());
299 LOG(VB_GENERAL, LOG_ERR,
LOC +
300 QString(
"Exiv2 error: Could not open file %1").arg(filePath));
303 catch (Exiv2::Error &e)
305 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Exiv2 exception %1").arg(e.what()));
323 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"Found %1 tag(s) for file %2")
326 Exiv2::ExifData::const_iterator i;
329 QString label = QString::fromStdString(i->tagLabel());
335 QString key = QString::fromStdString(i->key());
338 if (i->size() >= 256)
340 LOG(VB_FILE, LOG_DEBUG,
LOC +
341 QString(
"Ignoring %1 (%2, %3) : Too big")
342 .arg(key, i->typeName()).arg(i->size()));
347 LOG(VB_FILE, LOG_DEBUG,
LOC +
348 QString(
"Ignoring %1 (%2, %3) : Undecodable")
349 .arg(key, i->typeName()).arg(i->size()));
362 if (value.contains(QChar::Null))
364 LOG(VB_GENERAL, LOG_NOTICE,
LOC +
365 QString(
"Corrupted Exif detected in %1").arg(
m_filePath));
370 QString str =
ToString(key, label, value);
373 #ifdef DUMP_METADATA_TAGS
374 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"%1 (%2, %3)")
375 .arg(str, i->typeName()).arg(i->size()));
399 Exiv2::ExifKey exifKey = Exiv2::ExifKey(key.toStdString());
409 return exifIt->value().toString();
421 return QString::fromStdString(value).toInt();
433 QString dt = QString::fromStdString(value);
449 bool comExists =
false;
450 bool desExists =
false;
458 *
exists = comExists || desExists;
472 Exiv2::CommentValue comVal = Exiv2::CommentValue(rawValue);
473 if (comVal.charsetId() != Exiv2::CommentValue::undefined)
474 rawValue = comVal.comment();
475 return QString::fromStdString(rawValue);
498 QString
GetTag(
const QString &key,
bool *
exists =
nullptr);
513 AVInputFormat* p_inputformat =
nullptr;
516 if (avformat_open_input(&
m_context, filePath.toLatin1().constData(),
517 p_inputformat,
nullptr) < 0)
521 int vidStream = av_find_best_stream(
m_context, AVMEDIA_TYPE_VIDEO, -1, -1,
nullptr, 0);
560 args <<
"-loglevel quiet"
561 <<
"-print_format compact"
564 "format=format_long_name,duration,bit_rate:format_tags:"
565 "stream=codec_long_name,codec_type,width,height,pix_fmt,color_space,avg_frame_rate"
566 ",codec_tag_string,sample_rate,channels,channel_layout,bit_rate:stream_tags"
575 LOG(VB_GENERAL, LOG_ERR,
LOC +
576 QString(
"Timeout or Failed: %2 %3").arg(cmd,
args.join(
" ")));
580 QByteArray result = ffprobe.
ReadAll();
581 QTextStream ostream(result);
583 while (!ostream.atEnd())
585 QStringList fields = ostream.readLine().split(
'|');
587 if (fields.size() <= 1)
593 QString group = fields.takeFirst();
594 if (group ==
"stream")
597 prefix = QString::number(stream++) +
":";
601 for (
const auto& field : std::as_const(fields))
604 QStringList parts = field.split(
'=');
605 if (parts.size() != 2)
609 QString label = parts[0].remove(
"tag:");
610 QString value = parts[1];
613 QString key = QString(
"FFmpeg.%1.%2").arg(group, label);
619 #ifdef DUMP_METADATA_TAGS
620 LOG(VB_FILE, LOG_DEBUG,
LOC + str);
638 AVDictionaryEntry *tag =
nullptr;
639 while ((tag = av_dict_get(
m_dict,
"\0", tag, AV_DICT_IGNORE_SUFFIX)))
641 if (QString(tag->key) == key)
645 return QString::fromUtf8(tag->value);
724 for (
const auto& token : std::as_const(tagStrings))
728 if (parts.size() == 3)
732 QString group = parts[0].section(
'.', 0, 1);
733 tags.insert(group, parts);
735 #ifdef DUMP_METADATA_TAGS
736 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"%1 = %2").arg(group, token));
QHash< int, QHash< int, int > > Matrix
int m_current
The orientation to use: the file orientation with user transformations applied.
static int FromRotation(const QString °rees)
Convert degrees of rotation into Exif orientation code.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
static constexpr const char * MYTH_APPNAME_MYTHFFPROBE
int m_file
The orientation of the raw file image, as specified by the camera.
int GetCurrent(bool compensate)
Determines orientation required for an image.
int Transform(int transform)
Adjust orientation to apply a transform to an image.
@ GENERIC_EXIT_OK
Exited with no error.
int Composite() const
Encode original & current orientation to a single Db field.
uint Wait(std::chrono::seconds timeout=0s)
QString Description() const
Generate text description of orientation.
@ kMSRunShell
run process through shell
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
int Apply(int transform) const
Adjust current orientation code to apply a transform to an image.
static QString AsText(int orientation)
Converts orientation code to text description for info display.
static const Matrix kQt541_orientation
Orientation conversions for proper display on Qt 5.4.1.
static Matrix InitOrientationMatrix()
Initialises conversion matrix for Qt 5.4.1.
QString GetAppBinDir(void)
void Run(std::chrono::seconds timeout=0s)
Runs a command inside the /bin/sh shell. Returns immediately.
@ kMSStdOut
allow access to stdout
static const bool krunningQt541
True when using Qt 5.4.1 with its deviant orientation behaviour.