This repository has been archived by the owner on Feb 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ffprober with caching, new preview method
- Loading branch information
1 parent
421ab7d
commit c9fb446
Showing
4 changed files
with
96 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Newtonsoft.Json.Linq; | ||
using System.Linq; | ||
|
||
namespace VpxEncode | ||
{ | ||
internal static class Ffprober | ||
{ | ||
public struct Result | ||
{ | ||
public string Scale; | ||
public int HeightPix, WidthPix; | ||
public string EndTime; | ||
public string Framerate; | ||
} | ||
|
||
public static Result Probe(string filePath) | ||
{ | ||
string args = $"-v quiet -print_format json -show_streams -show_format -hide_banner \"{filePath}\""; | ||
string json = Cache.Instance.Get<string>(Cache.CACHE_STRINGS, args); | ||
if (json == null) | ||
{ | ||
json = new Executer(Executer.FFPROBE).Execute(args); | ||
Cache.Instance.Put(Cache.CACHE_STRINGS, args, json); | ||
} | ||
try | ||
{ | ||
JObject root = JObject.Parse(json); | ||
var videoStream = root["streams"].Where(x => x["codec_type"].ToString() == "video").First(); | ||
return new Result() | ||
{ | ||
EndTime = root["format"]["duration"].ToString(), | ||
WidthPix = int.Parse(videoStream["width"].ToString()), | ||
HeightPix = int.Parse(videoStream["height"].ToString()), | ||
Scale = $"{videoStream["width"]}:{videoStream["height"]}", | ||
Framerate = videoStream["r_frame_rate"].ToString() | ||
}; | ||
} | ||
catch { return default(Result); } | ||
} | ||
} | ||
} |
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