Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1f07bb2

Browse files
committed
3.2.0
1. Upgrade to `FFMpeg 5.0` Version. 2. Fix the const assignment bug caused by the codec configuration method.
1 parent e5d48b9 commit 1f07bb2

File tree

10 files changed

+82
-58
lines changed

10 files changed

+82
-58
lines changed

‎CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Update Report
44

5+
### V3.2.0 update report:
6+
7+
1. Upgrade to `FFMpeg 5.0` Version.
8+
9+
2. Fix the const assignment bug caused by the codec configuration method.
10+
511
### V3.1.0 update report:
612

713
1. Support `str()` type for all string arguments.

‎MpegCoder/MpegBase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
#define FFMPG3_4
1212
#define FFMPG4_0
1313
#define FFMPG4_4
14+
#define FFMPG5_0
1415

15-
#define MPEGCODER_CURRENT_VERSION "3.1.0"
16+
#define MPEGCODER_CURRENT_VERSION "3.2.0"
1617

1718
#define STREAM_PIX_FMT AVPixelFormat::AV_PIX_FMT_YUV420P /* default pix_fmt */
1819

‎MpegCoder/MpegCoder.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,43 +1092,45 @@ int cmpc::CMpegEncoder::__write_frame() {
10921092
}
10931093

10941094
/* Add an output stream. */
1095-
bool cmpc::CMpegEncoder::__add_stream(AVCodec** codec) {
1095+
const cmpc::AVCodec* cmpc::CMpegEncoder::__add_stream() {
10961096
/* find the encoder */
10971097
AVCodecID codec_id;
10981098
auto srcwidth = widthSrc > 0 ? widthSrc : width;
10991099
auto srcheight = heightSrc > 0 ? heightSrc : height;
1100-
*codec = avcodec_find_encoder_by_name(codecName.c_str());
1101-
if (!(*codec)) {
1100+
auto const_codec = avcodec_find_encoder_by_name(codecName.c_str());
1101+
const AVCodec* codec;
1102+
if (!(const_codec)) {
11021103
codec_id = PFormatCtx->oformat->video_codec;
11031104
cerr << "Could not find encoder " << codecName << ", use " << avcodec_get_name(codec_id) << " as an alternative." << endl;
1104-
*codec = avcodec_find_encoder(codec_id);
1105+
codec = avcodec_find_encoder(codec_id);
11051106
}
11061107
else {
1107-
codec_id = (*codec)->id;
1108-
PFormatCtx->oformat->video_codec = codec_id;
1108+
codec = const_codec;
1109+
codec_id = codec->id;
11091110
}
1110-
if (!(*codec)) {
1111+
1112+
if (!codec) {
11111113
cerr << "Could not find encoder for '" << avcodec_get_name(codec_id) << "'" << endl;
1112-
return false;
1114+
return nullptr;
11131115
}
11141116

11151117
PStreamContex.st = avformat_new_stream(PFormatCtx, nullptr);
11161118
if (!PStreamContex.st) {
11171119
cerr << "Could not allocate stream" << endl;
1118-
return false;
1120+
return nullptr;
11191121
}
11201122
PStreamContex.st->id = PFormatCtx->nb_streams - 1;
1121-
auto c = avcodec_alloc_context3(*codec);
1123+
auto c = avcodec_alloc_context3(codec);
11221124
if (!c) {
11231125
cerr << "Could not alloc an encoding context" << endl;
1124-
return false;
1126+
return nullptr;
11251127
}
11261128
if (nthread > 0) {
11271129
c->thread_count = nthread;
11281130
}
11291131
PStreamContex.enc = c;
11301132

1131-
switch ((*codec)->type) {
1133+
switch (codec->type) {
11321134
case AVMediaType::AVMEDIA_TYPE_VIDEO:
11331135
c->codec_id = codec_id;
11341136

@@ -1206,7 +1208,7 @@ bool cmpc::CMpegEncoder::__add_stream(AVCodec** codec) {
12061208
/* Some formats want stream headers to be separate. */
12071209
if (PFormatCtx->oformat->flags & AVFMT_GLOBALHEADER)
12081210
c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1209-
return true;
1211+
return codec;
12101212
}
12111213

12121214
/* video output */
@@ -1226,7 +1228,7 @@ cmpc::AVFrame* cmpc::CMpegEncoder::__alloc_picture(enum AVPixelFormat pix_fmt, i
12261228
return picture;
12271229
}
12281230

1229-
bool cmpc::CMpegEncoder::__open_video(AVCodec* codec, AVDictionary* opt_arg) {
1231+
bool cmpc::CMpegEncoder::__open_video(constAVCodec* codec,const AVDictionary* opt_arg) {
12301232
int ret;
12311233
auto c = PStreamContex.enc;
12321234
AVDictionary* opt = nullptr;
@@ -1809,7 +1811,7 @@ PyObject* cmpc::CMpegEncoder::getParameter() {
18091811
}
18101812

18111813
bool cmpc::CMpegEncoder::FFmpegSetup() {
1812-
AVCodec* video_codec = nullptr;
1814+
constAVCodec* video_codec;
18131815
int ret;
18141816

18151817
if (Ppacket)
@@ -1839,13 +1841,17 @@ bool cmpc::CMpegEncoder::FFmpegSetup() {
18391841
/* Add the audio and video streams using the default format codecs
18401842
* and initialize the codecs. */
18411843
if (fmt->video_codec != AVCodecID::AV_CODEC_ID_NONE) {
1842-
if (!__add_stream(&video_codec)) {
1844+
video_codec = __add_stream();
1845+
if (!video_codec) {
18431846
FFmpegClose();
18441847
return false;
18451848
}
18461849
else
18471850
__have_video = true;
18481851
}
1852+
else {
1853+
video_codec = nullptr;
1854+
}
18491855

18501856
/* Now that all the parameters are set, we can open the audio and
18511857
* video codecs and allocate the necessary encode buffers. */

‎MpegCoder/MpegCoder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ namespace cmpc {
122122
bool _LoadFrame_castFromPyFrameArray(AVFrame* frame, PyArrayObject* PyFrame);
123123
void __log_packet();
124124
int __write_frame();
125-
bool__add_stream(AVCodec** codec);
125+
constAVCodec*__add_stream();
126126
AVFrame* __alloc_picture(enum AVPixelFormat pix_fmt, int width, int height);
127-
bool __open_video(AVCodec* codec, AVDictionary* opt_arg);
127+
bool __open_video(constAVCodec* codec,const AVDictionary* opt_arg);
128128
AVFrame* __get_video_frame(PyArrayObject* PyFrame);
129129
int __avcodec_encode_video2(AVCodecContext* enc_ctx, AVPacket* pkt, AVFrame* frame);
130130
int __avcodec_encode_video2_flush(AVCodecContext* enc_ctx, AVPacket* pkt);

‎MpegCoder/MpegCoder.vcxproj

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@
2929
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
3030
<ConfigurationType>DynamicLibrary</ConfigurationType>
3131
<UseDebugLibraries>true</UseDebugLibraries>
32-
<PlatformToolset>v142</PlatformToolset>
32+
<PlatformToolset>v143</PlatformToolset>
3333
<CharacterSet>Unicode</CharacterSet>
3434
</PropertyGroup>
3535
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
3636
<ConfigurationType>DynamicLibrary</ConfigurationType>
3737
<UseDebugLibraries>false</UseDebugLibraries>
38-
<PlatformToolset>v142</PlatformToolset>
38+
<PlatformToolset>v143</PlatformToolset>
3939
<WholeProgramOptimization>true</WholeProgramOptimization>
4040
<CharacterSet>Unicode</CharacterSet>
4141
</PropertyGroup>
4242
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
4343
<ConfigurationType>DynamicLibrary</ConfigurationType>
4444
<UseDebugLibraries>true</UseDebugLibraries>
45-
<PlatformToolset>v142</PlatformToolset>
45+
<PlatformToolset>v143</PlatformToolset>
4646
<CharacterSet>Unicode</CharacterSet>
4747
</PropertyGroup>
4848
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
4949
<ConfigurationType>DynamicLibrary</ConfigurationType>
5050
<UseDebugLibraries>false</UseDebugLibraries>
51-
<PlatformToolset>v142</PlatformToolset>
51+
<PlatformToolset>v143</PlatformToolset>
5252
<WholeProgramOptimization>true</WholeProgramOptimization>
5353
<CharacterSet>Unicode</CharacterSet>
5454
</PropertyGroup>
@@ -77,8 +77,8 @@
7777
</PropertyGroup>
7878
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
7979
<LinkIncremental>true</LinkIncremental>
80-
<IncludePath>C:\Users\yjin4\.conda\envs\py39\include;C:\Users\yjin4\.conda\envs\py39\lib\site-packages\numpy\core\include;..\include;$(IncludePath)</IncludePath>
81-
<LibraryPath>C:\Users\yjin4\.conda\envs\py39\libs;C:\Users\yjin4\.conda\envs\py39\lib\site-packages\numpy\core\lib;..\lib;$(LibraryPath)</LibraryPath>
80+
<IncludePath>C:\Users\cainm\.conda\envs\py310\include;C:\Users\cainm\.conda\envs\py310\lib\site-packages\numpy\core\include;..\include;$(IncludePath)</IncludePath>
81+
<LibraryPath>C:\Users\cainm\.conda\envs\py310\libs;C:\Users\cainm\.conda\envs\py310\lib\site-packages\numpy\core\lib;..\lib;$(LibraryPath)</LibraryPath>
8282
</PropertyGroup>
8383
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
8484
<LinkIncremental>false</LinkIncremental>
@@ -87,8 +87,8 @@
8787
</PropertyGroup>
8888
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
8989
<LinkIncremental>false</LinkIncremental>
90-
<IncludePath>C:\Users\yjin4\.conda\envs\py39\include;C:\Users\yjin4\.conda\envs\py39\lib\site-packages\numpy\core\include;..\include;$(IncludePath)</IncludePath>
91-
<LibraryPath>C:\Users\yjin4\.conda\envs\py39\libs;C:\Users\yjin4\.conda\envs\py39\lib\site-packages\numpy\core\lib;..\lib;$(LibraryPath)</LibraryPath>
90+
<IncludePath>C:\Users\cainm\.conda\envs\py310\include;C:\Users\cainm\.conda\envs\py310\lib\site-packages\numpy\core\include;..\include;$(IncludePath)</IncludePath>
91+
<LibraryPath>C:\Users\cainm\.conda\envs\py310\libs;C:\Users\cainm\.conda\envs\py310\lib\site-packages\numpy\core\lib;..\lib;$(LibraryPath)</LibraryPath>
9292
</PropertyGroup>
9393
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
9494
<ClCompile>
@@ -111,11 +111,12 @@
111111
<Optimization>Disabled</Optimization>
112112
<PreprocessorDefinitions>_DEBUG;MpegCoder_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
113113
<SDLCheck>true</SDLCheck>
114+
<OpenMPSupport>true</OpenMPSupport>
114115
</ClCompile>
115116
<Link>
116117
<SubSystem>Windows</SubSystem>
117118
<GenerateDebugInformation>true</GenerateDebugInformation>
118-
<AdditionalDependencies>avcodec.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;python39.lib;python3.lib;npymath.lib;%(AdditionalDependencies)</AdditionalDependencies>
119+
<AdditionalDependencies>python310.lib;python3.lib;npymath.lib;avcodec.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;%(AdditionalDependencies)</AdditionalDependencies>
119120
</Link>
120121
<PostBuildEvent>
121122
<Command>echo F | xcopy /y /i "$(OutDir)$(TargetName)$(TargetExt)" "$(OutDir)mpegCoder.pyd"</Command>
@@ -148,13 +149,14 @@
148149
<IntrinsicFunctions>true</IntrinsicFunctions>
149150
<PreprocessorDefinitions>NDEBUG;MpegCoder_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
150151
<SDLCheck>true</SDLCheck>
152+
<OpenMPSupport>true</OpenMPSupport>
151153
</ClCompile>
152154
<Link>
153155
<SubSystem>Windows</SubSystem>
154156
<EnableCOMDATFolding>true</EnableCOMDATFolding>
155157
<OptimizeReferences>true</OptimizeReferences>
156158
<GenerateDebugInformation>true</GenerateDebugInformation>
157-
<AdditionalDependencies>avcodec.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;python39.lib;python3.lib;npymath.lib;%(AdditionalDependencies)</AdditionalDependencies>
159+
<AdditionalDependencies>python310.lib;python3.lib;npymath.lib;avcodec.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;%(AdditionalDependencies)</AdditionalDependencies>
158160
</Link>
159161
<PostBuildEvent>
160162
<Command>echo F | xcopy /y /i "$(OutDir)$(TargetName)$(TargetExt)" "$(OutDir)mpegCoder.pyd"</Command>

‎MpegCoder/MpegPyd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ Yuchen's Mpeg Coder - Readme
213213
>>> d.clear() # Disconnect with the stream.
214214
For more instructions, you could tap help(mpegCoder).
215215
================================================================================
216+
V3.2.0 update report:
217+
1. Upgrade FFMpeg to 5.0.
218+
2. Fix the const assignment bug caused by the codec configuration method.
216219
V3.1.0 update report:
217220
1. Support str() type for all string arguments.
218221
2. Support http, ftp, sftp streams for MpegServer.

‎MpegCoder/MpegStreamer.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,43 +1202,45 @@ int cmpc::CMpegServer::__write_frame() {
12021202
}
12031203

12041204
/* Add an output stream. */
1205-
bool cmpc::CMpegServer::__add_stream(AVCodec** codec) {
1205+
const cmpc::AVCodec* cmpc::CMpegServer::__add_stream() {
12061206
/* find the encoder */
12071207
AVCodecID codec_id;
12081208
auto srcwidth = widthSrc > 0 ? widthSrc : width;
12091209
auto srcheight = heightSrc > 0 ? heightSrc : height;
1210-
*codec = avcodec_find_encoder_by_name(codecName.c_str());
1211-
if (!(*codec)) {
1210+
auto const_codec = avcodec_find_encoder_by_name(codecName.c_str());
1211+
const AVCodec* codec;
1212+
if (!(const_codec)) {
12121213
codec_id = PFormatCtx->oformat->video_codec;
12131214
cerr << "Could not find encoder " << codecName << ", use " << avcodec_get_name(codec_id) << " as an alternative." << endl;
1214-
*codec = avcodec_find_encoder(codec_id);
1215+
codec = avcodec_find_encoder(codec_id);
12151216
}
12161217
else {
1217-
codec_id = (*codec)->id;
1218-
PFormatCtx->oformat->video_codec = codec_id;
1218+
codec = const_codec;
1219+
codec_id = codec->id;
12191220
}
1220-
if (!(*codec)) {
1221+
1222+
if (!codec) {
12211223
cerr << "Could not find encoder for '" << avcodec_get_name(codec_id) << "'" << endl;
1222-
return false;
1224+
return nullptr;
12231225
}
12241226

12251227
PStreamContex.st = avformat_new_stream(PFormatCtx, nullptr);
12261228
if (!PStreamContex.st) {
12271229
cerr << "Could not allocate stream" << endl;
1228-
return false;
1230+
return nullptr;
12291231
}
12301232
PStreamContex.st->id = PFormatCtx->nb_streams - 1;
1231-
auto c = avcodec_alloc_context3(*codec);
1233+
auto c = avcodec_alloc_context3(codec);
12321234
if (!c) {
12331235
cerr << "Could not alloc an encoding context" << endl;
1234-
return false;
1236+
return nullptr;
12351237
}
12361238
if (nthread > 0) {
12371239
c->thread_count = nthread;
12381240
}
12391241
PStreamContex.enc = c;
12401242

1241-
switch ((*codec)->type) {
1243+
switch (codec->type) {
12421244
case AVMediaType::AVMEDIA_TYPE_VIDEO:
12431245
c->codec_id = codec_id;
12441246

@@ -1316,7 +1318,7 @@ bool cmpc::CMpegServer::__add_stream(AVCodec** codec) {
13161318
/* Some formats want stream headers to be separate. */
13171319
if (PFormatCtx->oformat->flags & AVFMT_GLOBALHEADER)
13181320
c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1319-
return true;
1321+
return codec;
13201322
}
13211323

13221324
/* video output */
@@ -1336,7 +1338,7 @@ cmpc::AVFrame* cmpc::CMpegServer::__alloc_picture(enum AVPixelFormat pix_fmt, in
13361338
return picture;
13371339
}
13381340

1339-
bool cmpc::CMpegServer::__open_video(AVCodec* codec, AVDictionary* opt_arg) {
1341+
bool cmpc::CMpegServer::__open_video(constAVCodec* codec,const AVDictionary* opt_arg) {
13401342
int ret;
13411343
auto c = PStreamContex.enc;
13421344
AVDictionary* opt = nullptr;
@@ -1988,7 +1990,7 @@ bool cmpc::CMpegServer::FFmpegSetup() {
19881990
cerr << "Have not get necessary and correct configurations, so FFmpegSetup() should not be called." << endl;
19891991
return false;
19901992
}
1991-
AVCodec* video_codec = nullptr;
1993+
constAVCodec* video_codec;
19921994
int ret;
19931995

19941996
if (Ppacket)
@@ -2035,13 +2037,17 @@ bool cmpc::CMpegServer::FFmpegSetup() {
20352037
/* Add the audio and video streams using the default format codecs
20362038
* and initialize the codecs. */
20372039
if (fmt->video_codec != AVCodecID::AV_CODEC_ID_NONE) {
2038-
if (!__add_stream(&video_codec)) {
2040+
video_codec = __add_stream();
2041+
if (!video_codec) {
20392042
FFmpegClose();
20402043
return false;
20412044
}
20422045
else
20432046
__have_video = true;
20442047
}
2048+
else {
2049+
video_codec = nullptr;
2050+
}
20452051

20462052
/* Now that all the parameters are set, we can open the audio and
20472053
* video codecs and allocate the necessary encode buffers. */

‎MpegCoder/MpegStreamer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ namespace cmpc {
163163
bool _LoadFrame_castFromPyFrameArray(AVFrame* frame, PyArrayObject* PyFrame);
164164
void __log_packet();
165165
int __write_frame();
166-
bool__add_stream(AVCodec** codec);
166+
constAVCodec*__add_stream();
167167
AVFrame* __alloc_picture(enum AVPixelFormat pix_fmt, int width, int height);
168-
bool __open_video(AVCodec* codec, AVDictionary* opt_arg);
168+
bool __open_video(constAVCodec* codec,const AVDictionary* opt_arg);
169169
AVFrame* __get_video_frame(PyArrayObject* PyFrame);
170170
int __avcodec_encode_video2(AVCodecContext* enc_ctx, AVPacket* pkt, AVFrame* frame);
171171
int __avcodec_encode_video2_flush(AVCodecContext* enc_ctx, AVPacket* pkt);

‎README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ The following instructions are used for building the project on Windows with Vis
4646
6. The `mpegCoder.pyd` should be used together with the FFMpeg shared libraries, including:
4747

4848
```shell
49-
avcodec-58.dll
50-
avformat-58.dll
51-
avutil-56.dll
52-
swresample-3.dll
53-
swscale-5.dll
49+
avcodec-59.dll
50+
avformat-59.dll
51+
avutil-57.dll
52+
swresample-4.dll
53+
swscale-6.dll
5454
```
5555

5656
## Update reports
@@ -63,11 +63,11 @@ Current FFMpeg version is `4.4`.
6363

6464
| Dependency | Version |
6565
| :-------------: | :------------: |
66-
| `libavcodec` | `58.134.100.0` |
67-
| `libavformat` | `58.76.100.0` |
68-
| `libavutil` | `56.70.100.0` |
69-
| `libswresample` | `3.9.100.0` |
70-
| `libswscale` | `5.9.100.0` |
66+
| `libavcodec` | `59.18.100.0` |
67+
| `libavformat` | `59.16.100.0` |
68+
| `libavutil` | `57.17.100.0` |
69+
| `libswresample` | `4.3.100.0` |
70+
| `libswscale` | `6.4.100.0` |
7171

7272
[git-linux]:https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/tree/master-linux "master (Linux)"
7373
[exp1]:https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/tree/example-client-check "check the client"

‎webtools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,4 @@ def download_tarball(user, repo, tag, asset, path='.', mode='auto', token=None,
302302

303303
# token = get_token(token='')
304304
print('Get ffmpeg dependencies...')
305-
download_tarball('cainmagi', 'FFmpeg-Encoder-Decoder-for-Python', 'deps-3.0.0', 'dep-win-ffmpeg_4_4.tar.xz', path='.', mode='auto', verbose=True, token='')
305+
download_tarball('cainmagi', 'FFmpeg-Encoder-Decoder-for-Python', 'deps-3.2.0', 'dep-win-ffmpeg_5_0.tar.xz', path='.', mode='auto', verbose=True, token='')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /