-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMP4ReaderExtensions.cs
More file actions
65 lines (59 loc) · 2.19 KB
/
Copy pathMP4ReaderExtensions.cs
File metadata and controls
65 lines (59 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System.Text;
using MP4Reader.IO;
namespace MP4Reader
{
/// <summary>
/// Extension methods for reading QuickTime specific encodings from a <see cref="SequentialReader"/>.
/// </summary>
internal static class MP4ReaderExtensions
{
public static string Get4ccString(this SequentialReader reader)
{
var sb = new StringBuilder(4);
sb.Append((char)reader.GetByte());
sb.Append((char)reader.GetByte());
sb.Append((char)reader.GetByte());
sb.Append((char)reader.GetByte());
return sb.ToString();
}
public static decimal Get16BitFixedPoint(this SequentialReader reader)
{
return decimal.Add(
reader.GetByte(),
decimal.Divide(reader.GetByte(), byte.MaxValue));
}
public static decimal Get32BitFixedPoint(this SequentialReader reader)
{
return decimal.Add(
reader.GetUInt16(),
decimal.Divide(reader.GetUInt16(), ushort.MaxValue));
}
private static decimal GetS32BitFixedPoint(this SequentialReader reader)
{
return decimal.Add(
reader.GetInt16(),
decimal.Divide(reader.GetUInt16(), ushort.MaxValue));
}
/// <summary>
/// Returns a matrix as float[9].
/// See <a href="https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-18737">QuickTime File Format Specification</a>.
/// </summary>
/// <param name="reader">The reader.</param>
/// <returns>System.Single[].</returns>
public static float[] GetMatrix(this SequentialReader reader)
{
var matrix = new float[9];
for (var i = 0; i < matrix.Length; i++)
{
var val = reader.GetS32BitFixedPoint();
// the right column is fixed 2.30 instead of 16.16
if (i == 2 || i == 5 || i == 8)
{
val /= 0x4000;
}
matrix[i] = (float)val;
}
return matrix;
}
}
}