mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Updated BaseMediaHandler to output the ffmpeg log to our log directory. Made more progress on VideoHandler.
This commit is contained in:
parent
bae04374e5
commit
3bb0ae0f13
@ -5,6 +5,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Logging;
|
using MediaBrowser.Common.Logging;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Common.Net.Handlers;
|
using MediaBrowser.Common.Net.Handlers;
|
||||||
@ -241,16 +242,26 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
Process process = new Process();
|
Process process = new Process();
|
||||||
process.StartInfo = startInfo;
|
process.StartInfo = startInfo;
|
||||||
|
|
||||||
|
// FFMpeg writes debug info to StdErr. This is useful when debugging so let's put it in the log directory.
|
||||||
|
FileStream logStream = new FileStream(Path.Combine(ApplicationPaths.LogDirectoryPath, "ffmpeg-" + Guid.NewGuid().ToString() + ".txt"), FileMode.Create);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
process.Start();
|
process.Start();
|
||||||
|
|
||||||
// MUST read both stdout and stderr asynchronously or a deadlock may occurr
|
// MUST read both stdout and stderr asynchronously or a deadlock may occurr
|
||||||
process.BeginErrorReadLine();
|
// If we ever decide to disable the ffmpeg log then you must uncomment the below line.
|
||||||
|
//process.BeginErrorReadLine();
|
||||||
|
|
||||||
|
Task errorTask = Task.Run(async () => { await process.StandardError.BaseStream.CopyToAsync(logStream); });
|
||||||
|
|
||||||
await process.StandardOutput.BaseStream.CopyToAsync(stream);
|
await process.StandardOutput.BaseStream.CopyToAsync(stream);
|
||||||
|
|
||||||
process.WaitForExit();
|
process.WaitForExit();
|
||||||
|
|
||||||
|
await errorTask;
|
||||||
|
|
||||||
|
Logger.LogInfo("FFMpeg exited with code " + process.ExitCode);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -258,6 +269,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
logStream.Dispose();
|
||||||
process.Dispose();
|
process.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,21 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetFFMpegOutputFormat(string outputFormat)
|
||||||
|
{
|
||||||
|
if (outputFormat.Equals("mkv", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return "matroska";
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int GetOutputAudioStreamIndex(string outputFormat)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates arguments to pass to ffmpeg
|
/// Creates arguments to pass to ffmpeg
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -62,8 +77,61 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
List<string> audioTranscodeParams = new List<string>();
|
List<string> audioTranscodeParams = new List<string>();
|
||||||
|
|
||||||
string outputFormat = GetOutputFormat();
|
string outputFormat = GetOutputFormat();
|
||||||
outputFormat = "matroska";
|
|
||||||
return "-i \"" + LibraryItem.Path + "\" -vcodec copy -acodec copy -f " + outputFormat + " -";
|
int audioStreamIndex = GetOutputAudioStreamIndex(outputFormat);
|
||||||
|
|
||||||
|
List<string> maps = new List<string>();
|
||||||
|
|
||||||
|
// Add the video stream
|
||||||
|
maps.Add("-map 0:0");
|
||||||
|
|
||||||
|
// Add the audio stream
|
||||||
|
if (audioStreamIndex != -1)
|
||||||
|
{
|
||||||
|
maps.Add("-map 0:" + (1 + audioStreamIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add all the subtitle streams
|
||||||
|
for (int i = 0; i < LibraryItem.Subtitles.Count(); i++)
|
||||||
|
{
|
||||||
|
maps.Add("-map 0:" + (1 + LibraryItem.AudioStreams.Count() + i));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Format("-i \"{0}\" {1} {2} {3} -f {4} -",
|
||||||
|
LibraryItem.Path,
|
||||||
|
string.Join(" ", maps.ToArray()),
|
||||||
|
GetVideoArguments(),
|
||||||
|
GetAudioArguments(),
|
||||||
|
GetFFMpegOutputFormat(outputFormat)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetVideoArguments()
|
||||||
|
{
|
||||||
|
return "-c:v copy";
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetAudioArguments()
|
||||||
|
{
|
||||||
|
return "-c:a copy";
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetSubtitleArguments()
|
||||||
|
{
|
||||||
|
string args = "";
|
||||||
|
|
||||||
|
for (int i = 0; i < LibraryItem.Subtitles.Count(); i++)
|
||||||
|
{
|
||||||
|
if (i > 0)
|
||||||
|
{
|
||||||
|
args += " ";
|
||||||
|
}
|
||||||
|
args += "-c:s copy";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return args;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user