Skip to content

Commit

Permalink
FFMpeg path configuration removed. (Must be in the path variable now)…
Browse files Browse the repository at this point in the history
… Json settings for core tests.
  • Loading branch information
git authored and git committed Dec 10, 2019
1 parent 4dcd5e4 commit 29f8e81
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 42 deletions.
4 changes: 2 additions & 2 deletions IDBrowserServiceCore/Code/StaticFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public static void Resize(MagickImage image, int width, int height)
}
}

public async static Task<string> TranscodeVideo(string filePath, string guid, string transcodeDirectory, string ffmpegPath, string videosize)
public async static Task<string> TranscodeVideo(string filePath, string guid, string transcodeDirectory, string videosize)
{
string strTranscodeDirectory = Path.Combine(transcodeDirectory, videosize, guid.Substring(0, 2));
string strTranscodeFilePath = Path.Combine(strTranscodeDirectory, guid + ".mp4");
Expand All @@ -208,7 +208,7 @@ public async static Task<string> TranscodeVideo(string filePath, string guid, st
VideoSize = videoSize
};

var ffmpeg = new Engine(ffmpegPath);
var ffmpeg = new Engine();
await ffmpeg.ConvertAsync(inputFile, outputFile, conversionOptions);
}

Expand Down
10 changes: 2 additions & 8 deletions IDBrowserServiceCore/Controllers/MediaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,15 @@ public class MediaController : Controller
private readonly IDImagerDB db;
private readonly ILogger<ValuesController> logger;
private readonly IDiagnosticContext diagnosticContext;
private readonly IConfiguration configuration;
private readonly ServiceSettings serviceSettings;

private readonly string ffmpegPath;

public MediaController(IDImagerDB db, IConfiguration configuration, IOptions<ServiceSettings> serviceSettings,
public MediaController(IDImagerDB db, IOptions<ServiceSettings> serviceSettings,
ILogger<ValuesController> logger, IDiagnosticContext diagnosticContext)
{
this.db = db ?? throw new ArgumentNullException(nameof(logger));
this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
this.serviceSettings = serviceSettings.Value ?? throw new ArgumentNullException(nameof(serviceSettings));
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
this.diagnosticContext = diagnosticContext ?? throw new ArgumentNullException(nameof(diagnosticContext));

this.ffmpegPath = configuration.GetValue<string>("FFMpegPath");
}

[HttpGet]
Expand All @@ -68,7 +62,7 @@ public async Task<IActionResult> Play(string guid, string videosize)
return BadRequest("Missing TranscodeDirectory setting");

string strTranscodeFilePath = await StaticFunctions.TranscodeVideo(strFilePath, guid,
serviceSettings.TranscodeDirectory, ffmpegPath, videosize);
serviceSettings.TranscodeDirectory, videosize);

strFilePath = strTranscodeFilePath;
mimeType = "video/mp4";
Expand Down
5 changes: 2 additions & 3 deletions IDBrowserServiceCore/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"FFMpegPath": "D:\\Temp\\Transcode\\ffmpeg.exe",
"Sites": {
"mad": {
"ServiceSettings": {
Expand All @@ -9,7 +8,7 @@
"PathReplace": "\\\\172.17.2.14\\Multimedia"
}
],
"TranscodeDirectory": "\\\\QNAPNAS01\\Multimedia\\VideoTranscode\\mad"
"TranscodeDirectory": "D:\\Temp\\Transcode\\mad"
}
},
"maw": {
Expand All @@ -20,7 +19,7 @@
"PathReplace": "\\\\172.17.2.14\\Multimedia"
}
],
"TranscodeDirectory": "\\\\QNAPNAS01\\Multimedia\\VideoTranscode\\maw"
"TranscodeDirectory": "D:\\Temp\\Transcode\\maw"
}
}
},
Expand Down
1 change: 0 additions & 1 deletion IDBrowserServiceCore/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"urls": "http://172.17.2.17:5000",
"FFMpegPath": "/usr/bin/ffmpeg",
"Sites": {
"mad": {
"ConnectionStrings": {
Expand Down
5 changes: 0 additions & 5 deletions IDBrowserServiceCoreTest/IDBrowserServiceCoreTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<None Remove="appsettings.Development.json" />
<None Remove="appsettings.json" />
</ItemGroup>

<ItemGroup>
<Content Include="appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
10 changes: 10 additions & 0 deletions IDBrowserServiceCoreTest/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"IDBrowserServiceCoreTest": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
67 changes: 49 additions & 18 deletions IDBrowserServiceCoreTest/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,52 @@ public UnitTest1()
}
}

private IConfiguration configuration;
public IConfiguration Configuration
{
get
{
if (configuration == null)
{
configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
}

return configuration;
}
}

private IConfigurationSection settingsSection;
public IConfigurationSection SettingsSection
{
get
{
if (settingsSection == null)
{
settingsSection = Configuration
.GetSection("Sites")
.GetChildren()
.First()
.GetSection("ServiceSettings");
}

return settingsSection;
}
}

private ServiceSettings settings;
public ServiceSettings Settings
{
get
{
if (settings == null)
{
settings = new ServiceSettings()
{
CreateThumbnails = true,
MThumbmailWidth = 1680,
MThumbnailHeight = 1260,
KeepAspectRatio = true,
SetGenericVideoThumbnailOnError = true,
};

FilePathReplaceSettings filePathReplaceSettings = new FilePathReplaceSettings()
{
PathMatch = "\\\\QNAPNAS01\\Multimedia",
PathReplace = "\\\\172.17.2.14\\Multimedia"
};

settings.FilePathReplace.Add(filePathReplaceSettings);
settings = new ServiceSettings();
SettingsSection.Bind(settings);
}

return settings;
Expand Down Expand Up @@ -204,13 +227,12 @@ public ServiceProvider ServiceProvider
.ReplaceService<ISqlGenerationHelper, PostgresSqlGenerationHelper>())
.AddDbContextPool<IDImagerThumbsDB>(options => options.UseNpgsql(DbThumbsConnectionString)
.ReplaceService<ISqlGenerationHelper, PostgresSqlGenerationHelper>())
.AddSingleton<IOptions<ServiceSettings>>(Options.Create<ServiceSettings>(Settings))
.Configure<ServiceSettings>(SettingsSection)
.AddSingleton<ILoggerFactory>(services => new SerilogLoggerFactory(Logger, false))
.AddSingleton<ILogger<ValuesController>>(loggerFactory.CreateLogger<ValuesController>())
.AddSingleton<ILogger<MediaController>>(loggerFactory.CreateLogger<MediaController>())
.AddSingleton(diagnosticContext)
.AddSingleton<IDiagnosticContext>(diagnosticContext)
.AddSingleton<IConfiguration>(Configuration)
.AddTransient<ValuesController, ValuesController>()
.AddTransient<MediaController, MediaController>();

Expand Down Expand Up @@ -388,5 +410,14 @@ public async void MediaControllerPlayTest()
else
stream.FileStream.Close();
}

[Fact]
public async void MediaControllerPlayTranscodeTest()
{
if (!(await MediaController.Play(idCatalogItemFirstVideo.GUID, "Hd480") is FileStreamResult stream))
throw new Exception("No stream received");
else
stream.FileStream.Close();
}
}
}
5 changes: 2 additions & 3 deletions IDBrowserServiceCoreTest/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"FFMpegPath": "D:\\Temp\\Transcode\\ffmpeg.exe",
"Sites": {
"mad": {
"ServiceSettings": {
Expand All @@ -9,7 +8,7 @@
"PathReplace": "\\\\172.17.2.14\\Multimedia"
}
],
"TranscodeDirectory": "\\\\QNAPNAS01\\Multimedia\\VideoTranscode\\mad"
"TranscodeDirectory": "D:\\Temp\\Transcode\\mad"
}
},
"maw": {
Expand All @@ -20,7 +19,7 @@
"PathReplace": "\\\\172.17.2.14\\Multimedia"
}
],
"TranscodeDirectory": "\\\\QNAPNAS01\\Multimedia\\VideoTranscode\\maw"
"TranscodeDirectory": "D:\\Temp\\Transcode\\maw"
}
}
},
Expand Down
1 change: 0 additions & 1 deletion IDBrowserServiceCoreTest/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"urls": "http://172.17.2.17:5000",
"FFMpegPath": "/usr/bin/ffmpeg",
"Sites": {
"mad": {
"ConnectionStrings": {
Expand Down
2 changes: 1 addition & 1 deletion ManagementConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static void Main(string[] args)
{
String strFilePath = StaticFunctions.GetImageFilePath(catalogItem, null);
string strTranscodedFile = StaticFunctions.TranscodeVideo(strFilePath, catalogItem.GUID,
strTranscodeDirectory, null, strVideoSize).Result;
strTranscodeDirectory, strVideoSize).Result;

intCounter++;

Expand Down

0 comments on commit 29f8e81

Please sign in to comment.