This is a mpegcoder adapted from FFmpeg & Python-c-api. Using it you could get access to processing video easily. Just use it as a common module in python like this.
import mpegCoder
Branch | Description |
---|---|
master π | The source project of mpegCoder , Windows version. |
master-linux π | The source project of mpegCoder , Linux version. |
example-client-check π | A testing project of the online video stream demuxing. |
example-client-player π | A testing project of the simple online video stream player. |
The following instructions are used for building the project on Windows with Visual Studio 2019.
-
Clone the
master
branch which only contains the codes ofmpegCoder
:git clone --single-branch -b master https://github.com/cainmagi/FFmpeg-Encoder-Decoder-for-Python.git
-
Download the FFMpeg dependencies, including
include
andlib
. Users could download dependencies manually by checking the release page π. However, we recommend users to use the following script to get the dependencies quickly:python webtools.py
This script requires users to install
urllib3
. Thetqdm
is also recommended to be installed. -
The following configurations should be set for
All
(both debug and release) andx64
. Open the project byMpegCoder.sln
. Then configure the following paths of the include directories and the library directories. In both configurations, the first item is required to be modified according to your python path, the second item is required to be modified according to your numpy path.Path Screenshot includes
libs
-
Modify the linker configs. We only need to change the item
python3x.lib
according to the python version you have. -
Run the
Release
,x64
build. The built file should be saved asx64\Release\mpegCoder.pyd
. -
The
mpegCoder.pyd
should be used together with the FFMpeg shared libraries, including:avcodec-58.dll avformat-58.dll avutil-56.dll swresample-3.dll swscale-5.dll
-
Fix a severe memory leaking bugs when using
AVPacket
. -
Fix a bug caused by using
MpegClient.terminate()
when a video is closed by the server. -
Support the
MpegServer
. This class is used for serving the online video streams. -
Refactor the implementation of the loggings.
-
Add
getParameter()
andsetParameter(configDict)
APIs toMpegEncoder
andMpegServer
. -
Move
FFMpeg
depedencies and theOutputStream
class to thecmpc
space. -
Fix dependency issues and cpp standard issues.
-
Upgrade to
FFMpeg 4.4
Version. -
Add a quick script for fetching the
FFMpeg
dependencies.
-
Fix a severe bug that causes the memory leak when using
MpegClient
.This bug also exists inMpegDecoder
, but it seems that the bug would not cause memory leak in that case. (Although we have also fixed it now.) -
Upgrade to
FFMpeg 4.0
Version.
-
Fix a bug that occurs when the first received frame may has a PTS larger than zero.
-
Enable the project produce the newest
FFMpeg 3.4.2
version and usePython 3.6.4
,numpy 1.14
.
-
Revise the bug of the encoder which may cause the stream duration is shorter than the real duration of the video in some not advanced media players.
-
Improve the structure of the code and remove some unnecessary codes.
-
Provide a complete version of client, which could demux the video stream from a server in any network protocol.
-
Provide options
(widthDst, heightDst)
to letMpegDecoder
could control the output size manually. To ensure the option is valid, we must use the methodsetParameter
beforeFFmpegSetup
. Now you could use this options to get a rescaled output directly:d = mpegCoder.MpegDecoder() # initialize d.setParameter(widthDst=400, heightDst=300) # noted that these options must be set before 'FFmpegSetup'! d.FFmpegSetup(b'i.avi') # the original video size would not influence the output print(d) # examine the parameters. You could also get the original video size by 'getParameter' d.ExtractFrame(0, 100) # get 100 frames with 400x300
In another example, the set optional parameters could be inherited by encoder, too:
d.setParameter(widthDst=400, heightDst=300) # set optional parameters ... e.setParameter(decoder=d) # the width/height would inherit from widthDst/heightDst rather than original width/height of the decoder.
Noted that we do not provide
widthDst
/heightDst
ingetParameter
, because these 2 options are all set by users. There is no need to get them from the video metadata. -
Optimize some realization of Decoder so that its efficiency could be improved.
Thanks to God, we succeed in this work!
A new version is avaliable for Linux. To implement this tool, you need to install some libraries firstly:
-
python3.5
-
numpy 1.13
If you want, you could install ffmpeg
on Linux: Here are some instructions
-
Check every pack which ffmpeg needs here: Dependency of FFmpeg
-
Use these steps to install ffmpeg instead of provided commands on the above site.
$ git clone https://git.ffmpeg.org/ffmpeg.git $ cd ffmpeg $ ./configure --prefix=host --enable-gpl --enable-libx264 --enable-libx265 --enable-shared --disable-static --disable-doc $ make $ make install
-
Realize the encoder totally.
-
Provide a global option
dumpLevel
to control the log shown in the screen. -
Fix bugs in initialize functions.
- Provide an incomplete version of encoder, which could encode frames as a video stream that could not be played by player.
- Fix a severe bug of the decoder, which causes the memory collapsed if decoding a lot of frames.
- Use numpy array to replace the native pyList, which improves the speed significantly.
- Provide the decoder which could decode videos in arbitrary formats and arbitrary coding.
Current FFMpeg version is 4.4
.
Dependency | Version |
---|---|
libavcodec | 58.134.100.0 |
libavformat | 58.76.100.0 |
libavutil | 56.70.100.0 |
libswresample | 3.9.100.0 |
libswscale | 5.9.100.0 |