Skip to content

sajalkmr/frames-from-videos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

frames-from-videos

Extract Video Frames with Subtitles using ffmpeg

A Python script to extract frames from video files and burn subtitles into the video using the ffmpeg library.


Sample Output

Below is an example of output and a frame extracted with subtitles from a video file using this script:

Sample Output frame

How to Run

To run this script, follow the steps below:

  1. Install ffmpeg. Instructions can be found here.
  2. Python need to be insatlled and added to path.
  3. Download or clone this repository to your local machine.
  4. Open a terminal or command prompt and navigate to the root directory of the downloaded repository.
  5. Put your video files in .mkv or .mp4 format in the same directory.
  6. Run the following command: python frames.py
  7. The extracted frames with subtitles will be saved in the "frames_output" folder.

How it works

The Python script, frames.py, performs the following steps:

  1. Defines the input and output folder paths. The input folder is set to the current working directory, and the output folder is set to a new subdirectory called "frames_output" under the current working directory.
  2. Creates the output folder if it does not already exist.
  3. Iterates over each file in the input folder that has a .mkv or .mp4 extension.
  4. Creates a new subdirectory under the output folder with the same name as the input video file (without the extension).
  5. Calls ffmpeg as a subprocess to extract frames from the video file, burn subtitles into the video using the specified font size, font name, and primary color, and save the resulting frames as .jpg files in the new subdirectory.
  6. The output frames are saved with a filename format of 3 digits, padded with leading zeros, starting from 001, and increasing by 1 for each subsequent frame. The frame rate is set to 0.3 frames per second, and the video quality is set to a constant rate factor (CRF) of 23. The video quality is set to a value of 1 to preserve the original quality.

Dependencies

The script depends on the following:

  • Python 3
  • ffmpeg

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

Get frames from video including subtitles

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages