Skip to content

Commit

Permalink
Don't try muxing audio/subtitles from GIF inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
n00mkrad committed Nov 29, 2024
1 parent 075dd06 commit 6278fed
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions CodeLegacy/Main/Export.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ public static async Task ExportFrames(string path, string outFolder, OutputSetti
}
}

private const bool _useNutPipe = true;

public static async Task<string> GetPipedFfmpegCmd(bool ffplay = false)
{
InterpSettings s = I.currentSettings;
string encArgs = FfmpegUtils.GetEncArgs(s.outSettings, (s.OutputResolution.IsEmpty ? s.InputResolution : s.OutputResolution), s.outFps.Float, true).FirstOrDefault();
bool fpsLimit = MaxFpsFrac.Float > 0f && s.outFps.Float > MaxFpsFrac.Float;
bool gifInput = I.currentMediaFile.Format.Upper() == "GIF"; // If input is GIF, we don't need to check the color space etc
VidExtraData extraData = gifInput ? new VidExtraData() : await FfmpegCommands.GetVidExtraInfo(s.inPath);
string extraArgsIn = await FfmpegEncode.GetFfmpegExportArgsIn(s.FpsResampling ? s.outFpsResampled : s.outFps, s.outItsScale, extraData.Rotation);
string extraArgsIn = await FfmpegEncode.GetFfmpegExportArgsIn(I.currentMediaFile.IsVfr ? s.outFpsResampled : s.outFps, s.outItsScale, extraData.Rotation);
string extraArgsOut = await FfmpegEncode.GetFfmpegExportArgsOut(fpsLimit ? MaxFpsFrac : new Fraction(), extraData, s.outSettings);

// For EXR, force bt709 input flags. Not sure if this really does anything, EXR
Expand All @@ -89,9 +91,8 @@ public static async Task<string> GetPipedFfmpegCmd(bool ffplay = false)

if (ffplay)
{
bool useNutPipe = true; // TODO: Make this bool a config flag
encArgs = useNutPipe ? "-c:v rawvideo -pix_fmt rgba" : $"-pix_fmt yuv444p16";
string format = useNutPipe ? "nut" : "yuv4mpegpipe";
encArgs = _useNutPipe ? "-c:v rawvideo -pix_fmt rgba" : $"-pix_fmt yuv444p16";
string format = _useNutPipe ? "nut" : "yuv4mpegpipe";

return
$"{extraArgsIn} -i pipe: {encArgs} {extraArgsOut} -f {format} - | ffplay - " +
Expand Down Expand Up @@ -198,14 +199,14 @@ static async Task Encode(OutputSettings settings, string framesPath, string outP
VidExtraData extraData = await FfmpegCommands.GetVidExtraInfo(I.currentSettings.inPath);
await FfmpegEncode.FramesToVideo(framesFile, outPath, settings, fps, resampleFps, I.currentSettings.outItsScale, extraData);
await MuxOutputVideo(I.currentSettings.inPath, outPath);
await Loop(outPath, await GetLoopTimes());
await Loop(outPath, GetLoopTimes());
}
}

public static async Task MuxPipedVideo(string inputVideo, string outputPath)
{
await MuxOutputVideo(inputVideo, Path.Combine(outputPath, outputPath));
await Loop(outputPath, await GetLoopTimes());
await Loop(outputPath, GetLoopTimes());
}

public static async Task ChunksToVideo(string tempFolder, string chunksFolder, string baseOutPath, bool isBackup = false)
Expand Down Expand Up @@ -268,7 +269,7 @@ static async Task MergeChunks(string framesFile, string outPath, bool isBackup =
await MuxOutputVideo(I.currentSettings.inPath, outPath, isBackup, !isBackup);

if (!isBackup)
await Loop(outPath, await GetLoopTimes());
await Loop(outPath, GetLoopTimes());
}

public static async Task EncodeChunk(string outPath, string interpDir, int chunkNo, OutputSettings settings, int firstFrameNum, int framesAmount)
Expand Down Expand Up @@ -339,7 +340,7 @@ static async Task Loop(string outPath, int looptimes)
await FfmpegCommands.LoopVideo(outPath, looptimes, Config.GetInt(Config.Key.loopMode) == 0);
}

static async Task<int> GetLoopTimes()
private static int GetLoopTimes()
{
int times = -1;
int minLength = Config.GetInt(Config.Key.minOutVidLength);
Expand Down Expand Up @@ -368,7 +369,13 @@ public static async Task MuxOutputVideo(string inputPath, string outVideo, bool

if (I.currentSettings.inputIsFrames)
{
Logger.Log("Skipping muxing from input step as there is no input video, only frames.", true);
Logger.Log("Skipping muxing additional streams from input as there is no input video, only frames.", true);
return;
}

if (I.currentMediaFile.Format.Upper() == "GIF")
{
Logger.Log("Skipping muxing additional streams from input as GIF can't have any audio or subtitles to copy", true);
return;
}

Expand All @@ -379,7 +386,7 @@ public static async Task MuxOutputVideo(string inputPath, string outVideo, bool
catch (Exception e)
{
Logger.Log("Failed to merge audio/subtitles with output video!", !showLog);
Logger.Log("MergeAudio() Exception: " + e.Message, true);
Logger.Log($"{nameof(MuxOutputVideo)} Exception: {e.Message}", true);
}
}

Expand Down

0 comments on commit 6278fed

Please sign in to comment.