vitrivr / cineast

Cineast is a multi-feature content-based mulitmedia retrieval engine. It is capable of retrieving images, audio- and video sequences as well as 3d models based on edge or color sketches, textual descriptions and example objects.
MIT License
57 stars 50 forks source link

SRTSubTitleDecoder :NumberFormatException #91

Closed mmaatuq closed 5 years ago

mmaatuq commented 5 years ago

Hello, the below exception is thrown while trying to run extraction using cineast ` 2019-10-13 00:40:37.893 [extraction-file-handler-thread] ERROR o.v.c.c.r.f.GenericExtractionItemHandler - Media Type VIDEO does not sup port file type application/octet-stream 2019-10-13 00:40:37.894 [extraction-file-handler-thread] DEBUG o.v.c.c.r.p.TreeWalkContainerIteratorProvider - Next path: /var/www/html /test/1.mp4, base /var/www/html/test, res 1.mp4 2019-10-13 00:40:37.894 [extraction-file-handler-thread] INFO o.v.c.c.r.f.GenericExtractionItemHandler - Processing path ExtractionItem Container{object=MediaObjectDescriptor{objectId='null', name='1.mp4', path='1.mp4', exists=false, mediatypeId=99}, metadata=[], path=/v ar/www/html/test/1.mp4} and mediatype VIDEO 2019-10-13 00:40:38.867 [extraction-file-handler-thread] INFO o.v.c.c.d.s.s.SRTSubTitleDecoder - Loading SRT subtitle from /var/www/htm l/test/1.srt 2019-10-13 00:40:38.962 [extraction-file-handler-thread] WARN o.v.c.c.d.s.s.SRTSubTitleDecoder - Error while parsing subtitle item 2019-10-13 00:40:38.964 [extraction-file-handler-thread] WARN o.v.c.c.d.s.s.SRTSubTitleDecoder - java.lang.NumberFormatException: For i nput string: "1" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer.parseInt(Integer.java:615) at java.lang.Thread.run(Thread.java:748) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.vitrivr.cineast.core.decode.subtitle.SubtitleDecoderFactory.subtitleForFile(SubtitleDecoderFactory.java:77) at org.vitrivr.cineast.core.decode.subtitle.SubtitleDecoderFactory.subtitleForVideo(SubtitleDecoderFactory.java:56) at org.vitrivr.cineast.core.decode.video.FFMpegVideoDecoder.init(FFMpegVideoDecoder.java:430) at org.vitrivr.cineast.core.run.filehandler.GenericExtractionItemHandler.run(GenericExtractionItemHandler.java:208) at java.lang.Thread.run(Thread.java:748)

actully i tried to figure out if it's a problem with class SRTSubTitleDecoder itself so i somehow seperate it like below

import java.io.BufferedReader; import java.io.IOException; import java.nio.file.Paths; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; / import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.vitrivr.cineast.core.decode.subtitle.SubTitleDecoder; import org.vitrivr.cineast.core.decode.subtitle.SubtitleItem; import org.vitrivr.cineast.core.util.LogHelper; / public class SRTSubTitleDecoder {

//rivate static final Logger LOGGER = LogManager.getLogger();

//private List<SRTSubtitleItem> items = new ArrayList<>();
private int maxId = -1;
private long startTime = -1, endTime = -1;
private int pointer = 0;

public SRTSubTitleDecoder(Path file) {

// LOGGER.info("Loading SRT subtitle from {}", file); try (final BufferedReader reader = Files.newBufferedReader(file)) { String line1, line2, line3; StringBuffer text; int id = 0; long start, end; loop: while ((line1 = reader.readLine()) != null) {

            while (line1.isEmpty()) {
                line1 = reader.readLine();
                if (line1 == null) {
                    break loop;
                }
            }

            try {
                id = Integer.parseInt(line1);
                //System.out.println(id);

                this.maxId = Math.max(maxId, id);

                line2 = reader.readLine();
                if (line2 == null) {
                    break;
                }
                String[] timing = line2.split(" --> ");
                if (timing.length != 2) {
                    break;
                }

                start = parseTime(timing[0]);
                end = parseTime(timing[1]);

                if (this.startTime == -1) {
                    this.startTime = start;
                }

                this.endTime = end;

                text = new StringBuffer();
                while ((line3 = reader.readLine()) != null && !line3.isEmpty()) {
                    text.append(line3);
                    System.out.println(text);
                    text.append('\n');
                }

// items.add(new SRTSubtitleItem(id, start, end, text.toString())); } catch (NumberFormatException e) { // LOGGER.warn("Error while parsing subtitle item"); // LOGGER.warn(LogHelper.getStackTrace(e)); } } ` and i run that class against the same SRT file and it worked no exceptions were thrown.

lucaro commented 5 years ago

If the decoder throws an exception, it means that the SRT file is not valid. What is the content of the file in question? Also, could you please check the formatting of your posts before submitting them, the above is unnecessarily hard to read.

mmaatuq commented 5 years ago

Thanks for your support the SRT file was valid I treid it using standalone srtDecoder above but after many trials I somehow figured out what was wrong I was using an SRT file that wasn't for the video i was trying to run extraction on I'm not sure why but now with the correct SRT for the viedo file it's working and now issue will be closed.