File tree Expand file tree Collapse file tree 10 files changed +52
-88
lines changed
Expand file tree Collapse file tree 10 files changed +52
-88
lines changed Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" utf-8" ?>
22<Project ToolsVersion =" 15.0" xmlns =" http://schemas.microsoft.com/developer/msbuild/2003" >
3- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|Win32'" >
4- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
5- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
6- </PropertyGroup >
7- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Release|Win32'" >
8- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
9- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
10- </PropertyGroup >
11- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >
12- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
13- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
14- </PropertyGroup >
15- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Release|x64'" >
16- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
17- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
18- </PropertyGroup >
3+ <PropertyGroup />
194</Project >
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" utf-8" ?>
22<Project ToolsVersion =" 15.0" xmlns =" http://schemas.microsoft.com/developer/msbuild/2003" >
3- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|Win32'" >
4- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
5- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
6- </PropertyGroup >
7- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Release|Win32'" >
8- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
9- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
10- </PropertyGroup >
11- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >
12- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
13- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
14- </PropertyGroup >
15- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Release|x64'" >
16- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
17- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
18- </PropertyGroup >
3+ <PropertyGroup />
194</Project >
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" utf-8" ?>
22<Project ToolsVersion =" 15.0" xmlns =" http://schemas.microsoft.com/developer/msbuild/2003" >
3- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >
4- <LocalDebuggerCommandArguments >"D:\WonderMedia\ffmpeg\samples\carphone_qcif.y4m" "D:\WonderMedia\ffmpeg\samples\DesiJourney.wav" "D:\WonderMedia\ffmpeg\samples\out.mp4"</LocalDebuggerCommandArguments >
5- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
6- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
7- </PropertyGroup >
8- <PropertyGroup >
9- <ShowAllFiles >false</ShowAllFiles >
10- </PropertyGroup >
113 <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|Win32'" >
124 <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
135 <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
168 <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
179 <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
1810 </PropertyGroup >
11+ <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >
12+ <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
13+ <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
14+ </PropertyGroup >
1915 <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Release|x64'" >
2016 <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
2117 <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" utf-8" ?>
22<Project ToolsVersion =" 15.0" xmlns =" http://schemas.microsoft.com/developer/msbuild/2003" >
3- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|Win32'" >
4- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
5- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
6- </PropertyGroup >
7- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Release|Win32'" >
8- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
9- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
10- </PropertyGroup >
11- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >
12- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
13- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
14- </PropertyGroup >
15- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Release|x64'" >
16- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
17- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
18- </PropertyGroup >
3+ <PropertyGroup />
194</Project >
Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ int main()
2828 // but if we have something weird, we can specify the properties of the format
2929 // in the constructor as commented out below.
3030 RawVideoFileSource* videoFile = new RawVideoFileSource (" samples/carphone_qcif.y4m" , encoder);
31+ /* Demuxer* videoFile = new Demuxer("samples/big_buck_bunny.mp4");
32+ videoFile->DecodeBestVideoStream(encoder);*/
3133
3234 // Prepare the output pipeline. This will push a small amount of frames to the file sink until it IsPrimed returns true.
3335 videoFile->PreparePipeline ();
Original file line number Diff line number Diff line change @@ -77,4 +77,37 @@ namespace ffmpegcpp
7777 if (*p == AV_PIX_FMT_NONE) throw FFmpegException (" Codec " + string (codecContext->codec ->name ) + " does not have a default pixel format, you have to specify one" );
7878 return *p;
7979 }
80+
81+ AVRational VideoCodec::GetClosestSupportedFrameRate (AVRational originalFrameRate)
82+ {
83+ if (!codecContext->codec ->supported_framerates )
84+ {
85+ // make up a frame rate - there is no supported frame rate
86+ return originalFrameRate;
87+ };
88+
89+ const AVRational *p = codecContext->codec ->supported_framerates ;
90+ AVRational bestFrameRate;
91+ bestFrameRate.num = 0 ;
92+ bestFrameRate.den = 1 ;
93+ double bestDiff = std::numeric_limits<double >::max ();
94+ double fVal = av_q2d (originalFrameRate);
95+ while (p->num )
96+ {
97+ double pVal = av_q2d (*p);
98+ double diff = abs (pVal - fVal );
99+ if (diff < bestDiff)
100+ {
101+ bestDiff = diff;
102+ bestFrameRate.num = p->num ;
103+ bestFrameRate.den = p->den ;
104+ }
105+ p++;
106+ }
107+
108+ // There were no valid frame rates in the list... this should never happen unless ffmpeg screws up.
109+ if (bestFrameRate.num == 0 ) return originalFrameRate;
110+
111+ return bestFrameRate;
112+ }
80113}
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ namespace ffmpegcpp
2020 bool IsFrameRateSupported (AVRational* frameRate);
2121
2222 AVPixelFormat GetDefaultPixelFormat ();
23+ AVRational GetClosestSupportedFrameRate (AVRational frameRate);
2324
2425 };
2526
Original file line number Diff line number Diff line change @@ -71,11 +71,18 @@ namespace ffmpegcpp
7171 // configure the parameters for the codec based on the frame and our preferences
7272 int width = frame->width ;
7373 int height = frame->height ;
74+
75+ // the format is either the provided format, or the default format if it is not supported
7476 AVPixelFormat format = finalPixelFormat;
77+ if (!closedCodec->IsPixelFormatSupported (format)) format = closedCodec->GetDefaultPixelFormat ();
7578 if (format == AV_PIX_FMT_NONE) format = closedCodec->GetDefaultPixelFormat ();
79+
80+ // the frame rate is either the input frame rate, OR the default frame rate if the input frame rate
81+ // is not supported, OR the explicitly chosen framerate.
7682 AVRational frameRate;
7783 frameRate.num = timeBase->den ;
7884 frameRate.den = timeBase->num ;
85+ if (!closedCodec->IsFrameRateSupported (&frameRate)) frameRate = closedCodec->GetClosestSupportedFrameRate (frameRate);
7986 if (finalFrameRateSet) frameRate = finalFrameRate;
8087
8188 // open the codec
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" utf-8" ?>
22<Project ToolsVersion =" 15.0" xmlns =" http://schemas.microsoft.com/developer/msbuild/2003" >
3- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|Win32'" >
4- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
5- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
6- </PropertyGroup >
7- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Release|Win32'" >
8- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
9- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
10- </PropertyGroup >
11- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >
12- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
13- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
14- </PropertyGroup >
15- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Release|x64'" >
16- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
17- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
18- </PropertyGroup >
3+ <PropertyGroup />
194</Project >
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" utf-8" ?>
22<Project ToolsVersion =" 15.0" xmlns =" http://schemas.microsoft.com/developer/msbuild/2003" >
3- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|Win32'" >
4- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
5- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
6- </PropertyGroup >
7- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Release|Win32'" >
8- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
9- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
10- </PropertyGroup >
11- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >
12- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
13- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
14- </PropertyGroup >
15- <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Release|x64'" >
16- <LocalDebuggerWorkingDirectory >$(OutDir)</LocalDebuggerWorkingDirectory >
17- <DebuggerFlavor >WindowsLocalDebugger</DebuggerFlavor >
18- </PropertyGroup >
3+ <PropertyGroup />
194</Project >
You can’t perform that action at this time.
0 commit comments