Skip to content
Snippets Groups Projects
Commit bfaa98a4 authored by Anduin Xue's avatar Anduin Xue
Browse files

Add logging.

parent 23b2014f
No related branches found
No related tags found
No related merge requests found
using Aiursoft.Parser.Core; using Aiursoft.Parser.Core;
using Aiursoft.Parser.FFmpeg.Services; using Aiursoft.Parser.FFmpeg.Services;
using Microsoft.Extensions.Logging;
namespace Aiursoft.Parser.FFmpeg namespace Aiursoft.Parser.FFmpeg
{ {
public class FFmpegEntry : IEntryService public class FFmpegEntry : IEntryService
{ {
private readonly ILogger<FFmpegEntry> _logger;
private readonly FFmpegOptions _options; private readonly FFmpegOptions _options;
private readonly CommandService _commandService; private readonly CommandService _commandService;
public FFmpegEntry( public FFmpegEntry(
ILogger<FFmpegEntry> logger,
FFmpegOptions options, FFmpegOptions options,
CommandService commandService) CommandService commandService)
{ {
_logger = logger;
_options = options; _options = options;
_commandService = commandService; _commandService = commandService;
} }
public async Task OnServiceStartedAsync(string path, bool shouldTakeAction) public async Task OnServiceStartedAsync(string path, bool shouldTakeAction)
{ {
_logger.LogTrace("Enumerating files under path: " + path);
var videos = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories) var videos = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories)
.Where(v => .Where(v =>
v.EndsWith(".webm") || v.EndsWith(".webm") ||
...@@ -28,6 +33,7 @@ namespace Aiursoft.Parser.FFmpeg ...@@ -28,6 +33,7 @@ namespace Aiursoft.Parser.FFmpeg
foreach (var file in videos) foreach (var file in videos)
{ {
_logger.LogTrace("Parsing video file: " + file);
await Parse(file, coder: _options.UseGPU ? "hevc_nvenc" : "libx265"); await Parse(file, coder: _options.UseGPU ? "hevc_nvenc" : "libx265");
} }
} }
...@@ -46,7 +52,7 @@ namespace Aiursoft.Parser.FFmpeg ...@@ -46,7 +52,7 @@ namespace Aiursoft.Parser.FFmpeg
var newFileName = $"{fileInfo.Directory}{Path.DirectorySeparatorChar}{bareName}_265.mp4"; var newFileName = $"{fileInfo.Directory}{Path.DirectorySeparatorChar}{bareName}_265.mp4";
if (shouldParse) if (shouldParse)
{ {
Console.WriteLine($"{filePath} WILL be parsed!"); _logger.LogWarning($"{filePath} WILL be parsed, with codec: {coder}, crf is {_options.CRF}");
File.Delete(newFileName); File.Delete(newFileName);
await _commandService.RunCommand("ffmpeg", $@"-i ""{filePath}"" -codec:a copy -codec:v {coder} -crf {_options.CRF} ""{newFileName}""", folder, getOutput: false); await _commandService.RunCommand("ffmpeg", $@"-i ""{filePath}"" -codec:a copy -codec:v {coder} -crf {_options.CRF} ""{newFileName}""", folder, getOutput: false);
...@@ -63,7 +69,7 @@ namespace Aiursoft.Parser.FFmpeg ...@@ -63,7 +69,7 @@ namespace Aiursoft.Parser.FFmpeg
} }
else else
{ {
Console.WriteLine($"{filePath} don't have to be parsed..."); _logger.LogInformation($"{filePath} don't have to be parsed...");
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment