Mp4 - allow signed TimeOffset for samples (when version==1)

This commit is contained in:
niksedk 2023-10-28 20:48:31 +02:00
parent 1c6341484b
commit fb5d0380b4
4 changed files with 9 additions and 3 deletions

View File

@ -21,6 +21,11 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.Mp4.Boxes
return (uint)((Buffer[index] << 24) + (Buffer[index + 1] << 16) + (Buffer[index + 2] << 8) + Buffer[index + 3]);
}
public int GetInt(int index)
{
return (int)((Buffer[index] << 24) + (Buffer[index + 1] << 16) + (Buffer[index + 2] << 8) + Buffer[index + 3]);
}
public ulong GetUInt64(int index)
{
return (ulong)Buffer[index] << 56 | (ulong)Buffer[index + 1] << 48 | (ulong)Buffer[index + 2] << 40 | (ulong)Buffer[index + 3] << 32 |

View File

@ -29,6 +29,7 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.Mp4.Boxes
}
var versionAndFlags = GetUInt(0);
var version = versionAndFlags >> 24;
var flags = versionAndFlags & 0xFFFFFF;
var sampleCount = GetUInt(4);
if (sampleCount == 0)
@ -105,7 +106,7 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.Mp4.Boxes
// read "sample_time_offset" if present
if ((flags & 0x000800) > 0)
{
sample.TimeOffset = GetUInt(pos);
sample.TimeOffset = version == 1 ? GetInt(pos) : (long)GetUInt(pos);
pos += 4;
}

View File

@ -107,7 +107,7 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.Mp4
if (presentation.Duration.HasValue)
{
var startTime = presentation.TimeOffset.HasValue ? presentation.BaseMediaDecodeTime + presentation.TimeOffset.Value : presentation.BaseMediaDecodeTime;
var startTime = presentation.TimeOffset.HasValue ? (ulong)((long)presentation.BaseMediaDecodeTime + presentation.TimeOffset.Value) : presentation.BaseMediaDecodeTime;
var currentTime = startTime + presentation.Duration.Value;
// The payload can be null as that would mean that it was a VTTE and

View File

@ -4,7 +4,7 @@
{
public uint? Duration { get; set; }
public uint? Size { get; set; }
public uint? TimeOffset { get; set; }
public long? TimeOffset { get; set; }
public ulong BaseMediaDecodeTime { get; set; }
}
}