use of com.seleniumtests.util.video.avi.AVIReader in project seleniumRobot by bhecquet.
the class VideoUtils method extractReferenceForSteps.
/**
* Extract the picture associated to the beginning of a step to <output_dir>/video
* @param videoFile
* @param testSteps
* @param outputDirectory
*/
public static void extractReferenceForSteps(File videoFile, List<TestStep> testSteps, Path outputDirectory) {
// create output
Path videoOutputDirectory = outputDirectory.resolve(VIDEO_DIR);
videoOutputDirectory.toFile().mkdirs();
AVIReader in = null;
try {
// Create the reader
in = new AVIReader(videoFile);
// Look for the first video track
int trackId = 0;
while (trackId < in.getTrackCount() && in.getFormat(trackId).get(MediaTypeKey) != MediaType.VIDEO) {
trackId++;
}
Map<Long, TestStep> samples = new HashMap<>();
for (TestStep testStep : testSteps) {
if (!testStep.isTestEndStep()) {
// timestamp outside of video, do not try to extract as we would get the last picture
if (testStep.getVideoTimeStamp() / 1000 * in.getTimeScale(trackId) > in.getChunkCount(0)) {
continue;
}
samples.put(min(in.timeToSample(trackId, new Rational(testStep.getVideoTimeStamp(), 1000)), in.getChunkCount(trackId) - 1), testStep);
}
}
// Read images from the track
BufferedImage img = null;
// read video and extract requested images
long i = 0;
int j = 0;
do {
img = in.read(trackId, img);
if (samples.containsKey(i)) {
Path extractedPicture = videoOutputDirectory.resolve(String.format("video-%d.jpg", j));
FileUtility.writeImage(extractedPicture.toString(), img);
Snapshot snapshot = new Snapshot(new ScreenShot(outputDirectory.relativize(extractedPicture).toString()), "Step beginning state", SnapshotCheckType.REFERENCE_ONLY);
// by default, reference snapshot won't be displayed in report. This flag will be set to "true" only if step fails and we have a reference picture from server
snapshot.setDisplayInReport(false);
samples.get(i).addSnapshot(snapshot, j, null);
j++;
}
i++;
} while (img != null);
} catch (IOException e) {
logger.error("Cannot extract step reference " + e.getMessage());
} finally {
// Close the reader
if (in != null) {
try {
in.close();
} catch (IOException e) {
logger.error("Cannot close video reader " + e.getMessage());
}
}
}
}
Aggregations