Categories: Linux

Videogrep, how to extract a certain word from a video (or more)

In this post, we’ll see how to use video grep, an idea and a software made by Sam Lavigne.

Everything is well explained in his GitHub repository or on this page, but I think it could be easier to follow some easy steps for people that are not so confident with technology.

Link to Sam blog

This post will also serve as a reminder for me.

Download the videos with YT-DLP

Install YT-DLP with this command:

pip install yt-dlp

We are using YT-DLP to download videos. To do that just write this command with the link to the video or the playlist you want to download.

yt-dlp "https://www.youtube.com/watch?v=gxX8wZpc8ME&list=PLNlAEAan3IFU4UntqHaFtkVY501sF5awP" --sub-langs it --sub-format srt --format mp4 -f 137+140

Create subtitles with Vosk

To generate .srt we need Vosk transcriber, that is a speech to text (STT) open source software (GitHub repo). To install Vosk run

pip install vosk

If the YouTube video doesn’t have subtitles, you can create them with the Vosk speech to text.

The simplest command that you can use is this. It’s going to use the small modell.

vosk-transcriber -l it -i video.mp4 -t srt -o video.srt

If you want a more precise transcription, you can download the full model for your language. At the moment, you need to unzip the model before to use it.

vosk-transcriber -l it -i ./video.mp4 -m /home/ale/Downloads/vosk-model-it-0.22 -o ./video.srt -t srt

In this case, you have to specify where is the full model located. Note that you can transcribe also more videos at the same type, just leave ./ without specifying the name of the video.

If you are transcribing multiple videos with Vosk, in the actual version there is a bug that doesn’t allow spaces into videos.

In this way it will put – instead of spaces in every videos. Run this command once that you are in the folder where your videos are.

rename 's/\s+/-/g' *

Installing and using videogrep

To install videogrep run this.

pip install videogrep

Finally, we can use videogrep. Before cutting a video, it’s interesting to know how many times that word is repeated. To do that, we can use

-n 1

videogrep --input "./video.mp4" -n 1

Once that we know which word (or words!) we want to use we remove -n 1

videogrep --input "./video.mp4" --search 'ciao' -n 1
Alessandro Oppo

Alessandro è un milanese che vorrebbe scappare da Milano, è appassionato di informatica ma vorrebbe vivere senza telefono, è un artigiano eppure vorrebbe robotizzare tutto, impara una cosa e già vorrebbe studiare dell’altro. Autodidatta da sempre, gli piace sbattere la testa finché tutto non funziona come vuole lui, spesso ci riesce anche! Visita il suo blog personale alexoppo.com Il motto che si ripete dentro la testa è: “Se ci sono riusciti gli altri ci posso riuscire anche io”.

Share
Published by
Alessandro Oppo

Recent Posts

Ponti sospesi: cosa abbiamo sbagliato? cosa si potrebbe fare?

Poco prima di Natale ho avuto la fortuna di poter partecipare a un evento chiamato…

4 mesi ago

Siamo quel che facciamo? – racconto breve

Armando quel giorno era particolarmente stanco. Tutto, per quanto andasse bene, sembrava metterlo sotto pressione.…

9 mesi ago

Il limite è sempre la mente – Racconto breve

Armando guardò l’orologio e vide il proprio riflesso sul quadrante bianco. Il riflesso però non…

10 mesi ago

L’ultimo giorno del carcere – Racconto breve

I muri sono muri, lo sono sempre, anche quando le porte sono aperte. Era la…

10 mesi ago

Riflessioni sul carcere

Pochi di noi riflettono sull’esistenza nella nostra società del carcere. Il carcere è la concretizzazione…

11 mesi ago

Come dovremmo dialogare secondo me

Spesso intraprendiamo delle conversazioni e delle chiacchierate piuttosto inconsapevolmente. Voglio dire che non siamo molto…

11 mesi ago