Fix waveform delay sync issue in mkv - thx Joel :)

This commit is contained in:
Nikolaj Olsson 2020-09-19 09:23:31 +02:00
parent 291d3cd69a
commit f33ffe12ad
3 changed files with 19 additions and 4 deletions

View File

@ -111,6 +111,19 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.Matroska
return 0;
}
public long GetAudioTrackDelayMilliseconds(int audioTrackNumber)
{
var tracks = GetTracks(false);
var videoTrack = tracks.FirstOrDefault(p => p.IsVideo && p.IsDefault) ?? tracks.FirstOrDefault(p => p.IsVideo);
long videoDelay = 0;
if (videoTrack != null)
{
videoDelay = GetTrackStartTime(videoTrack.TrackNumber);
}
return GetTrackStartTime(audioTrackNumber) - videoDelay;
}
private long FindTrackStartInCluster(Element cluster, int targetTrackNumber)
{
long clusterTimeCode = 0L;

View File

@ -396,11 +396,12 @@ namespace Nikse.SubtitleEdit.Forms
matroska = new MatroskaFile(labelVideoFileName.Text);
if (matroska.IsValid)
{
_delayInMilliseconds = (int)matroska.GetTrackStartTime(mkvAudioTrackNumbers[_audioTrackNumber]);
_delayInMilliseconds = (int)matroska.GetAudioTrackDelayMilliseconds(mkvAudioTrackNumbers[_audioTrackNumber]);
}
}
catch
catch (Exception exception)
{
SeLogger.Error(exception, $"Error getting delay from mkv: {labelVideoFileName.Text}");
_delayInMilliseconds = 0;
}
finally

View File

@ -316,13 +316,14 @@ namespace Nikse.SubtitleEdit.Forms
}
if (mkvAudioTrackNumbers.Count > 0)
{
_delayInMilliseconds = (int)matroska.GetTrackStartTime(mkvAudioTrackNumbers[0]);
_delayInMilliseconds = (int)matroska.GetAudioTrackDelayMilliseconds(mkvAudioTrackNumbers[0]);
}
}
}
}
catch
catch (Exception exception)
{
SeLogger.Error(exception, $"Error getting delay from mkv: {fileName}");
_delayInMilliseconds = 0;
}
}