Code Monkey home page Code Monkey logo

videogrep.sh's Introduction

Videogrep.sh

Search videos for matching words or phrases, and generate a cut-down version in the ~/videogrep_output/ directory, containing only the matching dialogue.

For example, keep only the bits of a video where people say "banana".

Requirements

Dependencies

  • bash - it's a bash script
  • egrep - for finding matches in the subtitles
  • ffprobe for getting video information like dimensions, aspect ratio (in FFMPEG package)
  • bc - for calculating accurate video frame rates
  • mencoder - for creating the generated video
  • mplayer - for playing the generated video

Video requirements

  • Put the videos you want to search, and their subtitle files, in a directory together.
  • The source videos must have accompanying subtitles files, in either .srt or .sub format!
  • The subtitle file names must also match the videos to which they refer.
  • Here's a valid example (videogrep will find the subtitles OK):
./some_vids/my-cool-video-1080p.mp4
./some_vids/my-cool-video-1080p.srt

NOTE: Many YouTube videos have subtitles. You can download YouTube videos and their subtitles using various websites.

Installation

Copy videogrep.sh to a folder in your $PATH.

Usage:

You must give:

  • the input video (must have a matching subtitle file)
  • the search term (can be an egrep regex like one|two|every.*|a whole phrase
videogrep.sh <video-file> <search-term> [padding-start] [padding-end]

Example:

videogrep.sh 'my_videos/owen-jones-meets-jeremy-corbyn-again.mp4' 'parliamentary' 50 85

Note: padding-start and padding-end are in milliseconds.

Produces this output:

Video file:     owen-jones-meets-jeremy-corbyn-again.mp4
Subtitle file:  owen-jones-meets-jeremy-corbyn-again.sub
Search term(s): parliamentary

Speech found:

{8748}{8780}the mind by the parliamentary Labour
{10080}{10134}parliamentary by-elections with
{10619}{10676}throughout the parliamentary party and
{12330}{12381}parliamentary speeches on the budget for
{21950}{22002}firefighting within the parliamentary
{64168}{64202}parliamentary so things will come back


------------------------------------
Creating: /root/videogrep_output/parliamentary__owen-jones-meets-jeremy-corbyn-again.avi
------------------------------------

History

The videogrep.sh script in this repo is based on a shell script from http://activearchives.org/wiki/Videogrep

Improvements I made to the original script:

  • auto detect correct frame rate, dimensions and aspect ratio
  • support regex searches better
  • added ability to add padding around matching dialogue segments (in milliseconds)
  • actually build the cut-down video as a new file, don't just play it

I used this random shell script as inspiration because antiboredom/videogrep didn't work for me. (The ffmpeg supplied by moviepy segfaults, and switching to my local ffmpeg removed all errors, but still didn't produce any output video.)

videogrep.sh's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.