[FFmpeg-user] how to use ocr in ffmpeg to produce text message

DopeLabs dopelabs at dubstep.fm
Sat Jun 30 08:26:37 EEST 2018


A non-text attachment was scrubbed...
Name: ocr_in.png
Type: image/png
Size: 15213 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-user/attachments/20180629/b08633b6/attachment.png>
-------------- next part --------------


ffprobe -show_entries frame_tags=lavfi.ocr.text -f lavfi -i "movie=ocr_in.png,ocr"  > ocr.txt

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ocr.txt
URL: <http://ffmpeg.org/pipermail/ffmpeg-user/attachments/20180629/b08633b6/attachment.txt>
-------------- next part --------------


ffmpeg -f lavfi -i "color=black:s=1536x199,drawtext=fontfile=/Users/dopelabs/helvetica_bold.ttf:fontsize=24:fontcolor=white:textfile=ocr.txt" -frames 1 ocr_out.png


-------------- next part --------------
A non-text attachment was scrubbed...
Name: ocr_out.png
Type: image/png
Size: 11785 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-user/attachments/20180629/b08633b6/attachment-0001.png>
-------------- next part --------------



cheers =]


> On Jun 29, 2018, at 11:50 33AM, Paul B Mahol <onemda at gmail.com> wrote:
> 
> On 6/29/18, qw <applemax82 at 163.com> wrote:
>> Hi,
>> 
>> 
>> ocr is new in ffmpeg 4.0.
>> 
>> 
>> 1)
>> I build ffmpeg 4.0 and its tesseract-3.05.01, and copy english training data
>> to /usr/local/share/tessdata/eng.traineddata.
>> 
>> 
>> I use the following command to run ocr filter in ffmpeg, but fail to find
>> eng.traineddata. But I have set TESSDATA_PREFIX:
>> TESSDATA_PREFIX=/usr/local/share LD_LIBRARY_PATH=/usr/local/lib
>> /usr/local/bin/ffmpeg -f lavfi -i "movie=test_ocr.png,
>> ocr=datapath=tessdata:language=eng, drawgraph=lavfi.ocr.text"
>> test_ocr_out.png
>> 
>> 
>> ffmpeg version 4.0 Copyright (c) 2000-2018 the FFmpeg developers
>>  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-16)
>>  configuration: --enable-version3 --enable-asm --enable-x86asm
>> --enable-avfilter --disable-static --enable-shared --enable-gpl
>> --enable-nonfree --prefix=/usr/local/ --enable-libvidstab --enable-libass
>> --enable-libfreetype --extra-libs=-lfreetype --enable-libtesseract
>> --enable-libfdk_aac --enable-libmp3lame --enable-libx264
>> --enable-libopenjpeg --enable-libwebp --enable-libx265 --enable-libvorbis
>> --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib
>> --enable-stripping --enable-libmfx
>>  libavutil      56. 14.100 / 56. 14.100
>>  libavcodec     58. 18.100 / 58. 18.100
>>  libavformat    58. 12.100 / 58. 12.100
>>  libavdevice    58.  3.100 / 58.  3.100
>>  libavfilter     7. 16.100 /  7. 16.100
>>  libswscale      5.  1.100 /  5.  1.100
>>  libswresample   3.  1.100 /  3.  1.100
>>  libpostproc    55.  1.100 / 55.  1.100
>> Error opening data file /tessdata/eng.traineddata
>> Please make sure the TESSDATA_PREFIX environment variable is set to the
>> parent directory of your "tessdata" directory.
>> Failed loading language 'eng'
>> Tesseract couldn't load any languages!
>> [Parsed_ocr_1 @ 0x1e03d80] failed to init tesseract
>> [lavfi @ 0x1df77c0] Error initializing filter 'ocr' with args
>> 'datapath=tessdata:language=eng'
>> movie=test_ocr.png, ocr=datapath=tessdata:language=eng,
>> drawgraph=lavfi.ocr.text: Invalid argument
>> 
>> 
>> 
>> 
>> If I set TESSDATA_PREFIX to /usr/local/share/tessdata, the same error
>> occurs:
>> 
>> 
>> TESSDATA_PREFIX=/usr/local/share/tessdata LD_LIBRARY_PATH=/usr/local/lib
>> /usr/local/bin/ffmpeg -f lavfi -i "movie=test_ocr.png,
>> ocr=datapath=tessdata:language=eng, drawgraph=lavfi.ocr.text"
>> test_ocr_out.png
>> 
>> 
>> ffmpeg version 4.0 Copyright (c) 2000-2018 the FFmpeg developers
>>  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-16)
>>  configuration: --enable-version3 --enable-asm --enable-x86asm
>> --enable-avfilter --disable-static --enable-shared --enable-gpl
>> --enable-nonfree --prefix=/usr/local/ --enable-libvidstab --enable-libass
>> --enable-libfreetype --extra-libs=-lfreetype --enable-libtesseract
>> --enable-libfdk_aac --enable-libmp3lame --enable-libx264
>> --enable-libopenjpeg --enable-libwebp --enable-libx265 --enable-libvorbis
>> --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib
>> --enable-stripping --enable-libmfx
>>  libavutil      56. 14.100 / 56. 14.100
>>  libavcodec     58. 18.100 / 58. 18.100
>>  libavformat    58. 12.100 / 58. 12.100
>>  libavdevice    58.  3.100 / 58.  3.100
>>  libavfilter     7. 16.100 /  7. 16.100
>>  libswscale      5.  1.100 /  5.  1.100
>>  libswresample   3.  1.100 /  3.  1.100
>>  libpostproc    55.  1.100 / 55.  1.100
>> Error opening data file /tessdata/eng.traineddata
>> Please make sure the TESSDATA_PREFIX environment variable is set to the
>> parent directory of your "tessdata" directory.
>> Failed loading language 'eng'
>> Tesseract couldn't load any languages!
>> [Parsed_ocr_1 @ 0x18a8d80] failed to init tesseract
>> [lavfi @ 0x189c7c0] Error initializing filter 'ocr' with args
>> 'datapath=tessdata:language=eng'
>> movie=test_ocr.png, ocr=datapath=tessdata:language=eng,
>> drawgraph=lavfi.ocr.text: Invalid argument
>> 
>> 
>> If I use /usr/local/bin/tesseract to do the ocr task, there is no problem.
>> 
>> 
>> Why ffmpeg and tesseract-3.05.01 can't find eng.traineddata?
>> 
>> 
>> 
>> 
>> 2)
>> How can I use ocr to parse text from png file, and output the text into some
>> specified txt file?
>> 
> 
> Definetely by not using drawgraph, drawgraph parses numbers not text,
> but I see you have much bigger issues.
> 
>> 
>> 
>> 
>> Thanks
>> 
>> 
>> Regards
>> 
>> 
>> Andrew
>> _______________________________________________
>> ffmpeg-user mailing list
>> ffmpeg-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
> 
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".



More information about the ffmpeg-user mailing list