Skip to main content

A video cropping tool for artists that detects an object, finds the average center pixel of the bounding box, and crops out from center without a decrease in video quality.

Project description

Perfect Crop

Perfect Crop will locate a detected object within a video clip, find its average location, and create a cropped clip from the center. Object detection models splice videos into individual frames & then run detection on static images - Perfect Crop transmutes this into workable video.

This tool is most useful when used on large clip sets (200+). It was built for the quick processing of over 50 hours of live-stream footage!

As a test example, searching the video for "cell phone":

Source Clip Detected Object

Perfect Crop's algorithm was built around Hugging Face's hustvl/yolo sets, a series of vision transformer models trained on the COCO dataset. It's computationally light on any system. At the moment, the algorithm is set only for models using YOLO bounding box annotations - so if you want to swap out the model, keep that in mind.

Calculating the center pixel of a bounding box requires backward engineering of detection algorithms - I'm excited to release support for other annotations in v2.


Perfect Crop can also label scenes with content and object locations, as well as index a video & splice it into individual scenes without quality loss.

perfectcrop accepts the following inputs:

  -p   [video or directory]    | crop a video or directory of clips to select label (runs perfect_crop.py)

  -s   [video]                 | create .json file identifying shots (scene changes) in a long form video. shots.py will then splice the video into individual clips (or scenes).
  
  -vs  [video or directory]    | standardizes video length, codecs, etc. with ffmpeg bash. needed for concatenation!
  
  -g   [video or directory]    | creates a dynamic, randomized moving video grid with ffmpeg bash commands. this is a legacy file from Court Laureate, not necessary for the project itself :)

Due to the sensitive nature of working with video, Perfect Crop does not currently support multiple command line options. Please note that perfectcrop -s needs to be run in the same directory as the source video for shot splicing to occur.

potential errors:

  * global loadsave ->   thankfully, this is harmless and most often caused by minute differences in codecs or issues with local reading. I'll hide it.
  * video not found ->   please check permissions, you can do this by running ls -al on the directory & open with chmod commands.
  * file limit hit  ->   grid specific error. please run 'ulimit -n' in terminal to see your current limit, then ulimit -n [whatever] to increase the size to whatever you see fit. please note that this is isolated to your terminal window.

Made for Court Laureate, a short film screened at LARPA, December 2023, NY NY. Although one cannot patent an algorithm, please respect the open-source nature of this project & all derivatives.

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

perfectcrop-1.1.1.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

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

perfectcrop-1.1.1-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file perfectcrop-1.1.1.tar.gz.

File metadata

  • Download URL: perfectcrop-1.1.1.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for perfectcrop-1.1.1.tar.gz
Algorithm Hash digest
SHA256 3946be17babde08087ff7f27d25e81188a07f50b4d0edb7da6ecf9ba90c7b0a6
MD5 5427ebf88a505b5917477716dbec9326
BLAKE2b-256 a159c3e2fd6deb1bfc4cd2e0a7dd79cb2a2c211cf70e281a28c893cf91b86b32

See more details on using hashes here.

File details

Details for the file perfectcrop-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: perfectcrop-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for perfectcrop-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bf2b004e4c9005e8e9953e965b746744784b3129ae106fe1af0f528b4629bdcd
MD5 6491323499c7b8f81c3c6c72eb35b898
BLAKE2b-256 255a3c984bc77c84bc26c167e0811ac9a141ed4bc5be14fb41bcff99d2ab1d6c

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