Using FFmpeg on video subtitle and text extraction…

FFmpeg has been used by Googles YouTube and it is very popular among various developers and multimedia community. FFmpeg is a very fast video and audio converter that can also grab from a live audio/video source. For images we can use ImageMagick to do all sorts of manipulation but for video we’re utilizing FFMPEG. Purpose of this article is to showcase a small demo using FFmpeg to extract text from a video file. But i guess other information is also important like below are the installation steps for Centos:-

And for a complete set of tutorials go to:-

Below is code demo on my local VM:-

I am attaching code for reference too below.

Note: Sleep is added because it is running on file arrival process and don’t want to process partial file therefore the 5 seconds delay.

#!/bin/bash
files=$(shopt -s nullglob dotglob; echo /etc/OCR/data/*)
if (( ${#files} ))
then
 sleep 5
 mv /etc/OCR/data/* /etc/OCR/InProgress/
 echo “moved files”
FILE_OP=/etc/OCR/InProgress/*
for f in $FILE_OP
do
 echo “Processing $f file…”
 ffmpeg -i $f -r 0.3 /etc/OCR/InProgress/scan_%d.png
 # take action on each file. $f store current file name
 #cat $f
 # remove result.txt
 #rm /etc/OCR/InProgress/result.txt
 # convert the pdf to a group of tiffs
i=1
 while [ $i -ge 0 ]
 do
 if [ -a /etc/OCR/InProgress/scan_$i.png ]
 then
 /usr/local/bin/tesseract /etc/OCR/InProgress/scan_$i.png /etc/OCR/InProgress/scan_$i
 # add the text to the result.txt file
 cat /etc/OCR/InProgress/scan_$i.txt >> /etc/OCR/InProgress/result.txt
 rm /etc/OCR/InProgress/scan_$i.txt /etc/OCR/InProgress/scan_$i.png
 i=$(( $i + 1 ))
 else
 i=-100
 fi done
done
 mv /etc/OCR/InProgress/* /etc/OCR/Processed/
fi

You can do pin down your use case with FFmpeg and do various multimedia things easily and fast.