You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2019/01/31 15:34:10 UTC

[openmeetings] branch master updated: [OPENMEETINGS-1983] audio file upload seems to work better

This is an automated email from the ASF dual-hosted git repository.

solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git


The following commit(s) were added to refs/heads/master by this push:
     new f2b0273  [OPENMEETINGS-1983] audio file upload seems to work better
f2b0273 is described below

commit f2b0273e270ecf8fbbd79e23e2f4a74c56dbb009
Author: Maxim Solodovnik <so...@gmail.com>
AuthorDate: Thu Jan 31 22:29:40 2019 +0700

    [OPENMEETINGS-1983] audio file upload seems to work better
---
 .../core/converter/VideoConverter.java             |  31 ++++++++++++++-----
 .../openmeetings/core/data/file/FileProcessor.java |   2 +-
 .../org/apache/openmeetings/util/OmFileHelper.java |  34 ++++++++++++---------
 .../org/apache/openmeetings/util/StoredFile.java   |   9 +++++-
 .../src/main/webapp/css/images/audio.jpg           | Bin 0 -> 2687 bytes
 .../src/main/webapp/css/images/audio.png           | Bin 0 -> 1616 bytes
 .../src/main/webapp/css/images/audio.svg           |   5 +++
 7 files changed, 56 insertions(+), 25 deletions(-)

diff --git a/openmeetings-core/src/main/java/org/apache/openmeetings/core/converter/VideoConverter.java b/openmeetings-core/src/main/java/org/apache/openmeetings/core/converter/VideoConverter.java
index ffe5ec6..2b4c320 100644
--- a/openmeetings-core/src/main/java/org/apache/openmeetings/core/converter/VideoConverter.java
+++ b/openmeetings-core/src/main/java/org/apache/openmeetings/core/converter/VideoConverter.java
@@ -20,13 +20,18 @@ package org.apache.openmeetings.core.converter;
 
 import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
 import static org.apache.openmeetings.util.OmFileHelper.EXTENSION_MP4;
+import static org.apache.openmeetings.util.OmFileHelper.getCssImagesDir;
 
 import java.io.File;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 import org.apache.openmeetings.db.entity.file.BaseFileItem.Type;
 import org.apache.openmeetings.db.entity.file.FileItem;
+import org.apache.openmeetings.util.StoredFile;
 import org.apache.openmeetings.util.process.ProcessHelper;
 import org.apache.openmeetings.util.process.ProcessResult;
 import org.apache.openmeetings.util.process.ProcessResultList;
@@ -38,10 +43,11 @@ import org.springframework.stereotype.Component;
 public class VideoConverter extends BaseConverter {
 	private static final Logger log = LoggerFactory.getLogger(VideoConverter.class);
 
-	public void convertVideo(FileItem f, String ext, ProcessResultList logs) {
+	public void convertVideo(FileItem f, StoredFile sf, ProcessResultList logs) {
 		try {
-			File mp4 = f.getFile(EXTENSION_MP4);
+			final File mp4 = f.getFile(EXTENSION_MP4);
 			f.setType(Type.Video);
+			final String ext = sf.getExt();
 			String input = f.getFile(ext).getCanonicalPath();
 			boolean sameExt = EXTENSION_MP4.equals(ext);
 			Path tmp = null;
@@ -50,14 +56,23 @@ public class VideoConverter extends BaseConverter {
 				tmp = Files.createTempFile("video", ".mp4");
 				input = Files.move(mp4.toPath(), tmp, REPLACE_EXISTING).toFile().getCanonicalPath();
 			}
-			String[] args = new String[] { getPathToFFMPEG(), "-y"
-					, "-i", input //
+			List<String> args = new ArrayList<>(Arrays.asList(getPathToFFMPEG(), "-y"));
+			if (sf.isAudio()) {
+				// need to add background image, it should be jpg since black on transparent will be invisible
+				args.addAll(Arrays.asList("-loop", "1"//
+						, "-framerate", "24"//
+						, "-i", new File(getCssImagesDir(), "audio.jpg").getCanonicalPath()));
+			}
+			args.addAll(Arrays.asList("-i", input //
 					, "-c:v", "h264" //
 					, "-c:a", "libfaac" //
 					, "-c:a", "libfdk_aac" //
-					, "-pix_fmt", "yuv420p" //
-					, mp4.getCanonicalPath() };
-			ProcessResult res = ProcessHelper.executeScript("convert to MP4 :: " + f.getHash(), args);
+					, "-pix_fmt", "yuv420p"));
+			if (sf.isAudio()) {
+				args.add("-shortest");
+			}
+			args.add(mp4.getCanonicalPath());
+			ProcessResult res = ProcessHelper.executeScript("convert to MP4 :: " + f.getHash(), args.toArray(new String[0]));
 			logs.add(res);
 			if (sameExt && tmp != null) {
 				if (res.isOk()) {
@@ -73,7 +88,7 @@ public class VideoConverter extends BaseConverter {
 			f.setHeight(dim.getHeight());
 			convertToPng(f, mp4.getCanonicalPath(), logs);
 		} catch (Exception err) {
-			log.error("[convertToFLV]", err);
+			log.error("[convertVideo]", err);
 			logs.add(new ProcessResult("convertToMP4", err.getMessage(), err));
 		}
 	}
diff --git a/openmeetings-core/src/main/java/org/apache/openmeetings/core/data/file/FileProcessor.java b/openmeetings-core/src/main/java/org/apache/openmeetings/core/data/file/FileProcessor.java
index b8a50f1..bf2b765 100644
--- a/openmeetings-core/src/main/java/org/apache/openmeetings/core/data/file/FileProcessor.java
+++ b/openmeetings-core/src/main/java/org/apache/openmeetings/core/data/file/FileProcessor.java
@@ -124,7 +124,7 @@ public class FileProcessor {
 					break;
 				case Video:
 					copyFile(temp, file);
-					videoConverter.convertVideo(f, sf.getExt(), logs);
+					videoConverter.convertVideo(f, sf, logs);
 					break;
 				default:
 					break;
diff --git a/openmeetings-util/src/main/java/org/apache/openmeetings/util/OmFileHelper.java b/openmeetings-util/src/main/java/org/apache/openmeetings/util/OmFileHelper.java
index 3a8aa18..29f5af8 100644
--- a/openmeetings-util/src/main/java/org/apache/openmeetings/util/OmFileHelper.java
+++ b/openmeetings-util/src/main/java/org/apache/openmeetings/util/OmFileHelper.java
@@ -93,12 +93,12 @@ public class OmFileHelper {
 
 	private OmFileHelper() {}
 
-	public static void setOmHome(File omHome) {
-		OmFileHelper.omHome = omHome;
+	public static void setOmHome(File home) {
+		omHome = home;
 	}
 
-	public static void setOmHome(String omHome) {
-		OmFileHelper.omHome = new File(omHome);
+	public static void setOmHome(String home) {
+		omHome = new File(home);
 	}
 
 	public static File getRootDir() {
@@ -107,7 +107,7 @@ public class OmFileHelper {
 	}
 
 	public static File getOmHome() {
-		return OmFileHelper.omHome;
+		return omHome;
 	}
 
 	private static File getDir(File parent, String name) {
@@ -119,7 +119,7 @@ public class OmFileHelper {
 	}
 
 	public static File getUploadDir() {
-		return new File(OmFileHelper.omHome, UPLOAD_DIR);
+		return new File(omHome, UPLOAD_DIR);
 	}
 
 	public static File getUploadFilesDir() {
@@ -192,7 +192,7 @@ public class OmFileHelper {
 	}
 
 	public static File getStreamsDir() {
-		return getDir(OmFileHelper.omHome, STREAMS_DIR);
+		return getDir(omHome, STREAMS_DIR);
 	}
 
 	public static File getStreamsHibernateDir() {
@@ -232,11 +232,11 @@ public class OmFileHelper {
 	}
 
 	public static File getLanguagesDir() {
-		return new File(OmFileHelper.omHome, LANGUAGES_DIR);
+		return new File(omHome, LANGUAGES_DIR);
 	}
 
 	public static File getPublicDir() {
-		return new File(OmFileHelper.omHome, PUBLIC_DIR);
+		return new File(omHome, PUBLIC_DIR);
 	}
 
 	public static File getPublicClipartsDir() {
@@ -248,7 +248,7 @@ public class OmFileHelper {
 	}
 
 	public static File getWebinfDir() {
-		return new File(OmFileHelper.omHome, WEB_INF_DIR);
+		return new File(omHome, WEB_INF_DIR);
 	}
 
 	public static File getPersistence() {
@@ -260,11 +260,11 @@ public class OmFileHelper {
 	}
 
 	public static File getPersistence(DbType dbType) {
-		return new File(OmFileHelper.getWebinfDir(), dbType == null ? PERSISTENCE_NAME : String.format(DB_PERSISTENCE_NAME, dbType));
+		return new File(getWebinfDir(), dbType == null ? PERSISTENCE_NAME : String.format(DB_PERSISTENCE_NAME, dbType));
 	}
 
 	public static File getLdapConf(String name) {
-		return new File(new File(OmFileHelper.omHome, CONF_DIR), name);
+		return new File(new File(omHome, CONF_DIR), name);
 	}
 
 	public static void loadLdapConf(String name, Properties config) {
@@ -282,15 +282,19 @@ public class OmFileHelper {
 	}
 
 	public static File getScreenSharingDir() {
-		return new File(OmFileHelper.omHome, SCREENSHARING_DIR);
+		return new File(omHome, SCREENSHARING_DIR);
 	}
 
 	public static File getImagesDir() {
-		return new File(OmFileHelper.omHome, IMAGES_DIR);
+		return new File(omHome, IMAGES_DIR);
 	}
 
 	public static File getCssDir() {
-		return new File(OmFileHelper.omHome, CSS_DIR);
+		return new File(omHome, CSS_DIR);
+	}
+
+	public static File getCssImagesDir() {
+		return new File(getCssDir(), IMAGES_DIR);
 	}
 
 	public static File getCustomCss() {
diff --git a/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java b/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java
index 68ba782..2b2ec5e 100644
--- a/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java
+++ b/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java
@@ -168,11 +168,18 @@ public class StoredFile {
 		return MIME_IMAGE.equals(mime.getType());
 	}
 
+	public boolean isAudio() {
+		if (mime == null) {
+			return false;
+		}
+		return MIME_AUDIO.equals(mime.getType());
+	}
+
 	public boolean isVideo() {
 		if (mime == null) {
 			return false;
 		}
-		return MIME_AUDIO.equals(mime.getType()) || MIME_VIDEO.equals(mime.getType());
+		return isAudio() || MIME_VIDEO.equals(mime.getType());
 	}
 
 	public boolean isChart() {
diff --git a/openmeetings-web/src/main/webapp/css/images/audio.jpg b/openmeetings-web/src/main/webapp/css/images/audio.jpg
new file mode 100644
index 0000000..6b82dbc
Binary files /dev/null and b/openmeetings-web/src/main/webapp/css/images/audio.jpg differ
diff --git a/openmeetings-web/src/main/webapp/css/images/audio.png b/openmeetings-web/src/main/webapp/css/images/audio.png
new file mode 100644
index 0000000..8c1a047
Binary files /dev/null and b/openmeetings-web/src/main/webapp/css/images/audio.png differ
diff --git a/openmeetings-web/src/main/webapp/css/images/audio.svg b/openmeetings-web/src/main/webapp/css/images/audio.svg
new file mode 100644
index 0000000..27c141e
--- /dev/null
+++ b/openmeetings-web/src/main/webapp/css/images/audio.svg
@@ -0,0 +1,5 @@
+<?xml version="1.0" ?><!DOCTYPE svg  PUBLIC '-//W3C//DTD SVG 1.1//EN'  'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
+<!--
+	Licensed MIT
+	https://www.iconfinder.com/icons/211867/music_note_icon
+--><svg height="512px" id="Layer_1" style="enable-background:new 0 0 512 512;" version="1.1" viewBox="0 0 512 512" width="512px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M115.2,378C87,378,64,400.9,64,429c0,28.1,23,51,51.2,51h37.2c15.3,0,28.9-6.8,38.3-17.4c0.1-0.1,0.3-0.1,0.4-0.2  c0.6-0.6,1-1.5,1.5-2.1c1.3-1.6,2.5-3.2,3.5-5c9.5-14.2,14-32.9,14-47.2c0-16.8,0-197.3,0-197.3c0-0.6,0-1.1,0-1.7  c0-0.5,0-1.1,0-1.6c0.8-14.2,11.2 [...]