Skip to content

Commit 5ea6ff4

Browse files
committed
added support for multiple inputs to filters, added an example to demonstrate this
1 parent f80984a commit 5ea6ff4

38 files changed

+889
-120
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
/include
2323

2424
/source/ffmpeg-cpp/remuxing/obj
25+
/source/ffmpeg-cpp/difference/obj/x64/Debug

samples/out.mp4

-1.92 MB
Binary file not shown.

source/ffmpeg-cpp/decode_audio/decode_audio.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using namespace std;
77
using namespace ffmpegcpp;
88

9-
class RawAudioFileSink : public AudioFrameSink
9+
class RawAudioFileSink : public AudioFrameSink, public FrameWriter
1010
{
1111
public:
1212

@@ -15,7 +15,13 @@ class RawAudioFileSink : public AudioFrameSink
1515
file = fopen(fileName, "wb");
1616
}
1717

18-
virtual void WriteFrame(AVFrame* frame, AVRational* timeBase)
18+
FrameSinkStream* CreateStream()
19+
{
20+
stream = new FrameSinkStream(this, 0);
21+
return stream;
22+
}
23+
24+
virtual void WriteFrame(int streamIndex, AVFrame* frame, AVRational* timeBase)
1925
{
2026
// Just write out the samples channel by channel to a file.
2127
int data_size = av_get_bytes_per_sample((AVSampleFormat)frame->format);
@@ -28,9 +34,10 @@ class RawAudioFileSink : public AudioFrameSink
2834
}
2935
}
3036

31-
virtual void Close()
37+
virtual void Close(int streamIndex)
3238
{
3339
fclose(file);
40+
delete stream;
3441
}
3542

3643
virtual bool IsPrimed()
@@ -42,7 +49,9 @@ class RawAudioFileSink : public AudioFrameSink
4249
return true;
4350
}
4451

52+
private:
4553
FILE* file;
54+
FrameSinkStream* stream;
4655

4756
};
4857

source/ffmpeg-cpp/decode_video/decode_video.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66
using namespace std;
77
using namespace ffmpegcpp;
88

9-
class PGMFileSink : public VideoFrameSink
9+
class PGMFileSink : public VideoFrameSink, public FrameWriter
1010
{
1111
public:
1212

1313
PGMFileSink()
1414
{
1515
}
1616

17-
virtual void WriteFrame(AVFrame* frame, AVRational* timeBase)
17+
FrameSinkStream* CreateStream()
18+
{
19+
stream = new FrameSinkStream(this, 0);
20+
return stream;
21+
}
22+
23+
virtual void WriteFrame(int streamIndex, AVFrame* frame, AVRational* timeBase)
1824
{
1925
++frameNumber;
2026
printf("saving frame %3d\n", frameNumber);
@@ -41,9 +47,9 @@ class PGMFileSink : public VideoFrameSink
4147
fclose(f);
4248
}
4349

44-
virtual void Close()
50+
virtual void Close(int streamIndex)
4551
{
46-
// nothing to do here.
52+
delete stream;
4753
}
4854

4955
virtual bool IsPrimed()
@@ -58,6 +64,7 @@ class PGMFileSink : public VideoFrameSink
5864
private:
5965
char fileNameBuffer[1024];
6066
int frameNumber = 0;
67+
FrameSinkStream* stream;
6168

6269
};
6370

source/ffmpeg-cpp/demo/demo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ void PlayDemo(int argc, char** argv)
3333
// hard-code the settings here, but let them be overridden by the arguments
3434
string inputAudioSource = "CONTAINER"; // options are RAW, ENCODED, CONTAINER, GENERATED
3535
string inputVideoSource = "ENCODED"; // options are RAW, ENCODED, CONTAINER, GENERATED
36-
string outputAudioCodec = "AAC"; // options are MP2, AAC, NONE
36+
string outputAudioCodec = "NONE"; // options are MP2, AAC, NONE
3737
string outputVideoCodec = "H264"; // options are H264, H265, VP9, NONE (H264 and H265 only work on Nvidia hardware)
3838
string outputContainerName = "out.mp4"; // container format is deduced from extension so use a known one
3939

4040
// you can use any filter string that you can use in the ffmpeg command-line here
4141
// set the filter to NULL to disable filtering.
4242
// See https://trac.ffmpeg.org/wiki/FilteringGuide for more info
4343
// This example rotates the entire video and then puts a vignette on top of it.
44-
const char* videoFilterConfig = NULL;//"transpose=cclock[middle];[middle]vignette"
44+
const char* videoFilterConfig = "transpose=cclock[middle];[middle]vignette";
45+
//const char* videoFilterConfig = NULL;
4546

4647
// if command line is specified, we overwrite our hard-coded settings
4748
if (argc >= 6)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
#include <iostream>
3+
4+
#include "ffmpegcpp.h"
5+
6+
using namespace std;
7+
using namespace ffmpegcpp;
8+
9+
10+
int main()
11+
{
12+
// This example will apply a vignette filter and then compare the changed output to
13+
// the original video by using the difference filter.
14+
try
15+
{
16+
// Create a muxer that will output the video as MKV.
17+
Muxer* muxer = new Muxer("out.mp4");
18+
19+
// Create a codec that will encode video as VP9
20+
PNGCodec* videoCodec = new PNGCodec();
21+
22+
// Create encoders for both
23+
VideoEncoder* videoEncoder = new VideoEncoder(videoCodec, muxer);
24+
25+
// Create a video filter and do some funny stuff with the video data.
26+
VideoFilter* filter = new VideoFilter("blend=all_mode=difference", videoEncoder);
27+
//VideoFilter* filter = new VideoFilter("overlay=0:0", videoEncoder);
28+
//VideoFilter* filter = new VideoFilter("scale=100:800", videoEncoder);
29+
30+
// Create a video filter that will put a vignette on one of the video's,
31+
// so that our difference filter van detect this.
32+
VideoFilter* vignetteFilter = new VideoFilter("vignette", filter);
33+
34+
// Load both video's
35+
Demuxer* videoContainer1 = new Demuxer("samples/carphone.h264");
36+
Demuxer* videoContainer2 = new Demuxer("samples/carphone.h264");
37+
38+
// Tie the best stream from each container to the output
39+
videoContainer1->DecodeBestVideoStream(filter);
40+
videoContainer2->DecodeBestVideoStream(vignetteFilter);
41+
42+
// Prepare the pipeline. We want to call this before the rest of the loop
43+
// to ensure that the muxer will be fully ready to receive data from
44+
// multiple sources.
45+
videoContainer1->PreparePipeline();
46+
videoContainer2->PreparePipeline();
47+
48+
// Pump the audio and video fully through.
49+
// To avoid big buffers, we interleave these calls so that the container
50+
// can be written to disk efficiently.
51+
while (!videoContainer1->IsDone() || !videoContainer2->IsDone())
52+
{
53+
if (!videoContainer1->IsDone()) videoContainer1->Step();
54+
if (!videoContainer2->IsDone()) videoContainer2->Step();
55+
}
56+
57+
// Save everything to disk by closing the muxer.
58+
muxer->Close();
59+
}
60+
catch (FFmpegException e)
61+
{
62+
cerr << "Exception caught!" << endl;
63+
cerr << e.what() << endl;
64+
throw e;
65+
}
66+
67+
cout << "Encoding complete!" << endl;
68+
cout << "Press any key to continue..." << endl;
69+
70+
getchar();
71+
}
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>15.0</VCProjectVersion>
23+
<ProjectGuid>{9BD8FF1D-1C1B-4755-BF5C-AD58DC023711}</ProjectGuid>
24+
<Keyword>Win32Proj</Keyword>
25+
<RootNamespace>decodeaudio</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v141</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v141</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v141</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v141</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
<Import Project="..\FFmpegLibraryLocationProperty.props" />
63+
</ImportGroup>
64+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
65+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
66+
<Import Project="..\FFmpegLibraryLocationProperty.props" />
67+
</ImportGroup>
68+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
69+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70+
<Import Project="..\FFmpegLibraryLocationProperty.props" />
71+
</ImportGroup>
72+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
73+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
74+
<Import Project="..\FFmpegLibraryLocationProperty.props" />
75+
</ImportGroup>
76+
<PropertyGroup Label="UserMacros" />
77+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
78+
<LinkIncremental>true</LinkIncremental>
79+
<OutDir>$(ProjectDir)..\..\..\bin\$(Platform)\$(Configuration)\</OutDir>
80+
<IntDir>obj\$(Platform)\$(Configuration)\</IntDir>
81+
</PropertyGroup>
82+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
83+
<LinkIncremental>true</LinkIncremental>
84+
<OutDir>$(ProjectDir)..\..\..\bin\$(Platform)\$(Configuration)\</OutDir>
85+
<IntDir>obj\$(Platform)\$(Configuration)\</IntDir>
86+
</PropertyGroup>
87+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
88+
<LinkIncremental>false</LinkIncremental>
89+
<OutDir>$(ProjectDir)..\..\..\bin\$(Platform)\$(Configuration)\</OutDir>
90+
<IntDir>obj\$(Platform)\$(Configuration)\</IntDir>
91+
</PropertyGroup>
92+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
93+
<LinkIncremental>false</LinkIncremental>
94+
<OutDir>$(ProjectDir)..\..\..\bin\$(Platform)\$(Configuration)\</OutDir>
95+
<IntDir>obj\$(Platform)\$(Configuration)\</IntDir>
96+
</PropertyGroup>
97+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
98+
<ClCompile>
99+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
100+
<WarningLevel>Level3</WarningLevel>
101+
<Optimization>Disabled</Optimization>
102+
<SDLCheck>false</SDLCheck>
103+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
104+
<ConformanceMode>true</ConformanceMode>
105+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
106+
<AdditionalIncludeDirectories>$(FFmpegLibraryDir)include;..\ffmpeg-cpp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
107+
</ClCompile>
108+
<Link>
109+
<SubSystem>Console</SubSystem>
110+
<GenerateDebugInformation>true</GenerateDebugInformation>
111+
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
112+
</Link>
113+
<PostBuildEvent>
114+
<Command>xcopy $(SamplesDir) $(OutDir)samples /s /y /i
115+
xcopy $(FFmpegLibraryDir)bin $(OutDir) /s /y /i</Command>
116+
</PostBuildEvent>
117+
</ItemDefinitionGroup>
118+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
119+
<ClCompile>
120+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
121+
<WarningLevel>Level3</WarningLevel>
122+
<Optimization>Disabled</Optimization>
123+
<SDLCheck>true</SDLCheck>
124+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
125+
<ConformanceMode>true</ConformanceMode>
126+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
127+
<AdditionalIncludeDirectories>$(FFmpegLibraryDir)include;..\ffmpeg-cpp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
128+
</ClCompile>
129+
<Link>
130+
<SubSystem>Console</SubSystem>
131+
<GenerateDebugInformation>true</GenerateDebugInformation>
132+
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
133+
</Link>
134+
<PostBuildEvent>
135+
<Command>xcopy $(SamplesDir) $(OutDir)samples /s /y /i
136+
xcopy $(FFmpegLibraryDir)bin $(OutDir) /s /y /i</Command>
137+
</PostBuildEvent>
138+
</ItemDefinitionGroup>
139+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
140+
<ClCompile>
141+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
142+
<WarningLevel>Level3</WarningLevel>
143+
<Optimization>MaxSpeed</Optimization>
144+
<FunctionLevelLinking>true</FunctionLevelLinking>
145+
<IntrinsicFunctions>true</IntrinsicFunctions>
146+
<SDLCheck>true</SDLCheck>
147+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
148+
<ConformanceMode>true</ConformanceMode>
149+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
150+
<AdditionalIncludeDirectories>$(FFmpegLibraryDir)include;..\ffmpeg-cpp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
151+
</ClCompile>
152+
<Link>
153+
<SubSystem>Console</SubSystem>
154+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
155+
<OptimizeReferences>true</OptimizeReferences>
156+
<GenerateDebugInformation>true</GenerateDebugInformation>
157+
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
158+
</Link>
159+
<PostBuildEvent>
160+
<Command>xcopy $(SamplesDir) $(OutDir)samples /s /y /i
161+
xcopy $(FFmpegLibraryDir)bin $(OutDir) /s /y /i</Command>
162+
</PostBuildEvent>
163+
</ItemDefinitionGroup>
164+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
165+
<ClCompile>
166+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
167+
<WarningLevel>Level3</WarningLevel>
168+
<Optimization>MaxSpeed</Optimization>
169+
<FunctionLevelLinking>true</FunctionLevelLinking>
170+
<IntrinsicFunctions>true</IntrinsicFunctions>
171+
<SDLCheck>true</SDLCheck>
172+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
173+
<ConformanceMode>true</ConformanceMode>
174+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
175+
<AdditionalIncludeDirectories>$(FFmpegLibraryDir)include;..\ffmpeg-cpp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
176+
</ClCompile>
177+
<Link>
178+
<SubSystem>Console</SubSystem>
179+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
180+
<OptimizeReferences>true</OptimizeReferences>
181+
<GenerateDebugInformation>true</GenerateDebugInformation>
182+
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
183+
</Link>
184+
<PostBuildEvent>
185+
<Command>xcopy $(SamplesDir) $(OutDir)samples /s /y /i
186+
xcopy $(FFmpegLibraryDir)bin $(OutDir) /s /y /i</Command>
187+
</PostBuildEvent>
188+
</ItemDefinitionGroup>
189+
<ItemGroup>
190+
<ProjectReference Include="..\ffmpeg-cpp\ffmpeg-cpp.vcxproj">
191+
<Project>{babfd64d-9bf1-4328-b977-24bf81800620}</Project>
192+
</ProjectReference>
193+
</ItemGroup>
194+
<ItemGroup>
195+
<ClCompile Include="difference.cpp" />
196+
</ItemGroup>
197+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
198+
<ImportGroup Label="ExtensionTargets">
199+
</ImportGroup>
200+
</Project>

0 commit comments

Comments
 (0)