• Stars
    star
    3,186
  • Rank 14,008 (Top 0.3 %)
  • Language
    Python
  • License
    Other
  • Created over 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

automatic video supercuts with python

Videogrep

Videogrep is a command line tool that searches through dialog in video files and makes supercuts based on what it finds. It will recognize .srt or .vtt subtitle tracks, or transcriptions that can be generated with vosk, pocketsphinx, and other tools.

Examples

Tutorial

See my blog for a short tutorial on videogrep and yt-dlp, and part 2, on videogrep and natural language processing.


Installation

Videogrep is compatible with Python versions 3.6 to 3.10.

To install:

pip install videogrep

If you want to transcribe videos, you also need to install vosk:

pip install vosk

Note: the previous version of videogrep supported pocketsphinx for speech-to-text. Vosk seems much better so I've added support for it and will likely be phasing out support for pocketsphinx.

Usage

The most basic use:

videogrep --input path/to/video --search 'search phrase'

You can put any regular expression in the search phrase.

NOTE: videogrep requires a matching subtitle track with each video you want to use. The video file and subtitle file need to have the exact same name, up to the extension. For example, my_movie.mp4 and my_movie.srt will work, and my_movie.mp4 and my_movie_subtitle.srt will not work.

Videogrep will search for matching srt and vtt subtitles, as well as json transcript files that can be generated with the --transcribe argument.

Options

--input [filename(s)] / -i [filename(s)]

Video or videos to use as input. Most video formats should work.

--output [filename] / -o [filename]

Name of the file to generate. By default this is supercut.mp4. Any standard video extension will also work.

Videogrep will also recognize the following extensions for saving files:

  • .mpv.edl: generates an edl file playable by mpv (useful for previews)
  • .m3u: media playlist
  • .xml: Final Cut Pro timeline, compatible with Adobe Premiere and Davinci Resolve
videogrep --input path/to/video --search 'search phrase' --output coolvid.mp4

--search [query] / -s [query]

Search term, as a regular expression. You can add as many of these as you want. For example:

videogrep --input path/to/video --search 'search phrase' --search 'another search' --search 'a third search' --output coolvid.mp4

--search-type [type] / -st [type]

Type of search you want to perform. There are two options:

  • sentence: (default): Generates clips containing the full sentences of your search query.
  • fragment: Generates clips containing the exact word or phrase of your search query.

Both options take regular expressions. You may only use the fragment search if your transcript has word-level timestamps, which will be the case for youtube .vtt files, or if you generated a transcript using Videogrep itself.

videogrep --input path/to/video --search 'experience' --search-type fragment

--max-clips [num] / -m [num]

Maximum number of clips to use for the supercut.

--demo / -d

Show the search results without making the supercut.

--randomize / -r

Randomize the order of the clips.

--padding [seconds] / -p [seconds]

Padding in seconds to add to the start and end of each clip.

--resyncsubs [seconds] / -rs [seconds]

Time in seconds to shift the shift the subtitles forwards or backwards.

--transcribe / -tr

Transcribe the video using vosk. This will generate a .json file in the same folder as the video. By default this uses vosk's small english model.

NOTE: Because of some compatibility issues, vosk must be installed separately with pip install vosk.

videogrep -i vid.mp4 --transcribe

--model [modelpath] / -mo [modelpath]

In combination with the --transcribe option, allows you to specify the path to a vosk model folder to use. Vosk models are available here in a variety of languages.

videogrep -i vid.mp4 --transcribe --model path/to/model/

--export-clips / -ec

Exports clips as individual files rather than as a supercut.

videogrep -i vid.mp4 --search 'whatever' --export-clips

--export-vtt / -ev

Exports the transcript of the supercut as a WebVTT file next to the video.

videogrep -i vid.mp4 --search 'whatever' --export-vtt

--ngrams [num] / -n [num]

Shows common words and phrases from the video.

videogrep -i vid.mp4 --ngrams 1

Use it as a module

from videogrep import videogrep

videogrep('path/to/your/files','output_file_name.mp4', 'search_term', 'search_type')

The videogrep module accepts the same parameters as the command line script. To see the usage check out the source.

Example Scripts

Also see the examples folder for:

More Repositories

1

audiogrep

Creates audio supercuts.
Python
962
star
2

ffmpeg-explorer

Create and render complex ffmpeg filtergraphs in the browser.
Svelte
415
star
3

patent-generator

Transforms literary/philosophical texts into patent applications
Python
352
star
4

p5.riso

A p5js library for risograph printing by Sam Lavigne and Tega Brain.
JavaScript
299
star
5

zoom-escaper

a simple tool to help you escape zoom meetings by making your presence unbearable to others
Vue
197
star
6

vidpy

video editing and compositing with python and melt
Python
127
star
7

camera-motion-detector

Uses opencv to detect when a camera is panning or zooming.
Python
92
star
8

sfpc-scrapism

7-week class at SFPC, Fall 2018
Python
84
star
9

scrapism-spring-2022

Python
84
star
10

p5.gif.js

let's you play gifs in p5
JavaScript
83
star
11

scrapism

a work-in-progress guide to web scraping as an artistic and critical practice
Python
78
star
12

flickr-scrape

Python
63
star
13

automating-video-itp

A 6 week class at ITP NYU
61
star
14

p5.patgrad

a p5.js library for adding gradients and repeating patterns to your sketches
JavaScript
58
star
15

prison_fax

Python
57
star
16

p5.vscode

A VS Code extension to generate new p5.js project files.
TypeScript
53
star
17

detourning-the-web

Syllabus and example code for 7-week class at NYU/ITP
Python
47
star
18

zoom-deleter

deletes zoom and prevents you from reinstalling it
Go
44
star
19

detourning-the-web-2018

Python
39
star
20

infinite-video-fall-2023

Syllabus and materials for "Infinite Video" a 10-week course at the School for Poetic Computation
Python
38
star
21

servi.js

JavaScript
36
star
22

automating-video

Two-day workshop for SFPC
30
star
23

scrapism-fall-2022

Syllabus for Scrapism @ SFPC / Fall 2022
Python
27
star
24

internet-as-form

JavaScript
27
star
25

other-orders

experiments in sorting
Python
25
star
26

sfpc-scrapism-spring-2019

Python
22
star
27

enron-email-archive

The front end for http://archive.enron.email
CSS
18
star
28

autotv

Automatically generated television (draft)
Python
18
star
29

servi-ide

JavaScript
15
star
30

slow-hot-computer

makes your computer slow, and hot, so you can be less productive.
JavaScript
15
star
31

get-well-soon

code for "Get Well Soon"
Python
13
star
32

mask-generator

Generates masks you can print out, cut and wear from images of faces.
Python
13
star
33

youtubegrep

makes supercuts from youtube searches (alpha)
Python
12
star
34

interrogating-dating-pioneer-works

11
star
35

semantic-searcher

command line semantic text search tool
Python
11
star
36

stupidhackathon

stupid shit no one needs and terrible ideas hackathon
HTML
10
star
37

LazyCoin

A new currency that stores non-value.
TeX
10
star
38

websocket-p5

JavaScript
9
star
39

AynRandom

ayn random twitter bot
Python
9
star
40

portfolio-generator

Python
9
star
41

automating-video-lang

8
star
42

webscrape_tutorial

Python
8
star
43

new-york-apartment

Python
6
star
44

processing.riso

Java
6
star
45

videogrep-gui

Python
6
star
46

noflyzone

Python
5
star
47

code-poetry-2017

5
star
48

stocktalk

Generate video/gif messages using stock footage
JavaScript
5
star
49

dynamicweb-2017

HTML
5
star
50

p5-ide

an IDE for p5.js
JavaScript
4
star
51

supercut-sonic-acts-workshop

Supercut workshop for Sonic Acts, June 2022
4
star
52

videosonnet

Processing
4
star
53

creatures

JavaScript
4
star
54

p5-gif-example

A simple example showing how to save animated gifs from p5.js sketches
JavaScript
3
star
55

piplayer

A (relatively) simple utility for setting up a raspberry pi as a video player.
Python
3
star
56

inventories-lists-catalogs

2-day workshop at Pioneer Works
3
star
57

zuckify

zuckifies things
JavaScript
3
star
58

occupied-bnb

code and resources for https://lav.io/occupied_bnb
HTML
3
star
59

popcorn-exporter

python server that creates mp4s from popcorn js compositions
Python
3
star
60

p5_tutorial

processing to p5.js examples
JavaScript
3
star
61

streeteasy-scrape

scrape streeteasy with selenium
Python
3
star
62

contract_generator

transform literary texts into legal contracts
Python
3
star
63

yt-vid-grid

JavaScript
3
star
64

yale-vid-workshop-2024

Python
3
star
65

voice_puppet

Python
3
star
66

vidquery

Python
3
star
67

smelldating

HTML
2
star
68

darkgenius

text annotation
JavaScript
2
star
69

scenegraphhh

C++
2
star
70

the-capitalist-gene

HTML
2
star
71

carbon-offset-scraper

Python
2
star
72

onhell

HTML
2
star
73

synthetic-messenger-performance

CSS
2
star
74

climate-clock

Python
2
star
75

notes-on-police-funding

Jupyter Notebook
2
star
76

greetings

Greetings Fellow Alienated Subject of Late Capitalism
HTML
2
star
77

snail-chat-4

JavaScript
2
star
78

waves

JavaScript
2
star
79

offset-archive

An archive of carbon credit schemes and sales
Jupyter Notebook
1
star
80

creative-ml-fall-2024

1
star
81

webdev-2017

CSS
1
star
82

oddjobs

HTML
1
star
83

text-masher

Python
1
star
84

ffx9subs

Python
1
star
85

case-study

A tool for the military to analyze literary and philosophical texts
JavaScript
1
star
86

baabaa

JavaScript
1
star
87

interaction1-spring2020

HTML
1
star
88

goldstein-lit

analyzes literature using the goldstein scale
JavaScript
1
star
89

internet-as-form-2020

HTML
1
star
90

scraping-text-workshop

Python
1
star
91

suspicious-camera

A camera rig with personality
Processing
1
star
92

creepy-controller

a processing sketch to control axis cameras
Processing
1
star