added OCR capability
[meviz.git] / src / main / java / eu / svjatoslav / meviz / encoder / converters / Ocr.java
1 /*
2  * Meviz - Various tools collection to work with multimedia.
3  * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 2 of the GNU General Public License
7  * as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.meviz.encoder.converters;
11
12 import java.io.File;
13 import java.util.List;
14
15 import eu.svjatoslav.meviz.encoder.EncodingOptions;
16
17 public class Ocr extends AbstractConverter {
18
19         @Override
20         public String getCommand(final File inputFile, final File targetFile,
21                         final EncodingOptions options, String targetFormat) {
22
23                 // for some stupid reason tesseract ALWAYS insists on automatically
24                 // adding txt suffix
25                 String targetAbsolutePath = targetFile.getAbsolutePath();
26                 String targetFileName = targetAbsolutePath.substring(0,
27                                 targetAbsolutePath.length() - 4);
28
29                 return "tesseract \"" + inputFile.getAbsolutePath() + "\" \""
30                                 + targetFileName + "\"";
31         }
32
33         @Override
34         public List<String> getSourceFileExtensions() {
35                 return toList("tif", "tiff", "png", "jpg", "jpeg");
36         }
37
38         @Override
39         public List<String> getTargetFileExtensions() {
40                 return toList("txt");
41         }
42
43         @Override
44         public boolean isTerminalMandatory() {
45                 return false;
46         }
47
48 }