Skip to content

Commit 3760c5f

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. 3. Upgrade the dependencies of FFMpeg to the newest versions (issue #4).
1 parent db31157 commit 3760c5f

11 files changed

+91
-65
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ lib/*
1414
*.lastbuildstate
1515
unsuccessfulbuild
1616
/MpegCoder/x64/
17+
/autobuild*.sh
1718

1819
# Prerequisites
1920
*.d

Diff for: CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
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+
11+
3. Upgrade the dependencies of FFMpeg to the newest versions (issue [#4 :exclamation:](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/issues/4)).
12+
513
### V3.1.0 update report:
614

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

Diff for: MpegCoder/MpegBase.h

+2-1
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

Diff for: MpegCoder/MpegCoder.cpp

+24-18
Original file line numberDiff line numberDiff line change
@@ -1087,43 +1087,45 @@ int cmpc::CMpegEncoder::__write_frame(){
10871087
}
10881088

10891089
/* Add an output stream. */
1090-
bool cmpc::CMpegEncoder::__add_stream(AVCodec **codec){
1090+
const cmpc::AVCodec* cmpc::CMpegEncoder::__add_stream() {
10911091
/* find the encoder */
10921092
AVCodecID codec_id;
10931093
auto srcwidth = widthSrc > 0 ? widthSrc : width;
10941094
auto srcheight = heightSrc > 0 ? heightSrc : height;
1095-
*codec = avcodec_find_encoder_by_name(codecName.c_str());
1096-
if (!(*codec)) {
1095+
auto const_codec = avcodec_find_encoder_by_name(codecName.c_str());
1096+
const AVCodec* codec;
1097+
if (!(const_codec)) {
10971098
codec_id = PFormatCtx->oformat->video_codec;
1098-
cerr << "Could not find encoder "<< codecName <<", use " << avcodec_get_name(codec_id) << " as an alternative." << endl;
1099-
*codec = avcodec_find_encoder(codec_id);
1099+
cerr << "Could not find encoder " << codecName << ", use " << avcodec_get_name(codec_id) << " as an alternative." << endl;
1100+
codec = avcodec_find_encoder(codec_id);
11001101
}
11011102
else {
1102-
codec_id = (*codec)->id;
1103-
PFormatCtx->oformat->video_codec = codec_id;
1103+
codec = const_codec;
1104+
codec_id = codec->id;
11041105
}
1105-
if (!(*codec)) {
1106+
1107+
if (!codec) {
11061108
cerr << "Could not find encoder for '" << avcodec_get_name(codec_id) << "'" << endl;
1107-
return false;
1109+
return nullptr;
11081110
}
11091111

11101112
PStreamContex.st = avformat_new_stream(PFormatCtx, nullptr);
11111113
if (!PStreamContex.st) {
11121114
cerr << "Could not allocate stream" << endl;
1113-
return false;
1115+
return nullptr;
11141116
}
11151117
PStreamContex.st->id = PFormatCtx->nb_streams - 1;
1116-
auto c = avcodec_alloc_context3(*codec);
1118+
auto c = avcodec_alloc_context3(codec);
11171119
if (!c) {
11181120
cerr << "Could not alloc an encoding context" << endl;
1119-
return false;
1121+
return nullptr;
11201122
}
11211123
if (nthread > 0) {
11221124
c->thread_count = nthread;
11231125
}
11241126
PStreamContex.enc = c;
11251127

1126-
switch ((*codec)->type) {
1128+
switch (codec->type) {
11271129
case AVMediaType::AVMEDIA_TYPE_VIDEO:
11281130
c->codec_id = codec_id;
11291131

@@ -1141,7 +1143,7 @@ bool cmpc::CMpegEncoder::__add_stream(AVCodec **codec){
11411143
//cout << "(" << frameRate.num << ", " << frameRate.den << ")" << endl;
11421144
//PStreamContex.st->r_frame_rate
11431145
c->time_base = timeBase;
1144-
1146+
11451147
//PStreamContex.st->frame
11461148
c->framerate = frameRate;
11471149

@@ -1201,7 +1203,7 @@ bool cmpc::CMpegEncoder::__add_stream(AVCodec **codec){
12011203
/* Some formats want stream headers to be separate. */
12021204
if (PFormatCtx->oformat->flags & AVFMT_GLOBALHEADER)
12031205
c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1204-
return true;
1206+
return codec;
12051207
}
12061208

12071209
/* video output */
@@ -1221,7 +1223,7 @@ cmpc::AVFrame* cmpc::CMpegEncoder::__alloc_picture(enum AVPixelFormat pix_fmt, i
12211223
return picture;
12221224
}
12231225

1224-
bool cmpc::CMpegEncoder::__open_video(AVCodec *codec, AVDictionary *opt_arg){
1226+
bool cmpc::CMpegEncoder::__open_video(const AVCodec* codec, const AVDictionary* opt_arg) {
12251227
int ret;
12261228
auto c = PStreamContex.enc;
12271229
AVDictionary *opt = nullptr;
@@ -1804,7 +1806,7 @@ PyObject* cmpc::CMpegEncoder::getParameter() {
18041806
}
18051807

18061808
bool cmpc::CMpegEncoder::FFmpegSetup() {
1807-
AVCodec *video_codec = nullptr;
1809+
const AVCodec* video_codec;
18081810
int ret;
18091811

18101812
if (Ppacket)
@@ -1834,13 +1836,17 @@ bool cmpc::CMpegEncoder::FFmpegSetup() {
18341836
/* Add the audio and video streams using the default format codecs
18351837
* and initialize the codecs. */
18361838
if (fmt->video_codec != AVCodecID::AV_CODEC_ID_NONE) {
1837-
if (!__add_stream(&video_codec)) {
1839+
video_codec = __add_stream();
1840+
if (!video_codec) {
18381841
FFmpegClose();
18391842
return false;
18401843
}
18411844
else
18421845
__have_video = true;
18431846
}
1847+
else {
1848+
video_codec = nullptr;
1849+
}
18441850

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

Diff for: MpegCoder/MpegCoder.h

+2-2
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+
const AVCodec* __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(const AVCodec* 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);

Diff for: MpegCoder/MpegPyd.h

+4
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ Yuchen's Mpeg Coder - Readme
214214
>>> d.clear() # Disconnect with the stream.
215215
For more instructions, you could tap help(mpegCoder).
216216
================================================================================
217+
V3.2.0 update report:
218+
1. Upgrade FFMpeg to 5.0.
219+
2. Fix the const assignment bug caused by the codec configuration method.
220+
3. Upgrade the dependencies of FFMpeg to the newest versions (issue #4).
217221
V3.1.0 update report:
218222
1. Support str() type for all string arguments.
219223
2. Support http, ftp, sftp streams for MpegServer.

Diff for: MpegCoder/MpegStreamer.cpp

+22-16
Original file line numberDiff line numberDiff line change
@@ -1201,43 +1201,45 @@ int cmpc::CMpegServer::__write_frame() {
12011201
}
12021202

12031203
/* Add an output stream. */
1204-
bool cmpc::CMpegServer::__add_stream(AVCodec** codec) {
1204+
const cmpc::AVCodec* cmpc::CMpegServer::__add_stream() {
12051205
/* find the encoder */
12061206
AVCodecID codec_id;
12071207
auto srcwidth = widthSrc > 0 ? widthSrc : width;
12081208
auto srcheight = heightSrc > 0 ? heightSrc : height;
1209-
*codec = avcodec_find_encoder_by_name(codecName.c_str());
1210-
if (!(*codec)) {
1209+
auto const_codec = avcodec_find_encoder_by_name(codecName.c_str());
1210+
const AVCodec* codec;
1211+
if (!(const_codec)) {
12111212
codec_id = PFormatCtx->oformat->video_codec;
12121213
cerr << "Could not find encoder " << codecName << ", use " << avcodec_get_name(codec_id) << " as an alternative." << endl;
1213-
*codec = avcodec_find_encoder(codec_id);
1214+
codec = avcodec_find_encoder(codec_id);
12141215
}
12151216
else {
1216-
codec_id = (*codec)->id;
1217-
PFormatCtx->oformat->video_codec = codec_id;
1217+
codec = const_codec;
1218+
codec_id = codec->id;
12181219
}
1219-
if (!(*codec)) {
1220+
1221+
if (!codec) {
12201222
cerr << "Could not find encoder for '" << avcodec_get_name(codec_id) << "'" << endl;
1221-
return false;
1223+
return nullptr;
12221224
}
12231225

12241226
PStreamContex.st = avformat_new_stream(PFormatCtx, nullptr);
12251227
if (!PStreamContex.st) {
12261228
cerr << "Could not allocate stream" << endl;
1227-
return false;
1229+
return nullptr;
12281230
}
12291231
PStreamContex.st->id = PFormatCtx->nb_streams - 1;
1230-
auto c = avcodec_alloc_context3(*codec);
1232+
auto c = avcodec_alloc_context3(codec);
12311233
if (!c) {
12321234
cerr << "Could not alloc an encoding context" << endl;
1233-
return false;
1235+
return nullptr;
12341236
}
12351237
if (nthread > 0) {
12361238
c->thread_count = nthread;
12371239
}
12381240
PStreamContex.enc = c;
12391241

1240-
switch ((*codec)->type) {
1242+
switch (codec->type) {
12411243
case AVMediaType::AVMEDIA_TYPE_VIDEO:
12421244
c->codec_id = codec_id;
12431245

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

13211323
/* video output */
@@ -1335,7 +1337,7 @@ cmpc::AVFrame* cmpc::CMpegServer::__alloc_picture(enum AVPixelFormat pix_fmt, in
13351337
return picture;
13361338
}
13371339

1338-
bool cmpc::CMpegServer::__open_video(AVCodec* codec, AVDictionary* opt_arg) {
1340+
bool cmpc::CMpegServer::__open_video(const AVCodec* codec, const AVDictionary* opt_arg) {
13391341
int ret;
13401342
auto c = PStreamContex.enc;
13411343
AVDictionary* opt = nullptr;
@@ -1987,7 +1989,7 @@ bool cmpc::CMpegServer::FFmpegSetup() {
19871989
cerr << "Have not get necessary and correct configurations, so FFmpegSetup() should not be called." << endl;
19881990
return false;
19891991
}
1990-
AVCodec* video_codec = nullptr;
1992+
const AVCodec* video_codec;
19911993
int ret;
19921994

19931995
if (Ppacket)
@@ -2034,13 +2036,17 @@ bool cmpc::CMpegServer::FFmpegSetup() {
20342036
/* Add the audio and video streams using the default format codecs
20352037
* and initialize the codecs. */
20362038
if (fmt->video_codec != AVCodecID::AV_CODEC_ID_NONE) {
2037-
if (!__add_stream(&video_codec)) {
2039+
video_codec = __add_stream();
2040+
if (!video_codec) {
20382041
FFmpegClose();
20392042
return false;
20402043
}
20412044
else
20422045
__have_video = true;
20432046
}
2047+
else {
2048+
video_codec = nullptr;
2049+
}
20442050

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

Diff for: MpegCoder/MpegStreamer.h

+2-2
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+
const AVCodec* __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(const AVCodec* 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);

Diff for: README.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The following instructions are used for building the project on Windows with Vis
3232

3333
We strongly suggest that users should also install the python dependencies (optional):
3434

35-
```shell
35+
```shell
3636
python -m pip install -r requirements.txt
3737
```
3838

@@ -42,23 +42,23 @@ The following instructions are used for building the project on Windows with Vis
4242
```shell
4343
mkdir -p /apps
4444
chmod +rwx /apps
45-
curl -O https://raw.githubusercontent.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/deps/install-ffmpeg-4_4.sh
46-
chmod +rwx install-ffmpeg-4_4.sh
47-
./install-ffmpeg-4_4.sh
45+
curl -O https://raw.githubusercontent.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/deps/install-ffmpeg-5_0.sh
46+
chmod +rwx install-ffmpeg-5_0.sh
47+
./install-ffmpeg-5_0.sh --all --nvcuda
4848
```
4949

5050
After running this script, the FFMpeg with most of the dependencies would be complied along with the shared libraries. Then you could replace the FFMpeg path in the `setup.py` by
5151

5252
```python
53-
FFMPEG_DIR = '/apps/build/ffmpeg-4.4'
53+
FFMPEG_DIR = '/apps/build/ffmpeg-5.0'
5454
```
5555

56-
* Download the pre-built dependencies. These dependencies are built by myself. You could download the archive [here :package:](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/deps-3.0.0/dep-linux-ffmpeg_4_4.tar.xz). The files need to be extracted to `./dependencies`:
56+
* Download the pre-built dependencies. These dependencies are built by myself. You could download the archive [here :package:](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/deps-3.2.0/dep-linux-ffmpeg_5_0.tar.xz). The files need to be extracted to `./dependencies`:
5757

5858
```shell
5959
cd FFmpeg-Encoder-Decoder-for-Python
6060
mkdir -p dependencies
61-
wget -O- https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/deps-3.0.0/dep-linux-ffmpeg_4_4.tar.xz | tar xJ -C "./dependencies"
61+
wget -O- https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/deps-3.2.0/dep-linux-ffmpeg_5_0.tar.xz | tar xJ -C "./dependencies"
6262
```
6363

6464
* The dependencies could be also downloaded by the automatic script, you just need to run
@@ -75,20 +75,20 @@ The following instructions are used for building the project on Windows with Vis
7575
python setup.py build
7676
```
7777

78-
5. Rename the built module as `mpegCoder.so`, then you could import it in the same directory. If you have built FFMpeg by our script, you do not need any other dependencies when importing the libs. However, if not, you may need to download [the lib dependencies :package:](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/deps-3.0.0/so-linux-ffmpeg_4_4.tar.xz) and add the `lib` folder to your `LD_LIBRARY_PATH`:
78+
5. Rename the built module as `mpegCoder.so`, then you could import it in the same directory. If you have built FFMpeg by our script, you do not need any other dependencies when importing the libs. However, if not, you may need to download [the lib dependencies :package:](https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/deps-3.2.0/so-linux-ffmpeg_5_0.tar.xz) and add the `lib` folder to your `LD_LIBRARY_PATH`:
7979

8080
```shell
81-
mkdir -p /apps/ffmpeg-4.4
82-
cd /apps/ffmpeg-4.4
83-
wget -O- https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/deps-3.0.0/so-linux-ffmpeg_4_4.tar.xz | tar xJ -C "."
84-
echo "export LD_LIBRARY_PATH=/apps/ffmpeg-4.4/lib:\$LD_LIBRARY_PATH" >> ~/.bashrc
85-
export LD_LIBRARY_PATH=/apps/ffmpeg-4.4/lib:$LD_LIBRARY_PATH
81+
mkdir -p /apps/ffmpeg-5.0
82+
cd /apps/ffmpeg-5.0
83+
wget -O- https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/releases/download/deps-3.2.0/so-linux-ffmpeg_5_0.tar.xz | tar xJ -C "."
84+
echo "export LD_LIBRARY_PATH=/apps/ffmpeg-5.0/lib:\$LD_LIBRARY_PATH" >> ~/.bashrc
85+
export LD_LIBRARY_PATH=/apps/ffmpeg-5.0/lib:$LD_LIBRARY_PATH
8686
```
8787

8888
6. Running `mpegCoder` requires `GLIBC>=2.29`. This requirement is not satisfied in some cases. However, if you have built FFMpeg by our script, the requirement would be fulfilled (i.e. you could skip this step). If users are using our pre-built dependencies, users may need to solve this problem by
8989

9090
```shell
91-
ln -sf /apps/ffmpeg-4.4/lib-fix/libm-2.31.so /lib/x86_64-linux-gnu/libm.so.6
91+
ln -sf /apps/ffmpeg-4.4/lib-fix/libm-2.35.so /lib/x86_64-linux-gnu/libm.so.6
9292
```
9393

9494
## Update reports
@@ -97,15 +97,15 @@ Has been moved to [:bookmark_tabs: CHANGELOG.md](./CHANGELOG.md)
9797

9898
## Version of currently used FFmpeg library
9999

100-
Current FFMpeg version is `4.4`.
100+
Current FFMpeg version is `5.0`.
101101

102102
| Dependency | Version |
103103
| :-------------: | :------------: |
104-
| `libavcodec` | `58.134.100.0` |
105-
| `libavformat` | `58.76.100.0` |
106-
| `libavutil` | `56.70.100.0` |
107-
| `libswresample` | `3.9.100.0` |
108-
| `libswscale` | `5.9.100.0` |
104+
| `libavcodec` | `59.18.100.0` |
105+
| `libavformat` | `59.16.100.0` |
106+
| `libavutil` | `57.17.100.0` |
107+
| `libswresample` | `4.3.100.0` |
108+
| `libswscale` | `6.4.100.0` |
109109

110110
[git-master]:https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python "master (windows)"
111111
[exp1]:https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python/tree/example-client-check "check the client"

Diff for: requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
urllib3>=1.26.6
22
tqdm>=4.50.0
33
setuptools>=50.3.2
4-
numpy>=1.18.5
4+
numpy>=1.19.5

0 commit comments

Comments
 (0)