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.

files=$(shopt -s nullglob dotglob; echo /etc/OCR/data/*)
if (( ${#files} ))
 sleep 5
 mv /etc/OCR/data/* /etc/OCR/InProgress/
 echo “moved files”
for f in $FILE_OP
 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
 while [ $i -ge 0 ]
 if [ -a /etc/OCR/InProgress/scan_$i.png ]
 /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 ))
 fi done
 mv /etc/OCR/InProgress/* /etc/OCR/Processed/

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