Skip to main content

A keyframes and ffmpeg iframes extractor

Project description

Quick guide

Installation

pip install video-kf

Usage

Open a command line, or a terminal, from the same directory where your video is located and run:

video-kf "My_video.mp4"

If the command line was open in a different directory from where the video is located, then the full path would be needed.

Extended documentation

Video-kf is a Python package that can be run either from the command line, or from inside Python, by importing it. It extracts the most relevant keyframes of a video, based on different methods.

At the moment, there are 3 methods available:

  • iframes: it extracts the iframes of the video, calculated by ffmpeg. This is the default option.

    Use in the command line:

    video-kf "My_video.mp4"
    

    or

    video-kf "My_video.mp4" -m "iframes"
    

    Use inside Python:

    import videokf as vf
    
    vf.extract_keyframes("My_video.mp4")
    

    or

    import videokf as vf
    
    vf.extract_keyframes("My_video.mp4", method="iframes")
    
  • color: it returns the average frame, based on color, of every shot sequence. Shot sequences are group of frames that start with an iframe.

    Use in the command line:

    video-kf "My_video.mp4" -m "color"
    

    Use inside Python:

    import videokf as vf
    
    vf.extract_keyframes("My_video.mp4", method="color")
    
  • flow: it returns the most still frame with respect of the previous frame of every shot sequence. Shot sequences are group of frames that start with an iframe.

    Use in the command line:

    video-kf "My_video.mp4" -m "flow"
    

    Use inside Python:

    import videokf as vf
    
    vf.extract_keyframes("My_video.mp4", method="flow")
    

Caution

The methods color and flow will download all the frames of the video. Keep in mind that if the video is long, this will take time, as well as space to save the frames.

This is not the case for the method iframes that will only download the iframes.

Use of Ffmpeg and Ffprobe

Video-kf automatically downloads the executable files of ffmpeg and ffprobe and saves them, by default, in a folder called "Ffmpeg" located in your home directory. You can choose to save the executable files in a different location by running:

video-kf "My_video.mp4" -dir "PATH_RO_A_DIFFERENT_LOCATION"

If you already have ffmpeg or ffprobe installed, you can also use your own executable files. There are various ways of doing this, all of them equivalent. Choose the one that best suits you:

  • Using the command line options ffmpeg and ffprobe (you can choose to use just one of the two):

    video-kf "My_video.mp4" -ffmpeg "PATH_TO_FFMPEG" -ffprobe "PATH_TO_FFPROBE"
    
  • Saving ffmpeg and ffprobe as environmental variables named respectively FFMPEG and FFPROBE.

  • Saving manually ffmpeg and ffprobe in the folder called "Ffmpeg", which by default is located in your home directory, and running the program normally (either in the command line or inside python). You can also choose a different directory through the command line with the -dir option

Command line options

positional arguments:
  video_file            Path to the video file to extract the keyframes from.

optional arguments:
  -h, --help            show this help message and exit
  -m METHOD, --method METHOD
                        Method to extract the keyframes
  -o OUTPUT_DIR_KEYFRAMES, --output_dir_keyframes OUTPUT_DIR_KEYFRAMES
                        Directory where to extract keyframes. If it is a
                        string instead of a directory, keyframes will be saved
                        in a folder named as this string, located in the same
                        directory of the video
  -ffmpeg FFMPEG, --ffmpeg FFMPEG
                        Path to the Ffmpeg executable
  -ffprobe FFPROBE, --ffprobe FFPROBE
                        Path to the Ffprobe executable
  -dir DIR_FFMPEG_FFPROBE, --dir_ffmpeg_ffprobe DIR_FFMPEG_FFPROBE
                        Path to the directory containing both Ffmpeg and
                        Ffprobe executables
  --no-frames-rm        If present, this option will NOT remove the directory
                        with the extracted frames, if they were extracted
                        (only for 'color' and 'flow' methods)

References

FFmpeg Developers. (2016). Ffmpeg tool [Software]. Available from http://ffmpeg.org/

Binaries obtained from: https://ffbinaries.com/readme

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

video-kf-0.0.4.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

video_kf-0.0.4-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file video-kf-0.0.4.tar.gz.

File metadata

  • Download URL: video-kf-0.0.4.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for video-kf-0.0.4.tar.gz
Algorithm Hash digest
SHA256 79e97bf7e4c198a44d14308bfedd2d928efaeb11aea8bad0c863c71aa9e22c6e
MD5 ebc95d3109aa57934ecb824035304f55
BLAKE2b-256 33a33b8fedd070546bca913a5adf92b148f3919986c5aa330de734f126d21f1a

See more details on using hashes here.

File details

Details for the file video_kf-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: video_kf-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for video_kf-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f016a3e961f5ca9b6d7c8ea096d8f276f679d73f6c38fca0d337e4362cb5c562
MD5 c536fcfb2580626b68112c9e6fa67056
BLAKE2b-256 d51cfc162359e5c546dd2ea66f43494465c733451b24483e382aa5618d1fcd2e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page