Skip to main content

Digitized VHS Cassette Editing with Python

Project description

pyvhs

PyPI version

PyVHS is a Python library developed for editing of digitized VHS cassettes. This repository contains the PyVHS source code.

Introduction  •  Installation  •  Usage  •  Documentation  •  Issues  •  References

Introduction

PyVHS provides simple APIs/functions/methods to work with removing "blank" segments of digitized video files. When digitizing Video Home System (VHS) cassettes it is very common to have several segments of "blank" tape. The blank segments are portions of tape that have no recorded content. Typically, when recording on tape end users would start recording new content after passing the previous recordings on the tape. This ensured that content was not being overwritten. Also, its very common that the end of a tape is blank because it was never utilized by an end user (i.e., they didn't use all the tape).

This causes an issue, which is when digitizing VHS cassettes this can lead to several portions of blank segments that need be removed to: 1) reduce file size and 2) remove unwanted blank screens. It is also annoying when there are multiple tapes that have been digitized and the blank segments need to be removed.

An illustration of this issue is shown below for a single VHS cassette. PyVHS will remove the blank segments from the digitized film.

playback

PyVHS allows a user to:

  • remove the "Blank" segments (e.g., Blank #1 and Blank #2) from video files,
  • automatically remove blank segments from a single or multiple video files,
  • save new video file(s) which will have a smaller file size,
  • save new video files(s) with only footage and no more boring blank screens,
  • execute using either the command-line interface (CLI), Python scripts, or Jupyter Notebooks.

NOTE: The original digitized video files are not altered with PyVHS.

A primary benefit of this package is that there is no need to manually remove blank segments from the digitized videos. This saves lots of time especially if there are multiple video files.

Installation

pip

Available on PyPI

pip install pyvhs

Git Clone

Download the GitHub repository, create a Python Virtual Environment, and pip install PyVHS

git clone https://github.com/mddunlap924/PyVHS.git
cd PyVHS
python3 -m venv .venv
pip install .

For other dependency management tool, please visit

Usage

Use PyVHS as a command line tool from the terminal

Convert a single video

pyvhs -dir='./video_to_edit/video000.mp4'
File Structure for Editing a Single Video
Note: Set Folder and File Names to Your Choice

Input: video000.mp4
Output: video000_edited.mp4 (with blank segments removed)

├── ./video_to_edit
│   ├── video0.mp4
│   ├── video0_edited.mp4

Convert multiple videos

pyvhs -dir='./videos_to_edit'
File Structure for Editing Multiple Videos
Note: Set Folder and Files Names to Your Choice

Inputs: video000.mp4; video001.mpy; video002.mpy; ...
Outputs: video000_edited.mp4; video001_edited.mpy; video002_edited.mpy; ...

├── ./videos_to_edit
│   ├── video0.mp4
│   ├── video0_edited.mp4
│   ├── video1.mp4
│   ├── video1_edited.mp4
│   ├── video2.mp4
│   ├── video2_edited.mp4
│   ├── ...

Use PyVHS as a library

Refer to the Jupyter Notebook example showing how to edit a single video.

from pyvhs.utils.files import VideosToEdit
from pyvhs.utils.edits import EditVideo

# List video files
videos = VideosToEdit(path=PATH_VIDEO)
videos.list_videos()

# Create a video editing object
video_edit = EditVideo(path_original=videos.original[0],
                       path_edited=videos.edited[0],
                       templates=template_imgs,
                       interval=3,
                       )
print(f'Video Duration: {video_edit.duration:,.2f} seconds')
print(f'Check Video Frames Every: {video_edit.interval:,} seconds')

Documentation

PyVHS utilizes the excellent MoviePy library for video operations. Additional image processing was built into PyVHS to handle the unique requirements of editing digitized VHS video is described in the below section.

Identifying Blank Segments

Blank segments of a video are identified based on the images placed in the pyvhs/template_imgs folder. Users are welcomed to add as many images as they want within this directory. Based on my current experience of converting VHS cassettes to mp4 files there were two primary blank images found in the videos. These two images are shown below:

Example of Blank Images to Identify

playback playback

PyVHS identifies blank segments by taking an image (i.e., frame) from a video file at one second intervals across the entire video file. Every frame, taken at one second intervals, are compared to the template images. If at least 2 seconds of template images are found then that portion of video will be flagged as a blank segment for removal.

Template images are compared to video frames using Structural Similarity Index (SSIM) because this is a computationally fast and decently performing algorithm for image comparison. All operations are performed on a CPU as opposed to needing a high cost GPU. SSIM is implemented using Scikit-Image. This process is optimized to utilize all CPU cores via Python multiprocess.

VHS Cassette Digitization Process

All videos used in the testing of PyVHS were created by following this excellent YouTube tutorial: How to convert VHS videotape to 60p digital video (2023).

Extra Tip/Trick for Digitizing VHS Cassettes: Once everything is setup and the VHS cassette is ready to be digitized you can set a maximum recording time in OBS Studio. The upper recording time for a consumer grade VHS cassette tape is ~6 hours. Therefore, when using OBS Studio set a maximum recording time to 6 hours. This allows a user to walk away from the digitization process while ensuring the entire tape was digitized. A drawback of this approach is if a large segment of blank tape appears then the user is not present to stop the recording. Setting up a maximum record time can cause blank segments to be recorded particularly if the entire VHS cassette was not used/full. This digitization process is ideal when used with PyVHS because the blank segments can now easily be removed for multiple videos.

Issues

This repository is will do its best to be maintained, so if you face any issue please raise an issue or make a Pull Request. :smiley:

References

Liked the work? Please give the repository a :star:!

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

pyvhs-0.1.2.tar.gz (493.3 kB view details)

Uploaded Source

Built Distribution

pyvhs-0.1.2-py3-none-any.whl (71.5 kB view details)

Uploaded Python 3

File details

Details for the file pyvhs-0.1.2.tar.gz.

File metadata

  • Download URL: pyvhs-0.1.2.tar.gz
  • Upload date:
  • Size: 493.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-72-generic

File hashes

Hashes for pyvhs-0.1.2.tar.gz
Algorithm Hash digest
SHA256 39e314d52fe010eb06b650acfe3c0e0ea648dc82fb9aae83338cc96d3a6f8aa0
MD5 be4d8f2fb291f6ba23dc24f45dba2b2e
BLAKE2b-256 c8197a0c1edb901a76e015089346d1b96904a0c594ca821e8e35120d4b300740

See more details on using hashes here.

File details

Details for the file pyvhs-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyvhs-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 71.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-72-generic

File hashes

Hashes for pyvhs-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 811442e70974811cc639cd884b81e3f3c72b299b5aea3907a5e0ab8bde8bd3df
MD5 b1527077416b790aaa0913d2dc18e54b
BLAKE2b-256 7bb16789d0525dca080f5ce8e81ae48f3f76581155d73904051b61de98720005

See more details on using hashes here.

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