Skip to content

Commit 07503c7

Browse files
committed
Merge branch 'master' of https://github.com/Raveler/ffmpeg-cpp
2 parents 3d40b6f + bd6c406 commit 07503c7

File tree

1 file changed

+89
-3
lines changed

1 file changed

+89
-3
lines changed

README.md

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ffmpeg-cpp
2-
A clean C++ wrapper around the ffmpeg libraries. Makes the most commonly used functionality of FFmpeg easily available for any C++ projects with an easy-to-use interface. The full power of FFmpeg compacted in 10 lines of C++ code: if this sounds useful to you, read on!
2+
A clean C++ wrapper around the ffmpeg libraries which can be used in any C++ project or C# project (with DllImport or CLR). Makes the most commonly used functionality of FFmpeg easily available for any C++ projects with an easy-to-use interface. The full power of FFmpeg compacted in 10 lines of C++ code: if this sounds useful to you, read on!
33

44
# Installation
55

@@ -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++
@@ -53,22 +57,104 @@ while (!demuxer->IsDone())
5357

5458
// Save everything to disk by closing the muxer.
5559
muxer->Close();
60+
```
61+
62+
If you use the included simple-interface library, which only supports a subset of the full library, using ffmpeg-cpp becomes even easier:
63+
64+
```
65+
#include "SimpleInterface.h"
66+
67+
int main()
68+
{
69+
void* handle = ffmpegCppCreate("out.mp4");
70+
ffmpegCppAddVideoStream(handle, "samples/big_buck_bunny.mp4");
71+
ffmpegCppAddVideoFilter(handle, "transpose=cclock[middle];[middle]vignette");
72+
ffmpegCppAddAudioStream(handle, "samples/big_buck_bunny.mp4");
73+
ffmpegCppGenerate(handle);
74+
ffmpegCppClose(handle);
75+
}
76+
```
77+
78+
## C\#
5679
80+
The simple-interface is made in such a way that it can easily be called using [DllImport] from any C# project:
81+
82+
```
83+
public class Example
84+
{
85+
86+
public Example()
87+
{
88+
try
89+
{
90+
string inFileName = "in.mp4";
91+
string outFileName = "out.mp4";
92+
IntPtr handle = ffmpegCppCreate(outFileName); CheckError(handle);
93+
ffmpegCppAddVideoStream(handle, inFileName); CheckError(handle);
94+
ffmpegCppAddAudioStream(handle, inFileName); CheckError(handle);
95+
ffmpegCppAddVideoFilter(handle, "crop=1080:1920:740:0[middle];[middle]transpose=3"); CheckError(handle);
96+
ffmpegCppGenerate(handle); CheckError(handle);
97+
ffmpegCppClose(handle);
98+
}
99+
catch (InvalidOperationException e)
100+
{
101+
Console.WriteLine("ERROR: " + e.Message);
102+
}
103+
}
104+
105+
private void CheckError(IntPtr handle)
106+
{
107+
if (ffmpegCppIsError(handle))
108+
{
109+
IntPtr errorPtr = ffmpegCppGetError(handle);
110+
string error = Marshal.PtrToStringAnsi(errorPtr);
111+
throw new InvalidOperationException(error);
112+
}
113+
}
114+
115+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
116+
private static extern IntPtr ffmpegCppCreate(string outFileName);
117+
118+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
119+
private static extern void ffmpegCppAddVideoStream(IntPtr handle, [MarshalAs(UnmanagedType.LPStr)] string inFileName);
120+
121+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
122+
private static extern void ffmpegCppAddAudioStream(IntPtr handle, [MarshalAs(UnmanagedType.LPStr)] string inFileName);
123+
124+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
125+
private static extern void ffmpegCppAddVideoFilter(IntPtr handle, [MarshalAs(UnmanagedType.LPStr)] string filterString);
126+
127+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
128+
private static extern void ffmpegCppAddAudioFilter(IntPtr handle, [MarshalAs(UnmanagedType.LPStr)] string filterString);
129+
130+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
131+
private static extern void ffmpegCppGenerate(IntPtr handle);
132+
133+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
134+
private static extern bool ffmpegCppIsError(IntPtr handle);
135+
136+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
137+
private static extern IntPtr ffmpegCppGetError(IntPtr handle);
138+
139+
[DllImport("simple_interface.dll", CallingConvention = CallingConvention.Cdecl)]
140+
private static extern void ffmpegCppClose(IntPtr handle);
141+
}
57142
```
58143
144+
If you want to use ffmpeg-cpp in a C# project, you can easily do so by making your own C-wrapper around the
145+
59146
# Why?
60147
61148
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.
62149
63150
# Roadmap
64151
65152
- Add Linux/Mac build support
66-
- Audio filtering
67153
- Adding proper unit tests
68154
- Testing with more codecs, containers
69155
70156
# License
71157
72158
This library is licensed under LGPL (https://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License).
73159
74-
Please note though that FFmpeg, which you will need to build this library, is not. Depending on how you build it, it is either LGPL or GPL. So once you use the LGPL-version of FFmpeg in your project, this library will be GPL too.
160+
Please note though that FFmpeg, which you will need to build this library, is not. Depending on how you build it, it is either LGPL or GPL. So if you use the GPL-version of FFmpeg in your project, this library will be GPL too.

0 commit comments

Comments
 (0)