1515 :alt: GitHub Workflow Status
1616
1717Python `ffmpegio ` package aims to bring the full capability of `FFmpeg <https://ffmpeg.org >`__
18- to read, write, and manipulate multimedia data to Python. FFmpeg is an open-source cross-platform
18+ to read, write, probe, and manipulate multimedia data to Python. FFmpeg is an open-source cross-platform
1919multimedia framework, which can handle most of the multimedia formats available today.
2020
21- Since v0.3.0, `ffmpegio ` Python distribution package has been split into `ffmpegio-core ` and `ffmpegio ` to allow
22- Numpy-independent installation.
21+ .. note ::
22+
23+ Since v0.3.0, `ffmpegio ` Python distribution package has been split into `ffmpegio-core ` and `ffmpegio ` to allow
24+ Numpy-independent installation.
2325
2426Install the full `ffmpegio ` package via ``pip ``:
2527
@@ -46,7 +48,8 @@ Main Features
4648* Accepts all FFmpeg options including filter graphs
4749* Supports a user callback whenever FFmpeg updates its progress information file
4850 (see `-progress ` FFmpeg option)
49- * Advanced users can gain finer controls of FFmpeg I/O with `ffmpegio.ffmpegprocess ` submodule
51+ * `ffconcat ` scripter to make the use of `-f concat ` demuxer easier
52+ * I/O device enumeration to eliminate the need to look up device names. (currently supports only: Windows DirectShow)
5053* More features to follow
5154
5255Documentation
@@ -63,6 +66,20 @@ To import `ffmpegio`
6366
6467 >> > import ffmpegio
6568
69+ - `Transcoding <ex_trancode >`__
70+ - `Read Audio Files <ex_read_audio >`__
71+ - `Read Image Files / Capture Video Frames <ex_read_image >`__
72+ - `Read Video Files <ex_read_video >`__
73+ - `Read Multiple Files or Streams <ex_read_media >`__
74+ - `Write Audio, Image, & Video Files <ex_write >`__
75+ - `Filter Audio, Image, & Video Data <ex_filter >`__
76+ - `Stream I/O <ex_stream >`__
77+ - `Device I/O Enumeration <ex_devices >`__
78+ - `Progress Callback <ex_progress >`__
79+ - `Run FFmpeg and FFprobe Directly <ex_direct >`__
80+
81+ .. _ex_trancode :
82+
6683Transcoding
6784^^^^^^^^^^^
6885
@@ -79,6 +96,15 @@ Transcoding
7996 >> > ffmpegio.transcode(' input.avi' , ' output.mkv' , two_pass = True , show_log = True ,
8097 >> > ** {' c:v' :' libx264' , ' b:v' :' 2600k' , ' c:a' :' aac' , ' b:a' :' 128k' })
8198
99+ >> > # concatenate videos using concat demuxer
100+ >> > files = [' /video/video1.mkv' ,' /video/video2.mkv' ]
101+ >> > ffconcat = ffmpegio.FFConcat()
102+ >> > ffconcat.add_files(files)
103+ >> > with ffconcat: # generates temporary ffconcat file
104+ >> > ffmpegio.transcode(ffconcat, ' output.mkv' , f_in = ' concat' , codec = ' copy' , safe_in = 0 )
105+
106+ .. _ex_read_audio :
107+
82108Read Audio Files
83109^^^^^^^^^^^^^^^^
84110
@@ -95,6 +121,8 @@ Read Audio Files
95121 >> > # filter: equalizer which attenuate 10 dB at 1 kHz with a bandwidth of 200 Hz
96122 >> > fs, x = ffmpegio.audio.read(' myaudio.mp3' , t = 10.0 , af = ' equalizer=f=1000:t=h:width=200:g=-10' )
97123
124+ .. _ex_read_image :
125+
98126Read Image Files / Capture Video Frames
99127^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
100128
@@ -125,6 +153,8 @@ Read Image Files / Capture Video Frames
125153 >> > I = ffmpegio.image.read(' myaudio.mp3' , filter_complex = ' showspectrumpic=s=960x540' , pix_fmt = ' rgb24' )
126154
127155
156+ .. _ex_read_video :
157+
128158Read Video Files
129159^^^^^^^^^^^^^^^^
130160
@@ -136,7 +166,9 @@ Read Video Files
136166
137167 >> > # get running spectrogram of audio input (must specify pix_fmt if input is audio)
138168 >> > fs, F = ffmpegio.video.read(' myvideo.mp4' , pix_fmt = ' rgb24' , filter_complex = ' showspectrum=s=1280x480' )
169+
139170
171+ .. _ex_read_media :
140172
141173Read Multiple Files or Streams
142174^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -157,6 +189,8 @@ Read Multiple Files or Streams
157189 >> > # rates: dict of frame rates: keys="v:0" and "v:1"
158190 >> > # data: dict of video frame arrays: keys="v:0" and "v:1"
159191
192+ .. _ex_write :
193+
160194Write Audio, Image, & Video Files
161195^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
162196
@@ -171,7 +205,9 @@ Write Audio, Image, & Video Files
171205 >> > # create an audio file from a numpy array
172206 >> > ffmpegio.audio.write(' myaudio.mp3' , rate, x)
173207
174- Filter Audio, Image, & Video data
208+ .. _ex_filter :
209+
210+ Filter Audio, Image, & Video Data
175211^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
176212
177213.. code-block :: python
@@ -186,6 +222,8 @@ Filter Audio, Image, & Video data
186222 >> > filter = " drawtext=fontsize=30:fontfile=FreeSerif.ttf:text='hello world':x=(w-text_w)/2:y=(h-text_h)/2"
187223 >> > fs_out, F_out = ffmpegio.video.filter(filter , fs_in, F_in)
188224
225+ .. _ex_stream :
226+
189227Stream I/O
190228^^^^^^^^^^
191229
@@ -198,10 +236,28 @@ Stream I/O
198236 >> > for frames in fin:
199237 >> > fout.write(myprocess(frames))
200238
239+ .. _ex_devices :
240+
241+ Device I/O Enumeration
242+ ^^^^^^^^^^^^^^^^^^^^^^
243+
244+ .. code-block :: python
245+
246+ >> > # record 5 minutes of audio from Windows microphone
247+ >> > fs, x = ffmpegio.audio.read(' a:0' , f_in = ' dshow' , sample_fmt = ' dbl' , t = 300 )
201248
202- Progress callback
249+ >> > # capture Windows' webcam frame
250+ >> > with ffmpegio.open(' v:0' , ' rv' , f_in = ' dshow' ) as webcam,
251+ >> > for frame in webcam:
252+ >> > process_frame(frame)
253+
254+ .. _ex_progress :
255+
256+ Progress Callback
203257^^^^^^^^^^^^^^^^^
204258
259+ .. code-block :: python
260+
205261 >> > import pprint
206262
207263 >> > # progress callback
@@ -219,3 +275,34 @@ Progress callback
219275 >> > with ffmpegio.open(' myvideo.mp4' , ' rv' , blocksize = 100 , progress = progress) as fin:
220276 >> > for frames in fin:
221277 >> > myprocess(frames)
278+
279+ .. _ex_direct :
280+
281+ Run FFmpeg and FFprobe Directly
282+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
283+
284+ .. code-block :: python
285+
286+ >> > from ffmpegio import ffmpeg, FFprobe, ffmpegprocess
287+ >> > from subprocess import PIPE
288+
289+ >> > # call with options as a long string
290+ >> > ffmpeg(' -i input.avi -b:v 64k -bufsize 64k output.avi' )
291+
292+ >> > # or call with list of options
293+ >> > ffmpeg([' -i' , ' input.avi' ,' -r' , ' 24' , ' output.avi' ])
294+
295+ >> > # the same for ffprobe
296+ >> > ffprobe(' ffprobe -show_streams -select_streams a INPUT' )
297+
298+ >> > # specify subprocess arguments to capture stdout
299+ >> > out = ffprobe(' ffprobe -of json -show_frames INPUT' ,
300+ stdout = PIPE , universal_newlines = True ).stdout
301+
302+ >> > # use ffmpegprocess to take advantage of ffmpegio's default behaviors
303+ >> > out = ffmpegprocess.run({" inputs" : [(" input.avi" , None )],
304+ " outputs" : [(" out1.mp4" , None ),
305+ (" -" , {" f" : " rawvideo" , " vframes" : 1 , " pix_fmt" : " gray" , " an" : None })
306+ }, capture_log=True )
307+ >> > print (out.stderr) # print the captured FFmpeg logs (banner text omitted)
308+ >> > b = out.stdout # width*height bytes of the first frame
0 commit comments