-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiple partition video, and refactor the parsing of…
… ubnt_ubvinfo into a separate UbvInfoParser which generates a list of UbvPartition containing a list of FrameDataRef. Also adds some basic unit tests, using sample output from ubvinfo
- Loading branch information
1 parent
4f8ec83
commit 0156645
Showing
8 changed files
with
161 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class FrameDataRef | ||
{ | ||
public final int offset; | ||
public final int size; | ||
|
||
|
||
public FrameDataRef(final int offset, final int size) | ||
{ | ||
this.offset = offset; | ||
this.size = size; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
public class UbvInfoParser | ||
{ | ||
private static final String PARTITION_START = "----------- PARTITION START -----------"; | ||
private static final int FIELD_OFFSET = 4; | ||
private static final int FIELD_SIZE = 5; | ||
|
||
|
||
/** | ||
* Takes the output of ubvinfo, expected to start with the following line: | ||
* <pre>Type TID KF OFFSET SIZE DTS CTS WC CR</pre> | ||
* | ||
* @param lines | ||
* @return | ||
*/ | ||
public static List<UbvPartition> parse(Stream<String> lines) | ||
{ | ||
final List<UbvPartition> results = new ArrayList<>(); | ||
|
||
UbvPartition current = null; | ||
boolean firstLine = true; | ||
|
||
final Iterator<String> iterator = lines.iterator(); | ||
while (iterator.hasNext()) | ||
{ | ||
final String line = iterator.next(); | ||
|
||
if (firstLine) | ||
{ | ||
// Skip the first line (column headers) explicitly | ||
firstLine = false; | ||
} | ||
else if (line.equals(PARTITION_START)) | ||
{ | ||
// Start a new partition | ||
current = new UbvPartition(results.size() + 1); | ||
results.add(current); | ||
} | ||
else if (Character.isWhitespace(line.charAt(0))) | ||
{ | ||
final String[] fields = line.split(" +", 7); | ||
final int offset = Integer.parseInt(fields[FIELD_OFFSET]); | ||
final int size = Integer.parseInt(fields[FIELD_SIZE]); | ||
|
||
current.frames.add(new FrameDataRef(offset, size)); | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class UbvPartition | ||
{ | ||
public final int index; | ||
public final List<FrameDataRef> frames = new ArrayList<>(); | ||
|
||
|
||
public UbvPartition(final int index) | ||
{ | ||
this.index = index; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import org.junit.Test; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
import java.util.zip.GZIPInputStream; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class UbvInfoParserTest | ||
{ | ||
@Test | ||
public void testSinglePartitionFile() throws IOException | ||
{ | ||
final List<UbvPartition> partitions = UbvInfoParser.parse(readCompressedInfoFile( | ||
"/FCECFFFFFFFF_2_rotating_1596209441895.ubv.txt.gz")); | ||
|
||
assertEquals("expected partition count", 1, partitions.size()); | ||
assertEquals("frames in partition 1", 239194, partitions.get(0).frames.size()); | ||
} | ||
|
||
|
||
@Test | ||
public void testParseMultiPartition() throws IOException | ||
{ | ||
final List<UbvPartition> partitions = UbvInfoParser.parse(readCompressedInfoFile( | ||
"/F09FFFFFFFFF_2_timelapse_1556890741069.ubv.txt.gz")); | ||
|
||
assertEquals("expected partition count", 44, partitions.size()); | ||
assertEquals("frames in partition 1", 366, partitions.get(0).frames.size()); | ||
assertEquals("partition 1 frame 1 offset", 96, partitions.get(0).frames.get(0).offset); | ||
assertEquals("partition 1 frame 1 size", 2218, partitions.get(0).frames.get(0).size); | ||
} | ||
|
||
|
||
private Stream<String> readCompressedInfoFile(final String resource) throws IOException | ||
{ | ||
return new BufferedReader(new InputStreamReader(new GZIPInputStream(getClass().getResourceAsStream(resource)))).lines(); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.