-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New video finalization method (#1103)
* Concat video parts with FFmpeg * Fix too long chapters causing some video players to hallucinate a longer video duration * Fix race conditions * Implement unused CancellationToken * Log failure to clean up * Forgot to specify concat arg. May or may not be necessary * Fix video trimming * Make sure to dispose of FFmpeg * Don't append trim args unless absolutely necessary * Cleanup * Fix
- Loading branch information
Showing
9 changed files
with
187 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace TwitchDownloaderCore.Tools | ||
{ | ||
// https://www.ffmpeg.org/ffmpeg-formats.html#toc-concat-1 | ||
public static class FfmpegConcatList | ||
{ | ||
private const string LINE_FEED = "\u000A"; | ||
|
||
public static async Task SerializeAsync(string filePath, M3U8 playlist, Range videoListCrop, CancellationToken cancellationToken = default) | ||
{ | ||
await using var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read); | ||
await using var sw = new StreamWriter(fs) { NewLine = LINE_FEED }; | ||
|
||
await sw.WriteLineAsync("ffconcat version 1.0"); | ||
|
||
foreach (var stream in playlist.Streams.Take(videoListCrop)) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
|
||
await sw.WriteAsync("file '"); | ||
await sw.WriteAsync(stream.Path); | ||
await sw.WriteLineAsync('\''); | ||
|
||
await sw.WriteAsync("duration "); | ||
await sw.WriteLineAsync(stream.PartInfo.Duration.ToString(CultureInfo.InvariantCulture)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.