Skip to main content

Extract frames from videos and convert them to images or gifs.

Project description

videoxt

videoxt is a Python library and command-line tool that allows you to convert video frames to images, or create a GIF between two points in a video.

InstallationExamplesCLI optionsUsed by


Installation

git clone https://github.com/gurrutia/videoxt.git

or

pip install https://github.com/gurrutia/videoxt.git

Examples

NOTE: All command-line examples are run from the directory where the video is located. You can run the commands from any directory by specifying the full path to the video.

Example 1: Extract all video frames.

from videoxt.extractors import VideoToImage

vti = VideoToImage("C:/Users/gurrutia/Videos/video.mp4")

vti.extract_images()

Command-line equivalent:

vxt images video.mp4

Example 2: Extract every 30th frame from 50 seconds to the end of the video, save the images as png, resize the frames by 50% and rotate the frames by 180 degrees.

from videoxt.extractors import VideoToImage

vti = VideoToImage(
  "C:/Users/gurrutia/Videos/video.mp4",
  start_time=50,
  capture_rate=30,
  image_format="png",
  resize=0.5,
  rotate=180,
)

vti.extract_images()

Command-line equivalent:

vxt images video.mp4 --start 50 --capture-rate 30 --image-format png --resize 0.5 --rotate 180

Example 3: Create a GIF between 10:10 and 10:12 of the video at 1/4 the video speed, and resize the GIF to 640x480.

from videoxt.extractors import VideoToGIF

vtg = VideoToGIF(
  "C:/Users/gurrutia/Videos/video.mp4",
  start="10:10",
  end="10:12",
  speed=.25,
  dimensions=(640, 480),
)

vtg.create_gif()

Command-line equivalent:

vxt gif video.mp4 --start 10:10 --end 10:12 --speed 0.25 --dimensions 640 480

Command-line options

Options / Shared

Argument                   Description
video_path Path to the video file with the extension. (Required)

Example: C:/Users/gurrutia/Videos/video.mp4
--start-time Specify the video extraction start time, in seconds or as a timestamp in the format HH:MM:SS, H:MM:SS, MM:SS or M:SS.

Example: --start 1:30 or --start 90

Default: the start of the video.
--stop-time Specify the video extraction stop time, in seconds or as a timestamp in the format HH:MM:SS, H:MM:SS, MM:SS or M:SS.

Example: --end 2:00 or --end 120

Default: the end of the video.
--fps Number of frames per second in the video file, overrides the video metadata frames per second. Use this option sparingly and only when the video metadata fps is incorrectly detected.

Example: --fps 30

Default: the video metadata fps.
--dimensions Specify the media output dimensions as space-separated values.

Example: --dimensions 1920 1080

Default: the native video dimensions.
--resize Resize the media output by a factor of n.

Example: --resize 1.5 to increase the media output size by 50%

Default: 1.0, no resize.
--rotate Rotate the media output by 90, 180, or 270 degrees.

Valid rotate values: 0, 90, 180, 270

Example: --rotate 270 to rotate the media counter-clockwise by 90 degrees.

Default: 0, no rotation.
--output-dir Directory to save the media output to.

Example: --output-dir C:/Users/gurrutia/Videos/custom_folder

Default for images: same/directory/as/video/video_frames
Default for gif: same/directory/as/video.
--output-filename Specify the file name of the media output.

Example for images: --output-filname my_images, which will name all the images as my_images_*.jpg where * is the frame number.
Example for gif: --output-filename my.gif

Default for images: video_filename_*.jpg
Default for gif: video_filename.gif
--quiet Disable extraction details in terminal.

Example: --quiet to disable extraction details from being printed.

Default: False
--emoji Enable emoji's in terminal. Added by special request 👍.

Example: --emoji to enable emoji's.

Default: False

Options / Images

Argument                   Description
---capture-rate Capture every nth video frame.

Example: --capture-rate 30 to every 30th frame.

Default: 1, every frame.
--image-format Specify the image format to save the frames as.

Valid image formats: bmp, dib, jpeg, jpg, png, tiff, tif, webp

Example: --image-format png or --image-format .png

Default: jpg

Options / GIF

Argument                   Description
--speed Speed of the GIF animation.

Example: --speed 0.5 to create a GIF at half the video speed.

Default: 1.0, same speed as the video.

Used by

  • Grand St. Settlement (non-profit) filmmaking instructors to gather film stills that aid in constructing lesson plans for their youth workshops. Download workshop example here.

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

videoxt-0.1.0.tar.gz (13.6 kB view hashes)

Uploaded Source

Built Distribution

videoxt-0.1.0-py3-none-any.whl (13.0 kB view hashes)

Uploaded Python 3

Supported by

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