use of org.opencv.core.Size in project Frankenstein by olir.
the class MovieProcessor method processVideo.
public boolean processVideo(ProcessingListener l) {
try {
streamStopped = !configuration.doInput || !(configuration.getSource() instanceof VideoStreamSource);
if (!configuration.doInput || !(configuration.getSource() instanceof VideoStreamSource)) {
System.out.print("doOutput=" + configuration.doOutput + " with source=" + (configuration.getSource() != null ? configuration.getSource().getClass().getName() : "none"));
// temporarily
if (configuration.doOutput && configuration.doInput) {
if (!new Task(this, ffmpeg.getAbsolutePath() + " -y -i \"" + configuration.getInputVideo() + "\"" + " -f ffmetadata " + tempMetadataFile.getAbsolutePath() + " -vn -ar 44100 -ac 2 -ab 192k -f mp3 -r 21 " + tempAudioFile.getAbsolutePath(), new TimeTaskHandler(l, "Splitting Audio")).run())
return false;
configuration.metadata.clear();
configuration.metadata.load(tempMetadataFile);
System.out.print("Meta Data:\n===================\n" + configuration.metadata + "===================\n");
} else if (configuration.doOutput) {
// Create silent mp3
if (!new Task(this, ffmpeg.getAbsolutePath() + " -y -f lavfi -i anullsrc=r=44100:cl=mono -t " + (movie_frameCount / movie_fps) + " -q:a 9 -acodec libmp3lame " + tempAudioFile.getAbsolutePath(), new TimeTaskHandler(l, "Creating Silent Audio Audio")).run())
return false;
}
}
// 2. Process Video without audio ()
System.out.print("Processing video: ");
Mat newFrame = null;
if (l != null)
l.taskUpdate(null, "Processing video");
int i = 0;
while (!stopped && (configuration.getSource().getFrames() < 0 || i < configuration.getSource().getFrames() || !streamStopped)) {
i++;
if (streamStopped) {
currentPos = configuration.getSource().seek(i, l);
frame = configuration.getSource().getFrame();
} else {
((VideoStreamSource) configuration.getSource()).pause();
frame = configuration.getSource().getFrame();
}
if (frame != null && !frame.empty()) {
if (!filters.isEmpty()) {
FilterContext context = new DefaultFilterContext();
newFrame = frame;
for (VideoFilter filter : filters) {
// System.out.println("MovieProcessor
// process"+filter.getClass().getName());
newFrame = filter.process(newFrame, i, context);
}
} else {
newFrame = frame;
}
if (localFilters != null && !localFilters.isEmpty()) {
FilterContext context = new DefaultFilterContext();
for (FilterElement element : localFilters) {
if (element.filter != null) {
if (element.r.start <= i && (i < element.r.end || !streamStopped)) {
// System.out.println("MovieProcessor
// processStreamFrame
// " +
// element.filter);
newFrame = element.filter.process(newFrame, i, context);
}
}
}
}
if (configuration.doOutput) {
if (movie_w != newFrame.cols() || movie_h != newFrame.rows())
System.out.println("Warning: outputVideo.write changed size:" + new Size(newFrame.cols(), newFrame.rows()));
outputVideo.write(newFrame);
if ((i % 1000) == 0) {
// break;
System.out.print("+");
} else if ((i % 100) == 0)
System.out.print(".");
}
if (l != null)
l.nextFrameProcessed(newFrame, currentPos);
} else {
if (currentPos < movie_frameCount && l != null)
l.prematureEnd(currentPos);
break;
}
}
System.out.println("ok\nFrames proccessed: " + i);
if (configuration.doOutput) {
outputVideo.release();
}
if (stopped) {
return false;
}
if (configuration.doOutput) {
File of = findFreeFile(new File(configuration.outputVideo));
if (!configuration.doInput || !(configuration.getSource() instanceof VideoStreamSource)) {
if (configuration.doInput) {
if (!new Task(this, ffmpeg.getAbsolutePath() + " -y -i \"" + tempVideoFile.getAbsolutePath() + "\" -i " + tempAudioFile.getAbsolutePath() + " -i " + tempMetadataFile.getAbsolutePath() + " -map_metadata 2" + " -c:a aac -c:v libx264 -q 17 \"" + of.getAbsolutePath() + '"', new TimeTaskHandler(l, "Assembling Output")).run())
return false;
} else {
if (!new Task(this, ffmpeg.getAbsolutePath() + " -y -i \"" + tempVideoFile.getAbsolutePath() + "\" -i " + tempAudioFile.getAbsolutePath() + " -c:a aac -c:v libx264 -q 17 \"" + of.getAbsolutePath() + '"', new TimeTaskHandler(l, "Processing Output")).run())
System.out.println("Warning: Task failed");
}
} else {
System.out.println("Renaming temp file " + tempVideoFile.getAbsolutePath());
tempVideoFile.renameTo(of);
}
if (!of.exists()) {
System.err.println("Missing output " + of.getAbsolutePath());
return false;
} else {
System.out.println("Video created: " + of.getAbsolutePath());
}
tempVideoFile.delete();
tempAudioFile.delete();
tempMetadataFile.delete();
}
} finally {
// if (!configuration.doInput || !(configuration.getSource()
// instanceof VideoStreamSource))
// closeInput();
closeOutput();
openOutput(null);
}
return true;
}
use of org.opencv.core.Size in project Frankenstein by olir.
the class Anaglyph2LR method process.
@Override
public Mat process(Mat sourceFrame, int frameId, FilterContext context) {
List<Mat> sourcePlanes = new ArrayList<Mat>();
// planes[2] is the red channel
Core.split(sourceFrame, sourcePlanes);
List<Mat> leftPlanes = new ArrayList<Mat>();
List<Mat> rightPlanes = new ArrayList<Mat>();
leftPlanes.add(sourcePlanes.get(2));
leftPlanes.add(sourcePlanes.get(2));
leftPlanes.add(sourcePlanes.get(2));
Core.merge(leftPlanes, leftFrame);
rightPlanes.add(sourcePlanes.get(1));
rightPlanes.add(sourcePlanes.get(1));
rightPlanes.add(sourcePlanes.get(1));
Core.merge(rightPlanes, rightFrame);
Imgproc.resize(leftFrame, halfFrame1, new Size(smallWidth, smallHeight), 0, 0, Imgproc.INTER_AREA);
Imgproc.resize(rightFrame, halfFrame2, new Size(smallWidth, smallHeight), 0, 0, Imgproc.INTER_AREA);
Rect roi = new Rect(0, 0, smallWidth, smallHeight);
halfFrame1.copyTo(new Mat(newFrame, roi));
roi = new Rect(smallWidth, 0, smallWidth, smallHeight);
halfFrame2.copyTo(new Mat(newFrame, roi));
return newFrame;
}
use of org.opencv.core.Size in project Frankenstein by olir.
the class OU2LR method process.
@Override
public Mat process(Mat sourceFrame, int frameId, FilterContext context) {
Rect roi = new Rect(0, 0, smallWidth, smallHeight);
sourceFrame.submat(new Rect(0, 0, sourceFrame.cols(), sourceFrame.rows() >> 1)).copyTo(upperFrame);
sourceFrame.submat(new Rect(0, sourceFrame.rows() >> 1, sourceFrame.cols(), sourceFrame.rows() >> 1)).copyTo(lowerFrame);
Imgproc.resize(upperFrame, leftFrame, new Size(smallWidth, smallHeight), 0, 0, Imgproc.INTER_AREA);
Imgproc.resize(lowerFrame, rightFrame, new Size(smallWidth, smallHeight), 0, 0, Imgproc.INTER_AREA);
newFrame.setTo(new Scalar(255, 0, 0));
roi = new Rect(0, 0, smallWidth, smallHeight);
leftFrame.copyTo(new Mat(newFrame, roi));
roi = new Rect(smallWidth, 0, smallWidth, smallHeight);
rightFrame.copyTo(new Mat(newFrame, roi));
return newFrame;
}
use of org.opencv.core.Size in project Frankenstein by olir.
the class TestImageInput method configure.
@Override
public Mat configure(Mat sourceFrame) {
System.out.println("configure " + smallWidth + " x " + smallHeight);
System.out.println(" " + sourceFrame.cols() + " x " + sourceFrame.rows());
testFrame = sourceFrame.clone();
newFrame = sourceFrame.clone();
Imgproc.resize(sourceFrame, testFrame, new Size((double) smallWidth, (double) smallHeight));
Imgproc.resize(sourceFrame, newFrame, new Size((double) smallWidth, (double) smallHeight));
testFrame.setTo(new Scalar(0, 0, 0));
drawTestImage(0, 0, smallWidth, smallHeight);
return testFrame;
}
use of org.opencv.core.Size in project Frankenstein by olir.
the class LR2VR180 method process.
@Override
public Mat process(Mat sourceFrame, int frameId, FilterContext context) {
Rect roiDest, roiSource;
if (!coneCorrection) {
roiDest = new Rect(borderW, borderH, smallWidth, smallHeight);
sourceFrame.submat(new Rect(0, 0, smallWidth, smallHeight)).copyTo(new Mat(newFrame, roiDest));
roiDest = new Rect(smallWidth + 3 * borderW, borderH, smallWidth, smallHeight);
sourceFrame.submat(new Rect(smallWidth, 0, smallWidth, smallHeight)).copyTo(new Mat(newFrame, roiDest));
} else {
int ymid = smallHeight >> 1;
for (int i = 0; i < STEPS_PER_DIRECTION; i++) {
roiSource = new Rect(0, ymid + srcStepOffset[i], sourceFrame.cols(), srcStepHeight[i]);
Imgproc.resize(sourceFrame.submat(roiSource), bufferFrame[i], new Size(sourceFrame.cols(), destStepHeight[i]), 0, 0, Imgproc.INTER_AREA);
// bufferFrame.setTo(new Scalar((i % 2) * 255, 0, 255));
roiDest = new Rect(borderW, borderH + ymid + destStepOffset[i], smallWidth, destStepHeight[i]);
bufferFrame[i].submat(new Rect(0, 0, smallWidth, destStepHeight[i])).copyTo(new Mat(newFrame, roiDest));
roiDest = new Rect(smallWidth + 3 * borderW, borderH + ymid + destStepOffset[i], smallWidth, destStepHeight[i]);
bufferFrame[i].submat(new Rect(smallWidth, 0, smallWidth, destStepHeight[i])).copyTo(new Mat(newFrame, roiDest));
roiSource = new Rect(0, ymid - srcStepOffset[i] - srcStepHeight[i], sourceFrame.cols(), srcStepHeight[i]);
Imgproc.resize(sourceFrame.submat(roiSource), bufferFrame[i], new Size(sourceFrame.cols(), destStepHeight[i]), 0, 0, Imgproc.INTER_AREA);
// bufferFrame.setTo(new Scalar((i % 2) * 255, 255, 0));
roiDest = new Rect(borderW, borderH + ymid - destStepHeight[i] - destStepOffset[i], smallWidth, destStepHeight[i]);
bufferFrame[i].submat(new Rect(0, 0, smallWidth, destStepHeight[i])).copyTo(new Mat(newFrame, roiDest));
roiDest = new Rect(smallWidth + 3 * borderW, borderH + ymid - destStepHeight[i] - destStepOffset[i], smallWidth, destStepHeight[i]);
bufferFrame[i].submat(new Rect(smallWidth, 0, smallWidth, destStepHeight[i])).copyTo(new Mat(newFrame, roiDest));
}
}
return newFrame;
}
Aggregations