mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-26 13:12:39 +01:00
Fix waveform delay sync issue in mkv - thx Joel :)
This commit is contained in:
parent
291d3cd69a
commit
f33ffe12ad
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user