|
1 | 1 | # Examples
|
| 2 | + |
| 3 | +## [Get video info](https://github.com/kkroening/ffmpeg-python/blob/master/examples/video_info.py#L15) |
| 4 | + |
| 5 | +```python |
| 6 | +probe = ffmpeg.probe(args.in_filename) |
| 7 | +video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None) |
| 8 | +width = int(video_stream['width']) |
| 9 | +height = int(video_stream['height']) |
| 10 | +``` |
| 11 | + |
| 12 | +## [Convert video to numpy array](https://github.com/kkroening/ffmpeg-python/blob/master/examples/ffmpeg-numpy.ipynb) |
| 13 | + |
| 14 | +```python |
| 15 | +out, _ = ( |
| 16 | + ffmpeg |
| 17 | + .input('in.mp4') |
| 18 | + .output('pipe:', format='rawvideo', pix_fmt='rgb24') |
| 19 | + .run(capture_stdout=True) |
| 20 | +) |
| 21 | +video = ( |
| 22 | + np |
| 23 | + .frombuffer(out, np.uint8) |
| 24 | + .reshape([-1, height, width, 3]) |
| 25 | +) |
| 26 | +``` |
| 27 | + |
| 28 | +## [Generate thumbnail for video](https://github.com/kkroening/ffmpeg-python/blob/master/examples/get_video_thumbnail.py#L21) |
| 29 | +```python |
| 30 | +( |
| 31 | + ffmpeg |
| 32 | + .input(in_filename, ss=time) |
| 33 | + .filter_('scale', width, -1) |
| 34 | + .output(out_filename, vframes=1) |
| 35 | + .run() |
| 36 | +) |
| 37 | +``` |
| 38 | + |
| 39 | +## [Read single video frame as jpeg through pipe](https://github.com/kkroening/ffmpeg-python/blob/master/examples/read_frame_as_jpeg.py#L16) |
| 40 | +```python |
| 41 | +out, _ = ( |
| 42 | + ffmpeg |
| 43 | + .input(in_filename) |
| 44 | + .filter_('select', 'gte(n,{})'.format(frame_num)) |
| 45 | + .output('pipe:', vframes=1, format='image2', vcodec='mjpeg') |
| 46 | + .run(capture_output=True) |
| 47 | +) |
| 48 | +``` |
| 49 | + |
| 50 | +## [Convert sound to raw PCM audio](https://github.com/kkroening/ffmpeg-python/blob/master/examples/transcribe.py#L23) |
| 51 | +```python |
| 52 | +out, _ = (ffmpeg |
| 53 | + .input(in_filename, **input_kwargs) |
| 54 | + .output('-', format='s16le', acodec='pcm_s16le', ac=1, ar='16k') |
| 55 | + .overwrite_output() |
| 56 | + .run(capture_stdout=True) |
| 57 | +) |
| 58 | +``` |
| 59 | + |
| 60 | +## [JupyterLab/Notebook widgets](https://github.com/kkroening/ffmpeg-python/blob/master/examples/ffmpeg-numpy.ipynb) |
| 61 | + |
| 62 | +![Jupyter screenshot]( |
| 63 | + |
| 64 | +<img src="https://raw.githubusercontent.com/kkroening/ffmpeg-python/master/doc/jupyter-screenshot.png" alt="jupyter screenshot" width="75%" /> |
| 65 | + |
0 commit comments