Last active
January 20, 2016 21:03
-
-
Save Nasawa/64e232466e3793a9cdc8 to your computer and use it in GitHub Desktop.
Finds matching frames and reports their timestamp
This file contains hidden or 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
package videodiff; | |
import java.awt.image.BufferedImage; | |
import java.io.FileNotFoundException; | |
import java.io.PrintWriter; | |
import java.io.UnsupportedEncodingException; | |
import java.util.Vector; | |
import org.bytedeco.javacv.FFmpegFrameGrabber; | |
import org.bytedeco.javacv.Java2DFrameConverter; | |
public class GetFrames | |
{ | |
static FFmpegFrameGrabber grabber; | |
static ImageCompare ic; | |
public static void main(String[] args) | |
{ | |
String path = "C:\\somepath\\"; | |
grabber = new FFmpegFrameGrabber(path + "mini1.mp4"); | |
Java2DFrameConverter converter = new Java2DFrameConverter(); | |
long skiprate = 1000000; | |
long buffer = 0;//33000000; | |
long interval = 1000000; | |
String log = path + "datalog.txt"; | |
String out = path + "result.txt"; | |
Vector<Integer> stamps = new Vector<Integer>(); | |
try | |
{ | |
grabber.start(); | |
grabber.setTimestamp(buffer); | |
while(grabber.getFrameNumber() < grabber.getLengthInFrames() - 1) | |
{ | |
if(grabber.getTimestamp() % interval < 150000) | |
print(log, grabber.getTimestamp()); | |
BufferedImage buff = converter.getBufferedImage(grabber.grab(), 2.2/grabber.getGamma()); | |
if(buff != null) | |
{ | |
ic = new ImageCompare(path + "tv.jpg", buff); | |
ic.setParameters(4,4,4,10); // (num vertical regions, num horizontal regions, sensitivity, stabilizer) | |
ic.compare(); | |
if(ic.match()) | |
{ | |
//ImageIO.write(buff, "jpg", new File(path + "match.jpg")); // For finding on unique videos | |
long ts = grabber.getTimestamp(); | |
int ts2 = (int)(ts * 0.000001); | |
stamps.add(ts2); | |
System.out.println((ts2)); | |
grabber.setTimestamp(ts + skiprate); // avoids getting the same clip twice | |
} | |
} | |
} | |
grabber.stop(); | |
print(out, stamps); | |
} | |
catch (Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
} | |
public static void print(String path, Object val) throws FileNotFoundException, UnsupportedEncodingException | |
{ | |
PrintWriter writer = new PrintWriter(path, "UTF-8"); | |
writer.println(val); | |
writer.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment