This repository has been archived by the owner on Mar 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from njam/wowza-bin-cm
Import wowza thumbnails+archive to app with CLI tool
- Loading branch information
Showing
13 changed files
with
228 additions
and
209 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,40 @@ | ||
package ch.cargomedia.wms; | ||
|
||
import com.wowza.wms.application.WMSProperties; | ||
|
||
public final class Config { | ||
public static final String RPC_UNSUBSCRIBE = "CM_Stream_Video.unsubscribe"; | ||
public static final String RPC_UNPUBLISH = "CM_Stream_Video.unpublish"; | ||
public static final String RPC_SUBSCRIBE = "CM_Stream_Video.subscribe"; | ||
public static final String RPC_PUBLISH = "CM_Stream_Video.publish"; | ||
public static final String XMLPROPERTY_THUMBNAIL_AND_ARCHIVE_PATH = "ThumbnailAndArchivePath"; | ||
public static final String XMLPROPERTY_THUMBNAIL_WIDTH = "ThumbnailWidth"; | ||
public static final Integer BUCKETS_COUNT = 10000; | ||
public static final int THUMBNAILS_INTERVAL = 10000; | ||
public static final int THUMBNAILER_FFMPEG_RETRY_COUNT = 10; | ||
|
||
private WMSProperties _properties; | ||
|
||
public Config(WMSProperties properties) { | ||
_properties = properties; | ||
} | ||
|
||
public String getCmBinPath() { | ||
return this._getPropertyString("cm_bin_path"); | ||
} | ||
|
||
public Integer getThumbnailWidth() { | ||
return _properties.getPropertyInt("ThumbnailWidth", 240); | ||
} | ||
|
||
public Integer getThumbnailInterval() { | ||
return 10000; | ||
} | ||
|
||
public String getRpcUrl() { | ||
return this._getPropertyString("RPCUrl"); | ||
} | ||
|
||
private String _getPropertyString(String key) { | ||
String value = _properties.getPropertyStr(key); | ||
if (null == value || 0 == value.length()) { | ||
throw new RuntimeException("Missing config `" + key + "`."); | ||
} | ||
return value; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,49 @@ | ||
package ch.cargomedia.wms; | ||
|
||
import ch.cargomedia.wms.module.eventhandler.ConnectionsListener; | ||
import ch.cargomedia.wms.stream.VideostreamPublisher; | ||
import com.wowza.wms.application.IApplicationInstance; | ||
import com.wowza.wms.stream.IMediaStream; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.InputStreamReader; | ||
import java.util.UUID; | ||
|
||
public class Utils { | ||
public static final int MP4_LIVESTREAM = 0; | ||
public static final int MP4_ARCHIVESTREAM = 1; | ||
|
||
public static String[] getArchiveFilePaths(IMediaStream stream, VideostreamPublisher videostreamPublisher) { | ||
String[] files = new String[2]; | ||
IApplicationInstance appInstance = ConnectionsListener.appInstance; | ||
int streamId = videostreamPublisher.getStreamId(); | ||
String md5Hash = videostreamPublisher.getClientIdMD5Hash(); | ||
files[MP4_LIVESTREAM] = appInstance.getStreamStoragePath() + "/" + stream.getName() + ".mp4"; | ||
String storageDir = Utils.getStoragePath(videostreamPublisher); | ||
files[MP4_ARCHIVESTREAM] = storageDir + "/" + String.valueOf(streamId) + "-" + md5Hash + "-" + "original" + ".mp4"; | ||
return files; | ||
} | ||
|
||
public static String getStoragePath(VideostreamPublisher publisher) { | ||
int streamId = publisher.getStreamId(); | ||
IApplicationInstance appInstance = ConnectionsListener.appInstance; | ||
String storagePath = appInstance.getProperties().getPropertyStr(Config.XMLPROPERTY_THUMBNAIL_AND_ARCHIVE_PATH) + "/" | ||
+ streamId % Config.BUCKETS_COUNT; | ||
File storageDir = new File(storagePath); | ||
if (!storageDir.exists()) { | ||
storageDir.mkdirs(); | ||
public static File getTempFile(String extension) { | ||
String dirPath = System.getProperty("java.io.tmpdir") + "/" + "wowza-cm"; | ||
File dir = new File(dirPath); | ||
if (!dir.exists()) { | ||
dir.mkdirs(); | ||
} | ||
String filename = UUID.randomUUID().toString(); | ||
if (null != extension) { | ||
filename += "." + extension; | ||
} | ||
return appInstance.getProperties().getPropertyStr(Config.XMLPROPERTY_THUMBNAIL_AND_ARCHIVE_PATH) + "/" | ||
+ streamId % Config.BUCKETS_COUNT; | ||
return new File(dir + "/" + filename); | ||
} | ||
|
||
public static String getThumbnailStoragePath(VideostreamPublisher publisher) { | ||
int streamId = publisher.getStreamId(); | ||
String md5Hash = publisher.getClientIdMD5Hash(); | ||
return getStoragePath(publisher) + "/" + String.valueOf(streamId) + "-" + md5Hash + "-thumbs"; | ||
public static File getTempFile() { | ||
return getTempFile(null); | ||
} | ||
|
||
public static Integer getThumbnailCount(String path) { | ||
File[] thumbnailFiles = new File(path).listFiles(); | ||
if (null == thumbnailFiles) { | ||
return 0; | ||
public static String exec(String[] command) throws Exception { | ||
ProcessBuilder builder = new ProcessBuilder(command); | ||
builder.redirectErrorStream(true); | ||
Process process = builder.start(); | ||
|
||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); | ||
String line; | ||
String output = ""; | ||
while ((line = reader.readLine()) != null) { | ||
output += line + "\n"; | ||
} | ||
return thumbnailFiles.length; | ||
|
||
if (process.waitFor() != 0) { | ||
throw new Exception(String.format("Command exited with code `%s`. \nCommand: %s \nOutput: \n%s", | ||
process.exitValue(), StringUtils.join(command, " "), output)); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.