├── .gitmodules
├── FFmpegDotNet
├── StreamSubtitle.cs
├── StreamCommon.cs
├── StreamAttachment.cs
├── StreamAudio.cs
├── StreamVideo.cs
├── Run.cs
├── OS.cs
├── Properties
│ └── AssemblyInfo.cs
├── FFmpegDotNet.csproj
└── FFmpeg.cs
├── .gitattributes
├── FFmpegTest
├── Properties
│ └── AssemblyInfo.cs
├── Program.cs
└── FFmpegTest.csproj
├── FFmpegDotNet.sln
├── README.md
└── .gitignore
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "Newtonsoft.Json"]
2 | path = Newtonsoft.Json
3 | url = https://github.com/JamesNK/Newtonsoft.Json
4 |
--------------------------------------------------------------------------------
/FFmpegDotNet/StreamSubtitle.cs:
--------------------------------------------------------------------------------
1 | namespace FFmpegDotNet
2 | {
3 | public class StreamSubtitle : StreamCommon
4 | {
5 |
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/FFmpegDotNet/StreamCommon.cs:
--------------------------------------------------------------------------------
1 | namespace FFmpegDotNet
2 | {
3 | public class StreamCommon
4 | {
5 | public int Id { get; internal set; }
6 | public string Language { get; internal set; }
7 | public string Codec { get; internal set; }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/FFmpegDotNet/StreamAttachment.cs:
--------------------------------------------------------------------------------
1 | namespace FFmpegDotNet
2 | {
3 | public class StreamAttachment
4 | {
5 | public int Id { get; internal set; }
6 | public string FileName { get; internal set; }
7 | public string MimeType { get; internal set; }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/FFmpegDotNet/StreamAudio.cs:
--------------------------------------------------------------------------------
1 | namespace FFmpegDotNet
2 | {
3 | public class StreamAudio : StreamCommon
4 | {
5 | public int SampleRate { get; internal set; }
6 | public int Channel { get; internal set; }
7 | public int BitDepth { get; internal set; }
8 | public float Duration { get; internal set; }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/FFmpegDotNet/StreamVideo.cs:
--------------------------------------------------------------------------------
1 | namespace FFmpegDotNet
2 | {
3 | public class StreamVideo : StreamCommon
4 | {
5 | public int Chroma { get; internal set; }
6 | public int BitDepth { get; internal set; }
7 | public int Width { get; internal set; }
8 | public int Height { get; internal set; }
9 | public bool FrameRateConstant { get; internal set; }
10 | public float FrameRate { get; internal set; }
11 | public float FrameRateAvg { get; internal set; }
12 | public int FrameCount { get; internal set; }
13 | public float Duration { get; internal set; }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/FFmpegDotNet/Run.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 |
3 | namespace FFmpegDotNet
4 | {
5 | internal class Run
6 | {
7 | internal string Output { get; set; } = string.Empty;
8 |
9 | internal Run(string FileMedia)
10 | {
11 | var p = new Process();
12 |
13 | var exe = FFmpeg.FFmpegProbe;
14 | var arg = $"-hide_banner -print_format json -show_format -show_streams \"{FileMedia}\"";
15 |
16 | if (OS.IsWindows) exe += ".exe";
17 |
18 | p.StartInfo = new ProcessStartInfo(exe, arg)
19 | {
20 | UseShellExecute = false,
21 | CreateNoWindow = true,
22 |
23 | RedirectStandardOutput = true
24 | };
25 |
26 | p.OutputDataReceived += new DataReceivedEventHandler(ConsoleStandardHandler);
27 |
28 | p.Start();
29 |
30 | p.BeginOutputReadLine();
31 |
32 | p.WaitForExit();
33 | }
34 |
35 | private void ConsoleStandardHandler(object s, DataReceivedEventArgs e)
36 | {
37 | Output += e.Data;
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/FFmpegDotNet/OS.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace FFmpegDotNet
4 | {
5 | class OS
6 | {
7 | private static int p = (int)Environment.OSVersion.Platform;
8 |
9 | ///
10 | /// Return true if this program running on Windows OS
11 | ///
12 | public static bool IsWindows
13 | {
14 | get
15 | {
16 | if (p == 2)
17 | return true;
18 | else
19 | return false;
20 | }
21 | }
22 |
23 | ///
24 | /// Return true if this program running on Linux/Unix-like OS
25 | ///
26 | public static bool IsLinux
27 | {
28 | get
29 | {
30 | if ((p == 4) || (p == 6) || (p == 128))
31 | return true;
32 | else
33 | return false;
34 | }
35 | }
36 |
37 | // Test note:
38 | // Windows 7 and 8 return 2
39 | // Ubuntu 14.04.1 return 4
40 |
41 | ///
42 | /// Return true if OS is 64bit
43 | ///
44 | public static bool Is64bit
45 | {
46 | get
47 | {
48 | return Environment.Is64BitOperatingSystem;
49 | }
50 | }
51 |
52 | ///
53 | /// Return general OS name
54 | ///
55 | public static string Name
56 | {
57 | get
58 | {
59 | if ((p == 4) || (p == 6) || (p == 128))
60 | return "Linux";
61 | return "Windows";
62 | }
63 | }
64 |
65 | ///
66 | /// Return null device by specific OS
67 | ///
68 | public static string Null
69 | {
70 | get
71 | {
72 | if (IsWindows)
73 | return "nul";
74 | else
75 | return "/dev/null";
76 | }
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/FFmpegTest/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Test FFmpegDotNet")]
9 | [assembly: AssemblyDescription("Test FFmpegDotNet")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Anime4000")]
12 | [assembly: AssemblyProduct("Internet Friendly Media Encoder")]
13 | [assembly: AssemblyCopyright("GNU GPL")]
14 | [assembly: AssemblyTrademark("Internet Friendly Media Encoder")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("fefefefe-fefe-fefe-fefe-fefefefefefe")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("0.1")]
36 | [assembly: AssemblyFileVersion("0.1")]
37 |
--------------------------------------------------------------------------------
/FFmpegDotNet/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("FFmpegDotNet")]
10 | [assembly: AssemblyDescription("FFmpeg Wrapper for .NET")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("Anime4000")]
13 | [assembly: AssemblyProduct("Internet Friendly Media Encoder")]
14 | [assembly: AssemblyCopyright("Anime4000, GNU GPL v2")]
15 | [assembly: AssemblyTrademark("Internet Friendly Media Encoder")]
16 | [assembly: AssemblyCulture("")]
17 |
18 | // Setting ComVisible to false makes the types in this assembly not visible
19 | // to COM components. If you need to access a type in this assembly from
20 | // COM, set the ComVisible attribute to true on that type.
21 | [assembly: ComVisible(false)]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 | [assembly: Guid("12312312-6666-9999-bab1-faceb00cdead")]
25 |
26 | // Version information for an assembly consists of the following four values:
27 | //
28 | // Major Version
29 | // Minor Version
30 | // Build Number
31 | // Revision
32 | //
33 | // You can specify all the values or you can default the Build and Revision Numbers
34 | // by using the '*' as shown below:
35 | // [assembly: AssemblyVersion("1.0.*")]
36 | [assembly: AssemblyVersion("8.0")]
37 | [assembly: AssemblyFileVersion("8.0")]
38 |
39 | // For Newtonsoft.Json
40 | [assembly: CLSCompliant(true)]
--------------------------------------------------------------------------------
/FFmpegDotNet.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27428.2027
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FFmpegDotNet", "FFmpegDotNet\FFmpegDotNet.csproj", "{E496AD81-7F30-492A-9E00-0EABF86F708A}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FFmpegTest", "FFmpegTest\FFmpegTest.csproj", "{31EDC313-6014-405D-82FA-8676882AC827}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Newtonsoft.Json", "..\Newtonsoft.Json\Src\Newtonsoft.Json\Newtonsoft.Json.csproj", "{BEA99FF6-9F42-42CF-A3C1-CBE606D02163}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {E496AD81-7F30-492A-9E00-0EABF86F708A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {E496AD81-7F30-492A-9E00-0EABF86F708A}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {E496AD81-7F30-492A-9E00-0EABF86F708A}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {E496AD81-7F30-492A-9E00-0EABF86F708A}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {31EDC313-6014-405D-82FA-8676882AC827}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {31EDC313-6014-405D-82FA-8676882AC827}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {31EDC313-6014-405D-82FA-8676882AC827}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {31EDC313-6014-405D-82FA-8676882AC827}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {BEA99FF6-9F42-42CF-A3C1-CBE606D02163}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {BEA99FF6-9F42-42CF-A3C1-CBE606D02163}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {BEA99FF6-9F42-42CF-A3C1-CBE606D02163}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {BEA99FF6-9F42-42CF-A3C1-CBE606D02163}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {33B61663-3A81-4654-82F6-9A3E48F89044}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/FFmpegTest/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using FFmpegDotNet;
3 |
4 | namespace FFmpegTest
5 | {
6 | class Program
7 | {
8 | static void Main(string[] args)
9 | {
10 | var info = new FFmpeg.GetInfo(@"D:\Users\Anime4000\Videos\ASDF COMP- BALLZ.mp4");
11 |
12 | string fmtName = info.FormatName;
13 | string fmtName2 = info.FormatNameFull;
14 | float time = info.Duration;
15 | ulong size = info.FileSize; // in bytes
16 | ulong bitRate = info.BitRate; // in bits
17 |
18 | Console.WriteLine($"Format: {fmtName} ({fmtName2}),\nSize: {size}bytes,\nBitrate: {bitRate}bps,\nLength: {time}sec\n");
19 |
20 | foreach (var item in info.Video)
21 | {
22 | Console.Write($"ID : {item.Id}\n");
23 | Console.Write("Type : Video\n");
24 | Console.Write($"Language : {item.Language}\n");
25 | Console.Write($"Codec : {item.Codec}\n");
26 | Console.Write($"Pixel Format : {item.Chroma}\n");
27 | Console.Write($"Bit per Colour : {item.BitDepth}\n");
28 | Console.Write($"Resolution : {item.Width}x{item.Height}\n");
29 | Console.Write($"Frame Rate : {item.FrameRate:#.##}fps\n");
30 | Console.Write($"Frame Rate Avg : {item.FrameRateAvg:#.##}fps\n");
31 | Console.Write($"Frame Rate Mode : {(item.FrameRateConstant ? "Constant" : "Variable")}\n");
32 | Console.Write($"Frame Count : {item.FrameCount} frame's\n");
33 | Console.Write($"\n");
34 | }
35 |
36 | foreach (var item in info.Audio)
37 | {
38 | Console.Write($"ID : {item.Id}\n");
39 | Console.Write("Type : Audio\n");
40 | Console.Write($"Language : {item.Language}\n");
41 | Console.Write($"Codec : {item.Codec}\n");
42 | Console.Write($"Sample Rate : {item.SampleRate}Hz\n");
43 | Console.Write($"Bit Depth : {item.BitDepth} Bit (raw)\n");
44 | Console.Write($"Channels : {item.Channel}\n");
45 | Console.Write($"\n");
46 | }
47 |
48 | foreach (var item in info.Subtitle)
49 | {
50 | Console.Write($"ID : {item.Id}\n");
51 | Console.Write("Type : Subtitle\n");
52 | Console.Write($"Language : {item.Language}\n");
53 | Console.Write($"Codec : {item.Codec}\n");
54 | Console.Write($"\n");
55 | }
56 |
57 | foreach (var item in info.Attachment)
58 | {
59 | Console.Write($"Attachment: {item.Id}, {item.FileName}, {item.MimeType}\n");
60 | }
61 |
62 | Console.Read();
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/FFmpegTest/FFmpegTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {31EDC313-6014-405D-82FA-8676882AC827}
8 | Exe
9 | Properties
10 | FFmpegTest
11 | FFmpegTest
12 | v4.0
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | {e496ad81-7f30-492a-9e00-0eabf86f708a}
50 | FFmpegDotNet
51 |
52 |
53 |
54 |
61 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FFmpegDotNet
2 | Another FFmpeg compliance which reads media properties and then forward to FFmpeg to processing like encoding, extracting and more. This mainly use for *Internet Friendly Media Encoder*
3 |
4 | ## What is difference with MediaInfo?
5 | MediaInfo is great tool to display media properties, much more details than FFmpeg it self, however I find so difficult to play with MediaInfo & FFmpeg, for example capture media properties with `MediaInfo.dll` and use that info to `FFmpeg.exe`, mostly it work just fine, until `FFmpeg` rejects because `MediaInfo` provides different what FFmpeg needs
6 |
7 | For example media index/id, some are start from `1`, some are start from `0`. MediaInfo follow actual indexing/id but FFmpeg always start from `0`. When you try mapping, FFmpeg will reject.
8 |
9 | ## Usage
10 | Using `FFmpegDotNet` very stright forward
11 |
12 | ### Capture media properties
13 | ```cs
14 | FFmpeg.FFmpegProbe = Path.Combine("ffmpeg", "64", "ffprobe"); // set binary file
15 |
16 | var info = new FFmpeg.GetInfo(@"D:\Users\Anime4000\Videos\ASDF COMP- BALLZ.mp4");
17 |
18 | string fmtName = info.FormatName;
19 | string fmtName2 = info.FormatNameFull;
20 | float time = info.Duration;
21 | ulong size = info.FileSize; // in bytes
22 | ulong bitRate = info.BitRate; // in bits
23 |
24 | Console.WriteLine($"Format: {fmtName} ({fmtName2}),\nSize: {size}bytes,\nBitrate: {bitRate}bps,\nLength: {time}sec\n");
25 |
26 | foreach (var item in info.Video)
27 | {
28 | Console.Write($"ID : {item.Id}\n");
29 | Console.Write("Type : Video\n");
30 | Console.Write($"Language : {item.Language}\n");
31 | Console.Write($"Codec : {item.Codec}\n");
32 | Console.Write($"Pixel Format : {item.Chroma}\n");
33 | Console.Write($"Bit per Colour : {item.BitDepth}\n");
34 | Console.Write($"Resolution : {item.Width}x{item.Height}\n");
35 | Console.Write($"Frame Rate : {item.FrameRate:#.##}fps\n");
36 | Console.Write($"Frame Rate Avg : {item.FrameRateAvg:#.##}fps\n");
37 | Console.Write($"Frame Rate Mode : {(item.FrameRateConstant ? "Constant" : "Variable")}\n");
38 | Console.Write($"Frame Count : {item.FrameCount} frame's\n");
39 | Console.Write($"\n");
40 | }
41 |
42 | foreach (var item in info.Audio)
43 | {
44 | Console.Write($"ID : {item.Id}\n");
45 | Console.Write("Type : Audio\n");
46 | Console.Write($"Language : {item.Language}\n");
47 | Console.Write($"Codec : {item.Codec}\n");
48 | Console.Write($"Sample Rate : {item.SampleRate}Hz\n");
49 | Console.Write($"Bit Depth : {item.BitDepth} Bit (raw)\n");
50 | Console.Write($"Channels : {item.Channel}\n");
51 | Console.Write($"\n");
52 | }
53 |
54 | foreach (var item in info.Subtitle)
55 | {
56 | Console.Write($"ID : {item.Id}\n");
57 | Console.Write("Type : Subtitle\n");
58 | Console.Write($"Language : {item.Language}\n");
59 | Console.Write($"Codec : {item.Codec}\n");
60 | Console.Write($"\n");
61 | }
62 |
63 | foreach (var item in info.Attachment)
64 | {
65 | Console.Write($"Attachment: {item.Id}, {item.FileName}, {item.MimeType}\n");
66 | }
67 |
68 | Console.Read();
69 | ```
70 |
71 | With that code, it will display like this (console)
72 | ```
73 | Format: matroska,webm (Matroska / WebM)
74 | File Size: 477782006
75 |
76 | Type: Video
77 | ID: 0
78 | Language: jpn
79 | Codec: h264
80 | Pixel Format: yuv420p
81 | Bit per Colour: 8
82 | Resolution: 1280x720
83 | Frame Rate: 23.97602fps
84 |
85 | Type: Audio
86 | ID: 1
87 | Language: eng
88 | Codec: aac
89 | Sample Rate: 48000Hz
90 | Bit Depth: 16 Bit (raw)
91 | Channels: 2
92 |
93 | Type: Audio
94 | ID: 2
95 | Language: jpn
96 | Codec: aac
97 | Sample Rate: 48000Hz
98 | Bit Depth: 16 Bit (raw)
99 | Channels: 2
100 |
101 | Type: Subtitle
102 | ID: 3
103 | Language: eng
104 | Codec: ass
105 |
106 | Type: Subtitle
107 | ID: 4
108 | Language: eng
109 | Codec: ass
110 | ```
111 |
112 | ### Processing
113 | ```cs
114 | // Extract Attachment like fonts
115 | new FFmpeg.Process().ExtractAttachment("/home/anime4000/kawaii.mp4", "/home/anime4000/fonts/");
116 |
117 | // to do: doing encoding & decoding in the future
118 | ```
119 |
120 | ## Contribute
121 | This code written in C# 7.2, so you need Visual Studio 2017
122 |
123 | ### Clone
124 | You need clone these in same root directory, so FFmpegDotNet can link
125 | ```
126 | git clone https://github.com/Anime4000/FFmpegDotNet
127 | git clone https://github.com/JamesNK/Newtonsoft.Json
128 | MSBuild
129 | ```
130 | Then you can open Visual Studio Project file
131 |
132 | To use in your project, is better to use "Add existing project" and dont forget to include Newtonsoft.Json as well
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | build/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opensdf
80 | *.sdf
81 | *.cachefile
82 |
83 | # Visual Studio profiler
84 | *.psess
85 | *.vsp
86 | *.vspx
87 | *.sap
88 |
89 | # TFS 2012 Local Workspace
90 | $tf/
91 |
92 | # Guidance Automation Toolkit
93 | *.gpState
94 |
95 | # ReSharper is a .NET coding add-in
96 | _ReSharper*/
97 | *.[Rr]e[Ss]harper
98 | *.DotSettings.user
99 |
100 | # JustCode is a .NET coding add-in
101 | .JustCode
102 |
103 | # TeamCity is a build add-in
104 | _TeamCity*
105 |
106 | # DotCover is a Code Coverage Tool
107 | *.dotCover
108 |
109 | # NCrunch
110 | _NCrunch_*
111 | .*crunch*.local.xml
112 | nCrunchTemp_*
113 |
114 | # MightyMoose
115 | *.mm.*
116 | AutoTest.Net/
117 |
118 | # Web workbench (sass)
119 | .sass-cache/
120 |
121 | # Installshield output folder
122 | [Ee]xpress/
123 |
124 | # DocProject is a documentation generator add-in
125 | DocProject/buildhelp/
126 | DocProject/Help/*.HxT
127 | DocProject/Help/*.HxC
128 | DocProject/Help/*.hhc
129 | DocProject/Help/*.hhk
130 | DocProject/Help/*.hhp
131 | DocProject/Help/Html2
132 | DocProject/Help/html
133 |
134 | # Click-Once directory
135 | publish/
136 |
137 | # Publish Web Output
138 | *.[Pp]ublish.xml
139 | *.azurePubxml
140 | # TODO: Comment the next line if you want to checkin your web deploy settings
141 | # but database connection strings (with potential passwords) will be unencrypted
142 | *.pubxml
143 | *.publishproj
144 |
145 | # NuGet Packages
146 | *.nupkg
147 | # The packages folder can be ignored because of Package Restore
148 | **/packages/*
149 | # except build/, which is used as an MSBuild target.
150 | !**/packages/build/
151 | # Uncomment if necessary however generally it will be regenerated when needed
152 | #!**/packages/repositories.config
153 |
154 | # Windows Azure Build Output
155 | csx/
156 | *.build.csdef
157 |
158 | # Windows Azure Emulator
159 | efc/
160 | rfc/
161 |
162 | # Windows Store app package directory
163 | AppPackages/
164 |
165 | # Visual Studio cache files
166 | # files ending in .cache can be ignored
167 | *.[Cc]ache
168 | # but keep track of directories ending in .cache
169 | !*.[Cc]ache/
170 |
171 | # Others
172 | ClientBin/
173 | [Ss]tyle[Cc]op.*
174 | ~$*
175 | *~
176 | *.dbmdl
177 | *.dbproj.schemaview
178 | *.pfx
179 | *.publishsettings
180 | node_modules/
181 | orleans.codegen.cs
182 |
183 | # RIA/Silverlight projects
184 | Generated_Code/
185 |
186 | # Backup & report files from converting an old project file
187 | # to a newer Visual Studio version. Backup files are not needed,
188 | # because we have git ;-)
189 | _UpgradeReport_Files/
190 | Backup*/
191 | UpgradeLog*.XML
192 | UpgradeLog*.htm
193 |
194 | # SQL Server files
195 | *.mdf
196 | *.ldf
197 |
198 | # Business Intelligence projects
199 | *.rdl.data
200 | *.bim.layout
201 | *.bim_*.settings
202 |
203 | # Microsoft Fakes
204 | FakesAssemblies/
205 |
206 | # GhostDoc plugin setting file
207 | *.GhostDoc.xml
208 |
209 | # Node.js Tools for Visual Studio
210 | .ntvs_analysis.dat
211 |
212 | # Visual Studio 6 build log
213 | *.plg
214 |
215 | # Visual Studio 6 workspace options file
216 | *.opt
217 |
218 | # Visual Studio LightSwitch build output
219 | **/*.HTMLClient/GeneratedArtifacts
220 | **/*.DesktopClient/GeneratedArtifacts
221 | **/*.DesktopClient/ModelManifest.xml
222 | **/*.Server/GeneratedArtifacts
223 | **/*.Server/ModelManifest.xml
224 | _Pvt_Extensions
225 |
226 | # Paket dependency manager
227 | .paket/paket.exe
228 |
229 | # FAKE - F# Make
230 | .fake/
231 |
232 | # =========================
233 | # Operating System Files
234 | # =========================
235 |
236 | # OSX
237 | # =========================
238 |
239 | .DS_Store
240 | .AppleDouble
241 | .LSOverride
242 |
243 | # Thumbnails
244 | ._*
245 |
246 | # Files that might appear in the root of a volume
247 | .DocumentRevisions-V100
248 | .fseventsd
249 | .Spotlight-V100
250 | .TemporaryItems
251 | .Trashes
252 | .VolumeIcon.icns
253 |
254 | # Directories potentially created on remote AFP share
255 | .AppleDB
256 | .AppleDesktop
257 | Network Trash Folder
258 | Temporary Items
259 | .apdisk
260 |
261 | # Windows
262 | # =========================
263 |
264 | # Windows image file caches
265 | Thumbs.db
266 | ehthumbs.db
267 |
268 | # Folder config file
269 | Desktop.ini
270 |
271 | # Recycle Bin used on file shares
272 | $RECYCLE.BIN/
273 |
274 | # Windows Installer files
275 | *.cab
276 | *.msi
277 | *.msm
278 | *.msp
279 |
280 | # Windows shortcuts
281 | *.lnk
282 |
--------------------------------------------------------------------------------
/FFmpegDotNet/FFmpegDotNet.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {E496AD81-7F30-492A-9E00-0EABF86F708A}
8 | Library
9 | Properties
10 | FFmpegDotNet
11 | FFmpegDotNet
12 | v4.0
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | TRACE;DEBUG;NET40;HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_BIG_INTEGER;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_CAS;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_REFLECTION_EMIT;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;HAVE_CONCURRENT_DICTIONARY
22 | prompt
23 | 4
24 | 7.2
25 | false
26 |
27 |
28 |
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE;NET40;HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_BIG_INTEGER;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_CAS;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_REFLECTION_EMIT;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;HAVE_CONCURRENT_DICTIONARY
33 | prompt
34 | 4
35 | false
36 |
37 | 7.2
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | {bea99ff6-9f42-42cf-a3c1-cbe606d02163}
67 | Newtonsoft.Json
68 |
69 |
70 |
71 |
78 |
--------------------------------------------------------------------------------
/FFmpegDotNet/FFmpeg.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Collections.Generic;
4 | using System.Text.RegularExpressions;
5 |
6 | using Newtonsoft.Json;
7 |
8 | namespace FFmpegDotNet
9 | {
10 | public class FFmpeg
11 | {
12 | private static StringComparison IgnoreCase { get { return StringComparison.InvariantCultureIgnoreCase; } }
13 |
14 | public static string FFmpegProbe { get; set; } = Path.Combine("ffmpeg", "64", "ffprobe");
15 |
16 | public class GetInfo
17 | {
18 | public GetInfo(string FileMedia)
19 | {
20 | dynamic json = JsonConvert.DeserializeObject(new Run(FileMedia).Output);
21 |
22 | // General info
23 | FilePath = json.format.filename;
24 | FileSize = json.format.size;
25 | BitRate = json.format.bit_rate;
26 | Duration = json.format.duration;
27 | FormatName = json.format.format_name;
28 | FormatNameFull = json.format.format_long_name;
29 |
30 | // Capture stream type
31 | foreach (var stream in json.streams)
32 | {
33 | string type = stream.codec_type;
34 |
35 | if (string.Equals(type, "video", IgnoreCase))
36 | {
37 | string r = stream.r_frame_rate;
38 | float.TryParse(r.Split('/')[0], out float rn);
39 | float.TryParse(r.Split('/')[1], out float rd);
40 | float rfps = rn / rd;
41 |
42 | string a = stream.avg_frame_rate;
43 | float.TryParse(a.Split('/')[0], out float an);
44 | float.TryParse(a.Split('/')[1], out float ad);
45 | float afps = an / ad;
46 |
47 | int pix = 420;
48 | if (!string.IsNullOrEmpty((string)stream.pix_fmt))
49 | {
50 | var mpix = Regex.Match((string)stream.pix_fmt, @"yuv(\d+)");
51 |
52 | if (mpix.Success) int.TryParse(mpix.Groups[1].Value, out pix);
53 | else pix = 420;
54 | }
55 |
56 | int bpc = stream.bits_per_raw_sample;
57 | if (bpc == 0)
58 | {
59 | var mbpc = Regex.Match((string)stream.pix_fmt, @"yuv\d+p(\d+)");
60 |
61 | if (mbpc.Success) int.TryParse(mbpc.Groups[1].Value, out bpc);
62 | else bpc = 8;
63 | }
64 |
65 | string lang = stream.tags.language;
66 | if (string.IsNullOrEmpty(lang)) lang = "und";
67 |
68 | Video.Add(new StreamVideo
69 | {
70 | Id = stream.index,
71 | Language = lang,
72 | Codec = stream.codec_name,
73 | Chroma = pix,
74 | BitDepth = stream.bits_per_raw_sample,
75 | Width = stream.width,
76 | Height = stream.height,
77 | FrameRateConstant = rfps == afps,
78 | FrameRate = rfps,
79 | FrameRateAvg = afps,
80 | FrameCount = (int)(Duration * afps),
81 | Duration = Duration,
82 | });
83 | }
84 |
85 | if (string.Equals(type, "audio", IgnoreCase))
86 | {
87 | int.TryParse((string)stream.sample_rate, out int sample);
88 | int.TryParse((string)stream.sample_fmt, out int bitdepth);
89 | int.TryParse((string)stream.channels, out int channel);
90 |
91 | if (bitdepth == 0) bitdepth = 16;
92 | else if (bitdepth >= 32) bitdepth = 24;
93 |
94 | string lang = stream.tags.language;
95 | if (string.IsNullOrEmpty(lang)) lang = "und";
96 |
97 | Audio.Add(new StreamAudio
98 | {
99 | Id = stream.index,
100 | Language = lang,
101 | Codec = stream.codec_name,
102 | SampleRate = sample,
103 | BitDepth = bitdepth,
104 | Channel = channel,
105 | Duration = Duration,
106 | });
107 | }
108 |
109 | if (string.Equals(type, "subtitle", IgnoreCase))
110 | {
111 | string lang = stream.tags.language;
112 | if (string.IsNullOrEmpty(lang)) lang = "und";
113 |
114 | Subtitle.Add(new StreamSubtitle
115 | {
116 | Id = stream.index,
117 | Language = lang,
118 | Codec = stream.codec_name,
119 | });
120 | }
121 |
122 | if (string.Equals(type, "attachment", IgnoreCase))
123 | {
124 | Attachment.Add(new StreamAttachment
125 | {
126 | Id = stream.index,
127 | FileName = stream.tags.filename,
128 | MimeType = stream.tags.mimetype
129 | });
130 | }
131 | }
132 | }
133 |
134 | public string FilePath { get; internal set; } = string.Empty;
135 | #pragma warning disable CS3003 // Type is not CLS-compliant
136 | public ulong FileSize { get; internal set; } = 0;
137 | public ulong BitRate { get; internal set; } = 0;
138 | #pragma warning restore CS3003 // Type is not CLS-compliant
139 | public float Duration { get; internal set; } = 0;
140 | public string FormatName { get; internal set; } = "NEW";
141 | public string FormatNameFull { get; internal set; } = "Blank media";
142 |
143 | public List Video { get; internal set; } = new List();
144 | public List Audio { get; internal set; } = new List();
145 | public List Subtitle { get; internal set; } = new List();
146 | public List Attachment { get; internal set; } = new List();
147 | }
148 | }
149 | }
--------------------------------------------------------------------------------