Skip to content

Commit 6fce07f

Browse files
authored
Update README.md
1 parent 46010a8 commit 6fce07f

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Currently, only a Windows environment with Visual Studio is supported. This is s
2020

2121
There are multiple demo projects included in the solution. Check out the demo-project for a thorough exploration of the features (demuxing, decoding, filtering, encoding, muxing) or one of the other examples for a simpler example to follow.
2222

23+
There is also a .NET Core compatible simplified interface included so that you can embed this project in your .NET Core projects.
24+
25+
## C++
26+
2327
To give you an idea, this code will load a video stream from a container, filter it, and write it back out to another container:
2428

2529
```C++
@@ -56,6 +60,90 @@ muxer->Close();
5660

5761
```
5862
63+
If you use the included simple-interface library, which only supports a subset of the full library, using ffmpeg-cpp becomes even easier:
64+
65+
```
66+
#include "SimpleInterface.h"
67+
68+
int main()
69+
{
70+
void* handle = ffmpegCppCreate("out.mp4");
71+
ffmpegCppAddVideoStream(handle, "samples/big_buck_bunny.mp4");
72+
ffmpegCppAddVideoFilter(handle, "transpose=cclock[middle];[middle]vignette");
73+
ffmpegCppAddAudioStream(handle, "samples/big_buck_bunny.mp4");
74+
ffmpegCppGenerate(handle);
75+
ffmpegCppClose(handle);
76+
}
77+
´´´
78+
79+
## C#
80+
81+
The simple-interface is made in such a way that it can easily be called using [DllImport] from any C# project:
82+
83+
```
84+
public class Example
85+
{
86+
87+
public Example()
88+
{
89+
try
90+
{
91+
string inFileName = "in.mp4";
92+
string outFileName = "out.mp4";
93+
IntPtr handle = ffmpegCppCreate(outFileName); CheckError(handle);
94+
ffmpegCppAddVideoStream(handle, inFileName); CheckError(handle);
95+
ffmpegCppAddAudioStream(handle, inFileName); CheckError(handle);
96+
ffmpegCppAddVideoFilter(handle, "crop=1080:1920:740:0[middle];[middle]transpose=3"); CheckError(handle);
97+
ffmpegCppGenerate(handle); CheckError(handle);
98+
ffmpegCppClose(handle);
99+
}
100+
catch (InvalidOperationException e)
101+
{
102+
Console.WriteLine("ERROR: " + e.Message);
103+
}
104+
}
105+
106+
private void CheckError(IntPtr handle)
107+
{
108+
if (ffmpegCppIsError(handle))
109+
{
110+
IntPtr errorPtr = ffmpegCppGetError(handle);
111+
string error = Marshal.PtrToStringAnsi(errorPtr);
112+
throw new InvalidOperationException(error);
113+
}
114+
}
115+
116+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
117+
private static extern IntPtr ffmpegCppCreate(string outFileName);
118+
119+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
120+
private static extern void ffmpegCppAddVideoStream(IntPtr handle, [MarshalAs(UnmanagedType.LPStr)] string inFileName);
121+
122+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
123+
private static extern void ffmpegCppAddAudioStream(IntPtr handle, [MarshalAs(UnmanagedType.LPStr)] string inFileName);
124+
125+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
126+
private static extern void ffmpegCppAddVideoFilter(IntPtr handle, [MarshalAs(UnmanagedType.LPStr)] string filterString);
127+
128+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
129+
private static extern void ffmpegCppAddAudioFilter(IntPtr handle, [MarshalAs(UnmanagedType.LPStr)] string filterString);
130+
131+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
132+
private static extern void ffmpegCppGenerate(IntPtr handle);
133+
134+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
135+
private static extern bool ffmpegCppIsError(IntPtr handle);
136+
137+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
138+
private static extern IntPtr ffmpegCppGetError(IntPtr handle);
139+
140+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
141+
private static extern void ffmpegCppClose(IntPtr handle);
142+
}
143+
´´´
144+
145+
If you want to use ffmpeg-cpp in a C# project, you can easily do so by making your own C-wrapper around the
146+
59147
# Why?
60148
61149
I developed this project to be able to to integrate FFmpeg into our program without having to call the executable to do an operation. This is important because starting up an external executable tends to be blocked by antivirus software and can cause issues with users. It has been tested for the most common functionality, and some of the examples from https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples are mirrored in the project as well.

0 commit comments

Comments
 (0)