Skip to content

Commit

Permalink
various improvements of the video functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fhoehnel committed Apr 13, 2020
1 parent 7f57848 commit b24bb03
Show file tree
Hide file tree
Showing 26 changed files with 1,066 additions and 782 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand Down
6 changes: 3 additions & 3 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.compiler.source=1.7
52 changes: 26 additions & 26 deletions build-hotdeploy.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<project name="webfilesys-hotdeploy" default="hotdeploy" basedir=".">
<description>
deploy changed classes and webcontent to the development server
</description>

<property name="project-basedir" value="C:/Projekte/webfilesys/maven-project/webfilesys" />
<property name="deploy-target-basedir" value="C:/Program Files/apache-tomcat-7.0.50/webapps/webfilesys" />

<property name="project-classes-dir" value="${project-basedir}/target/classes" />
<property name="classes-deploy-target" value="${deploy-target-basedir}/WEB-INF/classes" />

<property name="webcontent-src" value="${project-basedir}/src/main/webapp" />
<property name="webcontent-deploy-target" value="${deploy-target-basedir}" />

<target name="hotdeploy">
<copy todir="${classes-deploy-target}" verbose="true">
<fileset dir="${project-classes-dir}" />
</copy>

<copy todir="${webcontent-deploy-target}" verbose="true">
<fileset dir="${webcontent-src}"
includes="styles/**/*,xsl/**/*,javascript/**/*,images/**/*,img-skin/**/*,icons/**/*,emoticons/**/*,help/**/*,html/**/*,fonts/**/*,WEB-INF/languages/**/*,WEB-INF/web.xml" />
</copy>
</target>

</project>
<project name="webfilesys-hotdeploy" default="hotdeploy" basedir=".">
<description>
deploy changed classes and webcontent to the development server
</description>

<property name="project-basedir" value="/home/frank/projekte/webfilesys/maven-project/webfilesys" />
<property name="deploy-target-basedir" value="/home/frank/tomcat-development/webapps/webfilesys" />

<property name="project-classes-dir" value="${project-basedir}/target/classes" />
<property name="classes-deploy-target" value="${deploy-target-basedir}/WEB-INF/classes" />

<property name="webcontent-src" value="${project-basedir}/src/main/webapp" />
<property name="webcontent-deploy-target" value="${deploy-target-basedir}" />

<target name="hotdeploy">
<copy todir="${classes-deploy-target}" verbose="true">
<fileset dir="${project-classes-dir}" />
</copy>

<copy todir="${webcontent-deploy-target}" verbose="true">
<fileset dir="${webcontent-src}"
includes="styles/**/*,xsl/**/*,javascript/**/*,images/**/*,img-skin/**/*,icons/**/*,emoticons/**/*,help/**/*,html/**/*,fonts/**/*,WEB-INF/languages/**/*,WEB-INF/web.xml" />
</copy>
</target>

</project>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>de.webfilesys</groupId>
<artifactId>webfilesys</artifactId>
<packaging>war</packaging>
<version>2.24.0</version>
<version>2.25.0</version>
<name>webfilesys Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/de/webfilesys/LanguageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -155,13 +156,13 @@ public Properties getLanguageResources(String language)
protected synchronized boolean loadResources(String configFilename, Properties langResources,
String language)
{
FileInputStream configFile = null;
InputStreamReader configFile = null;

Logger.getLogger(getClass()).info("Loading Resources from " + configFilename);

try
{
configFile = new FileInputStream(configFilename);
configFile = new InputStreamReader(new FileInputStream(configFilename), "UTF-8");

langResources.load(configFile);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/webfilesys/WebFileSys.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class WebFileSys
{
private static WebFileSys instance = null;

public static final String VERSION = "Version 2.24.0 (09 Feb 2020)";
public static final String VERSION = "Version 2.25.0-beta3 (28 Mar 2020)";

public static final String THUMB_DIR = "thumbnails";

Expand Down
21 changes: 20 additions & 1 deletion src/main/java/de/webfilesys/graphics/SlideshowToVideoThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,29 @@ public void run() {
progNameAndParams.add("-y");
progNameAndParams.add("-i");
progNameAndParams.add(pictureListFilePath);

progNameAndParams.add("-vf");
progNameAndParams.add("zoompan=d=" + (duration + 1) + ":s=" + videoResolutionWidth + "x" + videoResolutionHeight + ":fps=1,framerate=25:interp_start=0:interp_end=255:scene=100");

// with fade in/out but does not keep aspect ratio
// progNameAndParams.add("zoompan=d=" + (duration + 1) + ":s=" + videoResolutionWidth + "x" + videoResolutionHeight + ":fps=1,framerate=25:interp_start=0:interp_end=255:scene=100");

// scaled with correct aspect ratio but no fade in/out
// progNameAndParams.add("scale=" + videoResolutionWidth + ":" + videoResolutionHeight + ":force_original_aspect_ratio=decrease,pad=" + videoResolutionWidth + ":" + videoResolutionHeight + ":(ow-iw)/2:(oh-ih)/2,setsar=1");

// with fade in/fade out and keeps aspect ratio
progNameAndParams.add("scale=" + videoResolutionWidth + ":" + videoResolutionHeight + ":force_original_aspect_ratio=decrease,pad=" + videoResolutionWidth + ":" + videoResolutionHeight + ":(ow-iw)/2:(oh-ih)/2,zoompan=d=" + (duration + 1) + ":s=" + videoResolutionWidth + "x" + videoResolutionHeight + ":fps=1,framerate=25:interp_start=0:interp_end=255:scene=100");

progNameAndParams.add("-c:v");
progNameAndParams.add("h264");

// required to run on Samsung TV
progNameAndParams.add("-profile:v");
progNameAndParams.add("high");
progNameAndParams.add("-level:v");
progNameAndParams.add("4.0");
progNameAndParams.add("-pix_fmt");
progNameAndParams.add("yuv420p");

progNameAndParams.add(targetFilePath);

if (Logger.getLogger(getClass()).isDebugEnabled()) {
Expand Down
45 changes: 40 additions & 5 deletions src/main/java/de/webfilesys/graphics/VideoConverterThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.apache.log4j.Logger;

import de.webfilesys.SubdirExistCache;
import de.webfilesys.WebFileSys;
import de.webfilesys.util.CommonUtils;

Expand All @@ -16,14 +17,18 @@ public class VideoConverterThread extends Thread {

private String newSize;

private String newHeight;

private String newCodec;

private String newContainerFormat;

private String newFps;

private String startTime;
private String endTime;
private String endTime;

private boolean reencode;

private static HashMap<String, String> videoFileExtensions;

Expand All @@ -43,6 +48,10 @@ public void setNewSize(String newVal) {
newSize = newVal;
}

public void setNewHeight(String newVal) {
newHeight = newVal;
}

public void setNewCodec(String newVal) {
newCodec = newVal;
}
Expand All @@ -63,6 +72,14 @@ public void setEndTime(String newVal) {
endTime = newVal;
}

public void setReencode(boolean newVal) {
reencode = newVal;
}

public boolean getReencode() {
return reencode;
}

public void run() {
if (Logger.getLogger(getClass()).isDebugEnabled()) {
Logger.getLogger(getClass()).debug("starting video conversion thread for video file " + videoFilePath);
Expand Down Expand Up @@ -129,6 +146,7 @@ public void run() {
if ((!CommonUtils.isEmpty(startTime)) && (!CommonUtils.isEmpty(endTime))) {
if (CommonUtils.isEmpty(newSize) &&
(CommonUtils.isEmpty(newCodec) || newCodec.equals(sourceVideoInfo.getCodec())) &&
((!("h264".equals(newCodec) || CommonUtils.isEmpty(newCodec) && "h264".equals(sourceVideoInfo.getCodec()))) || !reencode) &&
(CommonUtils.isEmpty(newFps) || newFps.equals(sourceVideoInfo.getFrameRate()))) {
// timeRangeParam = " -c copy -ss " + startTime + " -to " + endTime;
progNameAndParams.add("-c");
Expand All @@ -142,10 +160,14 @@ public void run() {

if (!CommonUtils.isEmpty(newSize)) {
progNameAndParams.add("-vf");
if (sourceVideoInfo.getWidth() > sourceVideoInfo.getHeight()) {
progNameAndParams.add("scale=" + newSize + ":-1");
if (!CommonUtils.isEmpty(newHeight)) {
progNameAndParams.add("scale=" + newSize + ":" + newHeight + ":force_original_aspect_ratio=decrease,pad=" + newSize + ":" + newHeight + ":(ow-iw)/2:(oh-ih)/2");
} else {
progNameAndParams.add("scale=-1:" + newSize);
if (sourceVideoInfo.getWidth() > sourceVideoInfo.getHeight()) {
progNameAndParams.add("scale=" + newSize + ":-1");
} else {
progNameAndParams.add("scale=-1:" + newSize);
}
}
}

Expand All @@ -171,6 +193,19 @@ public void run() {
}
}

if ("h264".equals(newCodec) ||
CommonUtils.isEmpty(newCodec) && "h264".equals(sourceVideoInfo.getCodec())) {
if (reencode) {
// required to run on Samsung TV
progNameAndParams.add("-profile:v");
progNameAndParams.add("high");
progNameAndParams.add("-level:v");
progNameAndParams.add("4.0");
progNameAndParams.add("-pix_fmt");
progNameAndParams.add("yuv420p");
}
}

String addParams = WebFileSys.getInstance().getFfmpegAddParams();
if (addParams != null) {
String[] params = addParams.split(" ");
Expand Down Expand Up @@ -209,10 +244,10 @@ public void run() {

if (convertResult == 0) {
File resultFile = new File(targetFilePath);

if (!resultFile.exists()) {
Logger.getLogger(getClass()).error("result file from ffmpeg video conversion not found: " + targetFilePath);
}
SubdirExistCache.getInstance().setExistsSubdir(sourcePath, new Integer(1));
} else {
Logger.getLogger(getClass()).warn("ffmpeg returned error " + convertResult);
}
Expand Down
57 changes: 34 additions & 23 deletions src/main/java/de/webfilesys/graphics/VideoDeshaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,56 @@
public class VideoDeshaker extends Thread {
public static final String DESHAKE_TARGET_DIR = "_stabilized";

String videoFilePath;
private ArrayList<String> processQueue = null;

public VideoDeshaker(String videoFilePath) {
processQueue = new ArrayList<String>();
processQueue.add(videoFilePath);
}

public VideoDeshaker(String videoPath) {
videoFilePath = videoPath;
public VideoDeshaker(ArrayList<String> videoFilePathList) {
processQueue = videoFilePathList;
}

public void run() {
if (Logger.getLogger(getClass()).isDebugEnabled()) {
Logger.getLogger(getClass()).debug("starting video deshaker thread for video file " + videoFilePath);
Logger.getLogger(getClass()).debug("starting video deshaker thread for " + processQueue.size() + " video files");
}

String ffmpegExePath = WebFileSys.getInstance().getFfmpegExePath();

if (!CommonUtils.isEmpty(ffmpegExePath)) {

String targetVideoPath = getTargetPath(videoFilePath);
File targetVideoDir = new File(targetVideoPath);
if (!targetVideoDir.exists()) {
if (!targetVideoDir.mkdir()) {
Logger.getLogger(getClass()).error("failed to create target directory for deshaked video " + targetVideoPath);
for (String videoFilePath : processQueue) {
String targetVideoPath = getTargetPath(videoFilePath);
File targetVideoDir = new File(targetVideoPath);
if (!targetVideoDir.exists()) {
if (!targetVideoDir.mkdir()) {
Logger.getLogger(getClass()).error("failed to create target directory for deshaked video " + targetVideoPath);
return;
}
}

File transformFile = new File(getTransformFilePath(targetVideoPath));
if (transformFile.exists()) {
Logger.getLogger(getClass()).error("transform file for video deshaking still exists: " + transformFile + " - an other deshaking process seems to be running");
return;
}
}

File transformFile = new File(getTransformFilePath(targetVideoPath));
if (transformFile.exists()) {
Logger.getLogger(getClass()).error("transform file for video deshaking still exists: " + transformFile + " - an other deshaking process seems to be running");
return;
}

if (prepareStabilizer(targetVideoPath)) {
runStabilizer(targetVideoPath);

removeTransformFile(targetVideoPath);
}
if (Logger.getLogger(getClass()).isDebugEnabled()) {
Logger.getLogger(getClass()).debug("starting video deshaking for file " + videoFilePath);
}

if (prepareStabilizer(videoFilePath, targetVideoPath)) {
runStabilizer(videoFilePath, targetVideoPath);

removeTransformFile(targetVideoPath);
}
}
}
}

private boolean prepareStabilizer(String targetVideoPath) {
private boolean prepareStabilizer(String videoFilePath, String targetVideoPath) {

// ffmpeg -i original.mp4 -vf vidstabdetect=stepsize=5:shakiness=7:accuracy=15:result=transform.trf -f null -

Expand Down Expand Up @@ -114,7 +125,7 @@ private boolean prepareStabilizer(String targetVideoPath) {
return false;
}

private boolean runStabilizer(String targetVideoPath) {
private boolean runStabilizer(String videoFilePath, String targetVideoPath) {

// ffmpeg -i original.mp4 -vf vidstabtransform=input="transform.trf":zoom=2:smoothing=12,unsharp=5:5:0.8:3:3:0.4 -vcodec libx264 -preset slow -tune film -crf 18 -acodec copy stabilisiert.mp4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.io.File;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.text.MessageFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
Expand Down Expand Up @@ -34,6 +32,8 @@ protected void process() {
String videoFileName = getParameter("videoFileName");

String newSize = getParameter("newSize");

String newHeight = getParameter("newHeight");

String newFps = getParameter("newFps");

Expand All @@ -49,6 +49,8 @@ protected void process() {
String endMinParam = getParameter("endMin");
String endSecParam = getParameter("endSec");

String reencode = getParameter("re-encode");

String videoFilePath = getCwd();
if (videoFilePath.endsWith(File.separator)) {
videoFilePath = videoFilePath + videoFileName;
Expand All @@ -59,9 +61,11 @@ protected void process() {
VideoConverterThread videoConverter = new VideoConverterThread(videoFilePath);

videoConverter.setNewSize(newSize);
videoConverter.setNewHeight(newHeight);
videoConverter.setNewCodec(newCodec);
videoConverter.setNewFps(newFps);
videoConverter.setNewContainerFormat(newContainerFormat);
videoConverter.setReencode(reencode != null);

DecimalFormat numFormat = new DecimalFormat("00");

Expand Down
Loading

0 comments on commit b24bb03

Please sign in to comment.