Detect YUV4MPEG2 files

This commit is contained in:
Martchus 2017-09-03 18:26:32 +02:00
parent ab9ab4ba48
commit a2b36a0b30
4 changed files with 29 additions and 9 deletions

View File

@ -84,7 +84,7 @@ enum class GeneralMediaFormat
Tiff, /**< TIFF */
TimedText, /**< Timed Text */
Tta, /**< The True Audio lessles audio compressor */
UncompressedVideoFrames, /**< uncompressed RGB */
UncompressedVideoFrames, /**< uncompressed RGB or YCbCr */
Vc1, /**< VC-1 */
VobBtn, /**< VobBtn */
VobSub, /**< VobSub */

View File

@ -71,7 +71,6 @@ void OggStream::internalParseHeader()
if((sig & 0x00ffffffffffff00u) == 0x00766F7262697300u) {
// Vorbis header detected
// set Vorbis as format
switch(m_format.general) {
case GeneralMediaFormat::Unknown:
m_format = GeneralMediaFormat::Vorbis;
@ -134,7 +133,6 @@ void OggStream::internalParseHeader()
} else if(sig == 0x4F70757348656164u) {
// Opus header detected
// set Opus as format
switch(m_format.general) {
case GeneralMediaFormat::Unknown:
m_format = GeneralMediaFormat::Opus;
@ -176,7 +174,6 @@ void OggStream::internalParseHeader()
} else if(sig == 0x4F70757354616773u) {
// Opus comment detected
// set Opus as format
switch(m_format.general) {
case GeneralMediaFormat::Unknown:
m_format = GeneralMediaFormat::Opus;
@ -199,7 +196,6 @@ void OggStream::internalParseHeader()
} else if((sig & 0xFFFFFFFFFF000000u) == 0x7F464C4143000000u) {
// FLAC header detected
// set FLAC as format
switch(m_format.general) {
case GeneralMediaFormat::Unknown:
m_format = GeneralMediaFormat::Flac;
@ -255,7 +251,6 @@ void OggStream::internalParseHeader()
} else if((sig & 0x00ffffffffffff00u) == 0x007468656F726100u) {
// Theora header detected
// set Theora as format
switch(m_format.general) {
case GeneralMediaFormat::Unknown:
m_format = GeneralMediaFormat::Theora;
@ -269,7 +264,22 @@ void OggStream::internalParseHeader()
}
// TODO: read more information about Theora stream
} // currently only Vorbis, Opus and Theora can be detected, TODO: detect more formats
} else if(sig == 0x595556344D504547u) {
// YUV4MPEG header detected
switch(m_format.general) {
case GeneralMediaFormat::Unknown:
m_format = GeneralMediaFormat::UncompressedVideoFrames;
m_mediaType = MediaType::Video;
m_chromaFormat = "YUV";
break;
case GeneralMediaFormat::UncompressedVideoFrames:
break;
default:
addNotification(NotificationType::Warning, "Stream format is inconsistent.", context);
continue;
}
// TODO: read more information about YUV4MPEG stream
}
} else {
// just ignore segments of only 8 byte or even less
@ -279,7 +289,7 @@ void OggStream::internalParseHeader()
// TODO: reduce code duplication
}
if(m_duration.isNull() && m_size && m_bitrate) {
if(m_duration.isNull() && m_size && m_bitrate != 0.0) {
// calculate duration from stream size and bitrate, assuming 1 % overhead
m_duration = TimeSpan::fromSeconds(static_cast<double>(m_size) / (m_bitrate * 125.0) * 1.1);
}

View File

@ -17,6 +17,7 @@ enum Sig64 : uint64
Asf2 = 0xA6D900AA0062CE6Cul,
Png = 0x89504E470D0A1A0Aul,
RiffAvi = 0x415649204C495354ul,
YUV4Mpeg2 = 0x595556344D504547ul,
};
/*!
@ -125,6 +126,11 @@ ContainerFormat parseSignature(const char *buffer, int bufferSize)
return ContainerFormat::Asf;
case Png:
return ContainerFormat::Png;
case YUV4Mpeg2:
if(bufferSize >= 10 && buffer[8] == 0x32 && buffer[9] == 0x20) {
return ContainerFormat::YUV4Mpeg2;
}
break;
default:
;
}
@ -310,6 +316,7 @@ const char *containerFormatAbbreviation(ContainerFormat containerFormat, MediaTy
case ContainerFormat::Zip: return "zip";
case ContainerFormat::SevenZ: return "7z";
case ContainerFormat::Xz: return "xz";
case ContainerFormat::YUV4Mpeg2: return "y4m";
default: return "";
}
}
@ -402,6 +409,8 @@ const char *containerFormatName(ContainerFormat containerFormat)
return "Quick Time";
case ContainerFormat::Xz:
return "xz compressed file";
case ContainerFormat::YUV4Mpeg2:
return "YUV4MPEG2";
case ContainerFormat::Zip:
return "ZIP archive";
default:

View File

@ -59,7 +59,8 @@ enum class ContainerFormat
WindowsBitmap, /**< Microsoft Windows Bitmap */
WindowsIcon, /**< Microsoft Windows Icon */
Zip, /**< ZIP archive */
Xz /**< xz compressed file */
Xz, /**< xz compressed file */
YUV4Mpeg2, /**< YUV4MPEG2 */
};
TAG_PARSER_EXPORT ContainerFormat parseSignature(const char *buffer, int bufferSize);