Skip to content

Commit

Permalink
Add -fix_sub_duration for each subtitle input in FFmpeg
Browse files Browse the repository at this point in the history
Closes #756
  • Loading branch information
Tyrrrz committed Dec 27, 2023
1 parent f08ac9d commit f716400
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion YoutubeExplode.Converter/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,27 @@ private async ValueTask ProcessAsync(

// Stream inputs
foreach (var streamInput in streamInputs)
{
arguments.Add("-i").Add(streamInput.FilePath);
}

// Subtitle inputs
foreach (var subtitleInput in subtitleInputs)
arguments.Add("-i").Add(subtitleInput.FilePath);
{
arguments
// Fix invalid subtitle durations for each input
// https://github.com/Tyrrrz/YoutubeExplode/issues/756
.Add("-fix_sub_duration")
.Add("-i")
.Add(subtitleInput.FilePath);
}

// Explicitly specify that all inputs should be used, because by default
// FFmpeg only picks one input per stream type (audio, video, subtitle).
for (var i = 0; i < streamInputs.Count + subtitleInputs.Count; i++)
{
arguments.Add("-map").Add(i);
}

// Output format and encoding preset
arguments.Add("-f").Add(container.Name).Add("-preset").Add(preset);
Expand Down Expand Up @@ -74,7 +85,9 @@ private async ValueTask ProcessAsync(

// MP4: explicitly specify the codec for subtitles, otherwise they won't get embedded
if (container == Container.Mp4 && subtitleInputs.Any())
{
arguments.Add("-c:s").Add("mov_text");
}

// MP3: explicitly specify the bitrate for audio streams, otherwise their metadata
// might contain invalid total duration.
Expand Down

0 comments on commit f716400

Please sign in to comment.