Package: videogrep
VideogrepVideogrep is a command line tool that searches through dialog in video or audio files and makes supercuts based on what it finds. It will recognize.srtor.vttsubtitle tracks, or transcriptions that can be generated with vosk, pocketsphinx, and other tools.ExamplesThe Meta ExperienceAll the instances of the phrase "time" in the movie "In Time"All the one to two second silences in "Total Recall"A former press secretary telling us what he can tell usTutorialSee my blog for a shorttutorial on videogrep and yt-dlp, and part 2, onvideogrep and natural language processing.InstallationVideogrep is compatible with Python versions 3.6 to 3.10.To install:pip install videogrepIf you want to transcribe video or audio, you also need to installvosk:pip install voskNote: the previous version of videogrep supported pocketsphinx for speech-to-text. Vosk seemsmuchbetter so I've added support for it and will likely be phasing out support for pocketsphinx.UsageThe most basic use:videogrep --input path/to/video.mp4 --search 'search phrase'It works with audio too:videogrep --input path/to/audio.mp3 --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/audio file and subtitle file need to have the exact same name, up to the extension.For example,my_movie.mp4andmy_movie.srtwill work, andmy_movie.mp4andmy_movie_subtitle.srtwillnotwork.Videogrep will search for matchingsrtandvttsubtitles, as well asjsontranscript files that can be generated with the--transcribeargument.Options--input [filename(s)] / -i [filename(s)]File or files to use as input. Most video or audio formats should work. If you mix audio and video input files, the resulting output will only be audio.--output [filename] / -o [filename]Name of the file to generate. By default this issupercut.mp4. Any standard video or audio extension will also work. (If you're using audio input or mixed audio and video input and you keep the defaultsupercut.mp4as the output filename, videogrep will automatically change the output tosupercut.mp3)Videogrep will also recognize the following extensions for saving files:.mpv.edl: generates an edl file playable bympv(useful for previews).m3u: media playlist.xml: Final Cut Pro timeline, compatible with Adobe Premiere and Davinci Resolvevideogrep --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 thefragmentsearch if your transcript has word-level timestamps, which will be the case for youtube.vttfiles, 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 / -dShow the search results without making the supercut.--randomize / -rRandomize 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 / -trTranscribe the video/audio usingvosk. This will generate a.jsonfile 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 withpip install vosk.videogrep -i vid.mp4 --transcribe--model [modelpath] / -mo [modelpath]In combination with the--transcribeoption, allows you to specify the path to a vosk model folder to use. Vosk models areavailable herein a variety of languages.videogrep -i vid.mp4 --transcribe --model path/to/model/--export-clips / -ecExports clips as individual files rather than as a supercut.videogrep -i vid.mp4 --search 'whatever' --export-clips--export-vtt / -evExports 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 or audio file.videogrep -i vid.mp4 --ngrams 1Use it as a modulefrom 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 ScriptsAlso see the examples folder for:silence extractionautomatically creating supercutscreating supercuts based on youtube searchescreating supercuts from specific parts of speechcreating supercuts from spacy pattern matching