FFmpeg mpegCoder for Python
Instruction of this version
In the master
branch, we provide both the codes of VS (Win ver.) and those for g++ (Linux ver.). You need extra libraries to compile this project:
Windows
We use Visual Studio (VS) Community 2017 to compile this project.
After extracting the source-code
, you need to extract the attached package ffmpeg-dependency-win
in the root folder. The arranged file struct should be like this:
.
|-- docs # doc files of master branch
|-- include # included .h files of ffmpeg
|-- lib # libraries of ffmpeg
|-- MpegCoder # source code folder of Windows
|-- MpegCoder_LinuxVer # source code folder of Linux (not necessary in this platform)
| |-- MpegCoder # source code folder
| `-- setup.py # compile script
`-- MpegCoder.sln # the solution file of VS 2017
Then you may open the .sln
project and redirect the path of libraries of Python 3.5 & numpy 1.13 in settings. After that, could could compile this project successfully.
Linux
You only need the sub-folder MpegCoder_LinuxVer
in the source codes as what we describe in Win compile instructions. It should contain:
MpegCoder_LinuxVer # source code folder of Linux
|-- MpegCoder # source code folder
`-- setup.py # compile script based on python3
Because I would not provide dependency here (you could use newer version of ffmpeg to compile this project), you need to clone and compile the ffmpeg as the follow 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
-
Revise the paths defined in
setup.py
, especially that ofFFMPEG_DIR
. You need to redirect the path to where your codes are built (generally inffmpeg/host
). Certainly, you also need the revise the other paths like that ofPython3.5
. -
You could find the
.so
files inffmpeg/host/lib
. These files are depending dynamic libraries of our project. Now you could compile this project.
Update Report
ver 1.8 update report
Add source codes and instructions of compile this project.
ver 1.8 creation report
In this version, we have such improvements:
-
Provide options (widthDst, heightDst) to let MpegDecoder could control the output size manually. To ensure the option is valid, we must use the method
setParameter
before 'FFmpegSetup'. 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.