├── .gitignore ├── LICENSE ├── README.md ├── ffmpeg-transcoder-test └── src │ └── com │ └── flashvisions │ └── server │ └── rtmp │ └── transcoder │ └── testclient │ ├── Main.java │ └── MainLinux.java ├── ffmpeg-transcoder ├── .gitignore ├── build │ ├── .gitignore │ ├── dependency-jars.zip │ └── ffmpeg-transcoder.jar ├── pom.xml └── src │ └── main │ ├── java │ ├── com │ │ └── flashvisions │ │ │ └── server │ │ │ └── rtmp │ │ │ └── transcoder │ │ │ ├── Constants.java │ │ │ ├── command │ │ │ ├── BootstrapComplete.java │ │ │ ├── CheckFFmpegLibraries.java │ │ │ ├── InitializeEnvironment.java │ │ │ ├── InitializeVariables.java │ │ │ ├── PostTranscodeCleanupCommand.java │ │ │ └── chain │ │ │ │ └── TranscoderBootStrap.java │ │ │ ├── context │ │ │ ├── CleanUpContext.java │ │ │ ├── TranscodeRequest.java │ │ │ ├── TranscoderContext.java │ │ │ └── TranscoderOutputContext.java │ │ │ ├── data │ │ │ ├── dao │ │ │ │ └── TemplateDao.java │ │ │ └── factory │ │ │ │ ├── AbstractDAOFactory.java │ │ │ │ ├── LibRtmpConfigurationFactory.java │ │ │ │ ├── NullDAOFactory.java │ │ │ │ ├── TemplateDAOFactory.java │ │ │ │ └── TranscodeConfigurationFactory.java │ │ │ ├── decorator │ │ │ ├── MutableDecorator.java │ │ │ ├── PassThruDecorator.java │ │ │ ├── PropertyDecorator.java │ │ │ ├── RTMPTranscoderResource.java │ │ │ ├── SimpleTranscoderResource.java │ │ │ └── TranscoderResource.java │ │ │ ├── exception │ │ │ ├── InvalidCodecException.java │ │ │ ├── InvalidTranscoderResourceException.java │ │ │ ├── MalformedTranscodeQueryException.java │ │ │ ├── MediaIdentifyException.java │ │ │ ├── TranscodeConfigurationException.java │ │ │ └── TranscoderException.java │ │ │ ├── facade │ │ │ ├── GenericTranscoderFacade.java │ │ │ ├── Red5TranscoderFacade.java │ │ │ └── WowzaTranscoderFacade.java │ │ │ ├── ffmpeg │ │ │ └── Flags.java │ │ │ ├── generic │ │ │ └── command │ │ │ │ ├── AbortTranscodeCommand.java │ │ │ │ └── DoTranscodeCommand.java │ │ │ ├── handler │ │ │ ├── TranscodeSessionDestroyer.java │ │ │ ├── TranscodeSessionOutputStream.java │ │ │ └── TranscodeSessionResultHandler.java │ │ │ ├── helpers │ │ │ ├── CommandBuilderHelper.java │ │ │ ├── TemplateTokenParser.java │ │ │ └── TokenReplacer.java │ │ │ ├── interfaces │ │ │ ├── IAudio.java │ │ │ ├── IAudioBitrate.java │ │ │ ├── IAudioChannel.java │ │ │ ├── IAudioSampleRate.java │ │ │ ├── IAverageBitrate.java │ │ │ ├── ICodec.java │ │ │ ├── ICodecImplementation.java │ │ │ ├── IContainer.java │ │ │ ├── IDisposable.java │ │ │ ├── IEncode.java │ │ │ ├── IEncodeCollection.java │ │ │ ├── IEncodeIterator.java │ │ │ ├── IFileMedia.java │ │ │ ├── IFrameRate.java │ │ │ ├── IFrameSize.java │ │ │ ├── IKeyFrameInterval.java │ │ │ ├── ILibRtmpConfig.java │ │ │ ├── IMedia.java │ │ │ ├── IMutable.java │ │ │ ├── IMutableObject.java │ │ │ ├── IOverlay.java │ │ │ ├── IOverlayCollection.java │ │ │ ├── IOverlayIterator.java │ │ │ ├── IOverlayLocation.java │ │ │ ├── IParameter.java │ │ │ ├── IPassThru.java │ │ │ ├── IPassThruObject.java │ │ │ ├── IProperty.java │ │ │ ├── ISession.java │ │ │ ├── ISessionObserver.java │ │ │ ├── IStreamingMedia.java │ │ │ ├── ITranscode.java │ │ │ ├── ITranscodeDao.java │ │ │ ├── ITranscodeOutput.java │ │ │ ├── ITranscoderEntity.java │ │ │ ├── ITranscoderFacade.java │ │ │ ├── ITranscoderResource.java │ │ │ ├── IVideo.java │ │ │ ├── IVideoBitrate.java │ │ │ ├── TranscodeSessionDataCallback.java │ │ │ ├── TranscodeSessionProcessCallback.java │ │ │ └── TranscodeSessionResultCallback.java │ │ │ ├── librtmp │ │ │ ├── FMSLibRtmpConfig.java │ │ │ ├── LibRtmpConfig.java │ │ │ ├── Red5LibRtmpConfig.java │ │ │ └── WowzaLibRtmpConfig.java │ │ │ ├── managers │ │ │ └── IOManager.java │ │ │ ├── pojo │ │ │ ├── Codec.java │ │ │ ├── CodecImplementation.java │ │ │ ├── Container.java │ │ │ ├── Encode.java │ │ │ ├── Parameter.java │ │ │ ├── Property.java │ │ │ ├── Session.java │ │ │ ├── Transcode.java │ │ │ ├── TranscodeOutput.java │ │ │ ├── audio │ │ │ │ ├── Audio.java │ │ │ │ ├── AudioBitrate.java │ │ │ │ ├── AudioChannel.java │ │ │ │ ├── AudioCodec.java │ │ │ │ └── AudioSampleRate.java │ │ │ ├── base │ │ │ │ ├── MutableObject.java │ │ │ │ ├── PassThruObject.java │ │ │ │ └── TranscoderEntity.java │ │ │ ├── collection │ │ │ │ ├── EncodeCollection.java │ │ │ │ └── OverlayCollection.java │ │ │ ├── io │ │ │ │ ├── FileMedia.java │ │ │ │ ├── StreamMedia.java │ │ │ │ ├── base │ │ │ │ │ └── Media.java │ │ │ │ ├── enums │ │ │ │ │ ├── AudioChannelType.java │ │ │ │ │ ├── AudioCodecs.java │ │ │ │ │ ├── AudioSampleRates.java │ │ │ │ │ ├── CodecImplementations.java │ │ │ │ │ ├── CodecOptions.java │ │ │ │ │ ├── Format.java │ │ │ │ │ ├── Protocol.java │ │ │ │ │ ├── Server.java │ │ │ │ │ ├── SessionEvent.java │ │ │ │ │ └── VideoCodecs.java │ │ │ │ └── strategy │ │ │ │ │ ├── impl │ │ │ │ │ ├── DefaultInterpretStrategy.java │ │ │ │ │ └── RTMPInterpretStrategy.java │ │ │ │ │ └── interfaces │ │ │ │ │ └── InterpretStrategy.java │ │ │ └── video │ │ │ │ ├── AverageBitrate.java │ │ │ │ ├── DeviceBuffer.java │ │ │ │ ├── FrameRate.java │ │ │ │ ├── FrameSize.java │ │ │ │ ├── Gop.java │ │ │ │ ├── KeyFrameInterval.java │ │ │ │ ├── MaximumBitrate.java │ │ │ │ ├── MinKeyframeInterval.java │ │ │ │ ├── MinimumBitrate.java │ │ │ │ ├── Overlay.java │ │ │ │ ├── Video.java │ │ │ │ ├── VideoBitrate.java │ │ │ │ └── VideoCodec.java │ │ │ ├── pool │ │ │ └── TranscodeSessionPool.java │ │ │ ├── red5 │ │ │ └── command │ │ │ │ ├── AbortTranscodeCommand.java │ │ │ │ └── DoTranscodeCommand.java │ │ │ ├── system │ │ │ └── Globals.java │ │ │ ├── utils │ │ │ ├── IOUtils.java │ │ │ ├── SessionUtil.java │ │ │ └── TranscoderUtils.java │ │ │ ├── validation │ │ │ ├── impl │ │ │ │ ├── AudioBitrateValidator.java │ │ │ │ ├── AudioChannelValidator.java │ │ │ │ ├── AudioCodecValidator.java │ │ │ │ ├── AudioSampleRateValidator.java │ │ │ │ ├── CodecImplementationValidator.java │ │ │ │ ├── VideoBitrateValidator.java │ │ │ │ ├── VideoCodecValidator.java │ │ │ │ ├── VideoFrameRateValidator.java │ │ │ │ ├── VideoFrameSizeValidator.java │ │ │ │ └── VideoKeyframeIntervalValidator.java │ │ │ └── interfaces │ │ │ │ ├── ValidAudioBitrate.java │ │ │ │ ├── ValidAudioChannel.java │ │ │ │ ├── ValidAudioCodec.java │ │ │ │ ├── ValidAudioSampleRate.java │ │ │ │ ├── ValidCodecImplementation.java │ │ │ │ ├── ValidVideoBitrate.java │ │ │ │ ├── ValidVideoCodec.java │ │ │ │ ├── ValidVideoFrameRate.java │ │ │ │ ├── ValidVideoFrameSize.java │ │ │ │ └── ValidVideoKeyframeInterval.java │ │ │ ├── vo │ │ │ └── TranscoderExecutionError.java │ │ │ └── wowza │ │ │ └── command │ │ │ ├── AbortTranscodeCommand.java │ │ │ └── DoTranscodeCommand.java │ └── uk │ │ └── co │ │ └── jaimon │ │ └── SimpleImageInfo.java │ └── resources │ ├── ValidationMessages.properties │ └── log4j.properties ├── images ├── transcoder-service - small.png └── transcoder-service.png └── transcoder ├── images └── logo.png └── templates ├── hls-index-sample.html ├── hls-template.xml ├── image-template.xml ├── multibitrate-hls-template.xml ├── multibitrate-rtmp-template.xml ├── record-mp3-template.xml ├── record-mp4-template.xml └── rtmp-to-rtmp-template.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | # Windows image file caches 15 | Thumbs.db 16 | ehthumbs.db 17 | 18 | # Folder config file 19 | Desktop.ini 20 | 21 | # Recycle Bin used on file shares 22 | $RECYCLE.BIN/ 23 | 24 | # Windows Installer files 25 | *.cab 26 | *.msi 27 | *.msm 28 | *.msp 29 | 30 | # Windows shortcuts 31 | *.lnk 32 | 33 | # ========================= 34 | # Operating System Files 35 | # ========================= 36 | 37 | # OSX 38 | # ========================= 39 | 40 | .DS_Store 41 | .AppleDouble 42 | .LSOverride 43 | 44 | # Thumbnails 45 | ._* 46 | 47 | # Files that might appear on external disk 48 | .Spotlight-V100 49 | .Trashes 50 | 51 | # Directories potentially created on remote AFP share 52 | .AppleDB 53 | .AppleDesktop 54 | Network Trash Folder 55 | Temporary Items 56 | .apdisk 57 | 58 | # ======================= 59 | 60 | *.pydevproject 61 | .metadata 62 | .gradle 63 | bin/ 64 | tmp/ 65 | *.tmp 66 | *.bak 67 | *.swp 68 | *~.nib 69 | local.properties 70 | .settings/ 71 | .loadpath 72 | 73 | # Eclipse Core 74 | .project 75 | 76 | # External tool builders 77 | .externalToolBuilders/ 78 | 79 | # Locally stored "Eclipse launch configurations" 80 | *.launch 81 | 82 | # CDT-specific 83 | .cproject 84 | 85 | # JDT-specific (Eclipse Java Development Tools) 86 | .classpath 87 | 88 | # PDT-specific 89 | .buildpath 90 | 91 | # sbteclipse plugin 92 | .target 93 | 94 | # TeXlipse plugin 95 | .texlipse 96 | 97 | -------------------------------------------------------------------------------- /ffmpeg-transcoder-test/src/com/flashvisions/server/rtmp/transcoder/testclient/Main.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.testclient; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.context.TranscodeRequest; 7 | import com.flashvisions.server.rtmp.transcoder.decorator.RTMPTranscoderResource; 8 | import com.flashvisions.server.rtmp.transcoder.facade.GenericTranscoderFacade; 9 | import com.flashvisions.server.rtmp.transcoder.interfaces.IProperty; 10 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderFacade; 11 | import com.flashvisions.server.rtmp.transcoder.pojo.Property; 12 | import com.flashvisions.server.rtmp.transcoder.pojo.io.StreamMedia; 13 | 14 | public class Main { 15 | 16 | public static void main(String[] args) { 17 | // TODO Auto-generated method stub 18 | 19 | try 20 | { 21 | /* Boot strap */ 22 | ITranscoderFacade facade = GenericTranscoderFacade.getInstance(); 23 | facade.setFFmpegPath("C:\\ffmpeg\\bin\\ffmpeg.exe"); 24 | facade.setHomeDirectory("C:\\red5-server-1.0.5\\"); 25 | facade.setWorkingDirectory("C:\\red5-server-1.0.5\\webapps\\"); 26 | facade.setTemplateDirectory("C:\\red5-server-1.0.5\\transcoder\\templates\\"); 27 | facade.setOperatingMediaServer("red5"); 28 | facade.init(); 29 | 30 | 31 | /* Transcode request Object overrides global working directory.*/ 32 | TranscodeRequest request = new TranscodeRequest(); 33 | request.setWorkingDirectory("C:\\red5-server-1.0.5\\webapps\\live\\streams\\"); 34 | request.setTemplateFileName("record-mp4-template.xml"); 35 | request.setCleanUpSegmentsOnExit(true); 36 | 37 | 38 | /* fire request */ 39 | // ArrayList inputflags = new ArrayList(Arrays.asList(new Property("-probesize"), new Property("32"), new Property("-analyzeduration"), new Property("1000000"))); // for low latency 40 | ArrayList inputflags = new ArrayList(); 41 | facade.doTranscode(new RTMPTranscoderResource(new StreamMedia("rtmp://localhost/live/test"),inputflags), request); 42 | 43 | new java.util.Timer().schedule( 44 | new java.util.TimerTask() { 45 | @Override 46 | public void run() { 47 | // your code here 48 | ITranscoderFacade facade = GenericTranscoderFacade.getInstance(); 49 | facade.abortTranscode(); 50 | } 51 | }, 52 | 5000 53 | ); 54 | } 55 | catch (Exception e) 56 | { 57 | e.printStackTrace(); 58 | } 59 | } 60 | 61 | } 62 | 63 | -------------------------------------------------------------------------------- /ffmpeg-transcoder-test/src/com/flashvisions/server/rtmp/transcoder/testclient/MainLinux.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.testclient; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.context.TranscodeRequest; 7 | import com.flashvisions.server.rtmp.transcoder.decorator.RTMPTranscoderResource; 8 | import com.flashvisions.server.rtmp.transcoder.facade.GenericTranscoderFacade; 9 | import com.flashvisions.server.rtmp.transcoder.interfaces.IProperty; 10 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderFacade; 11 | import com.flashvisions.server.rtmp.transcoder.pojo.Property; 12 | import com.flashvisions.server.rtmp.transcoder.pojo.io.StreamMedia; 13 | 14 | public class MainLinux { 15 | 16 | public static void main(String[] args) { 17 | // TODO Auto-generated method stub 18 | 19 | try 20 | { 21 | /* Boot strap */ 22 | ITranscoderFacade facade = GenericTranscoderFacade.getInstance(); 23 | facade.setFFmpegPath("/home/rajdeeprath/bin/ffmpeg"); 24 | facade.setHomeDirectory("/home/rajdeeprath/red5-server/"); 25 | facade.setWorkingDirectory("/home/rajdeeprath/red5-server/webapps/"); 26 | facade.setTemplateDirectory("/home/rajdeeprath/red5-server/transcoder/templates/"); 27 | facade.setOperatingMediaServer("red5"); 28 | facade.init(); 29 | 30 | 31 | /* Transcode request Object - these params override the global params set in bootsrap */ 32 | TranscodeRequest request = new TranscodeRequest(); 33 | request.setWorkingDirectory("/home/rajdeeprath/red5-server/webapps/live/streams/hls/"); 34 | request.setTemplateFileName("hls-template.xml"); 35 | request.setCleanUpSegmentsOnExit(true); 36 | 37 | 38 | /* fire request */ 39 | // ArrayList inputflags = new ArrayList(Arrays.asList(new Property("-probesize"), new Property("32"), new Property("-analyzeduration"), new Property("1000000"))); // for low latency 40 | ArrayList inputflags = new ArrayList(); 41 | facade.doTranscode(new RTMPTranscoderResource(new StreamMedia("rtmp://localhost/live/test"),inputflags), request); 42 | 43 | /* 44 | new java.util.Timer().schedule( 45 | new java.util.TimerTask() { 46 | @Override 47 | public void run() { 48 | // your code here 49 | ITranscoderFacade facade = GenericTranscoderFacade.getInstance(); 50 | facade.abortTranscode(); 51 | } 52 | }, 53 | 5000 54 | ); 55 | */ 56 | } 57 | catch (Exception e) 58 | { 59 | e.printStackTrace(); 60 | } 61 | } 62 | 63 | } 64 | 65 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/build/.gitignore: -------------------------------------------------------------------------------- 1 | !*.jar 2 | !*.zip -------------------------------------------------------------------------------- /ffmpeg-transcoder/build/dependency-jars.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajdeeprath/poor-man-transcoder/af2ce882462e99d283abb7a45dfcc4c8d67ff402/ffmpeg-transcoder/build/dependency-jars.zip -------------------------------------------------------------------------------- /ffmpeg-transcoder/build/ffmpeg-transcoder.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajdeeprath/poor-man-transcoder/af2ce882462e99d283abb7a45dfcc4c8d67ff402/ffmpeg-transcoder/build/ffmpeg-transcoder.jar -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/Constants.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder; 2 | 3 | public class Constants { 4 | 5 | public static final String DEFAULT_HLS_SAMPLE_PLAYBACK_TEMPLATE = "hls-index-sample.html"; 6 | public static final String DEFAULT_OUTPUT_HLS_PLAYBACK_TEMPLATE = "index.html"; 7 | public static final String TRANSCODER_SESSION_ATTR = "TRANSCODERSESSION"; 8 | } 9 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/command/BootstrapComplete.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.command; 2 | 3 | import org.apache.commons.chain.Command; 4 | import org.apache.commons.chain.Context; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import com.flashvisions.server.rtmp.transcoder.context.TranscoderContext; 9 | 10 | 11 | public class BootstrapComplete implements Command { 12 | 13 | private static Logger logger = LoggerFactory.getLogger(BootstrapComplete.class); 14 | 15 | @Override 16 | public boolean execute(Context context) throws Exception 17 | { 18 | // TODO Auto-generated method stub 19 | logger.info("Bootstrap complete"); 20 | logger.info("Transcoder ready"); 21 | 22 | TranscoderContext ctx = (TranscoderContext) context; 23 | ctx.setContextReady(true); 24 | 25 | return false; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/command/CheckFFmpegLibraries.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.command; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.util.List; 5 | 6 | import org.apache.commons.chain.Command; 7 | import org.apache.commons.chain.Context; 8 | import org.apache.commons.exec.CommandLine; 9 | import org.apache.commons.exec.DefaultExecutor; 10 | import org.apache.commons.exec.ExecuteWatchdog; 11 | import org.apache.commons.exec.PumpStreamHandler; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import com.flashvisions.server.rtmp.transcoder.context.TranscoderContext; 16 | import com.flashvisions.server.rtmp.transcoder.exception.TranscoderException; 17 | import com.flashvisions.server.rtmp.transcoder.utils.TranscoderUtils; 18 | 19 | public class CheckFFmpegLibraries implements Command { 20 | 21 | private static Logger logger = LoggerFactory.getLogger(CheckFFmpegLibraries.class); 22 | 23 | @Override 24 | public boolean execute(Context context) throws Exception { 25 | // TODO Auto-generated method stub 26 | logger.info("Check FFmpeg Libraries"); 27 | 28 | long timeout = 2000; // 2sec 29 | CommandLine commandline; 30 | PumpStreamHandler streamHandler; 31 | ByteArrayOutputStream stdout; 32 | DefaultExecutor exec; 33 | 34 | try 35 | { 36 | TranscoderContext ctx = (TranscoderContext) context; 37 | 38 | commandline = CommandLine.parse(ctx.getFFmpegPath()); 39 | commandline.addArgument("-version"); 40 | 41 | stdout = new ByteArrayOutputStream(); 42 | streamHandler = new PumpStreamHandler(stdout); 43 | 44 | exec = new DefaultExecutor(); 45 | exec.setWatchdog(new ExecuteWatchdog(timeout)); 46 | exec.setStreamHandler(streamHandler); 47 | exec.execute(commandline); 48 | String capturedOutput = stdout.toString(); 49 | 50 | 51 | /************* get all libraries *************/ 52 | List libraries = TranscoderUtils.captureLibraries(capturedOutput); 53 | ctx.setSupportedLibraries(libraries); 54 | 55 | 56 | /************* get version *************/ 57 | String version = TranscoderUtils.captureVersion(capturedOutput); 58 | logger.info("FFmpeg version " + version); 59 | ctx.setFfmpegVersion(version); 60 | 61 | 62 | } 63 | catch(Exception e) 64 | { 65 | logger.error("Fffmpeg check failed " + e.getMessage()); 66 | throw new TranscoderException(e); 67 | } 68 | finally 69 | { 70 | commandline = null; 71 | stdout = null; 72 | streamHandler = null; 73 | exec = null; 74 | } 75 | 76 | 77 | return false; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/command/InitializeEnvironment.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.command; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.chain.Command; 7 | import org.apache.commons.chain.Context; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.flashvisions.server.rtmp.transcoder.context.TranscoderContext; 12 | import com.flashvisions.server.rtmp.transcoder.exception.TranscoderException; 13 | import com.flashvisions.server.rtmp.transcoder.system.Globals; 14 | import com.flashvisions.server.rtmp.transcoder.utils.TranscoderUtils; 15 | 16 | public class InitializeEnvironment implements Command { 17 | 18 | private static Logger logger = LoggerFactory.getLogger(InitializeEnvironment.class); 19 | 20 | @Override 21 | public boolean execute(Context context) throws Exception { 22 | 23 | logger.info("Initialize Environment"); 24 | 25 | try 26 | { 27 | TranscoderContext ctx = (TranscoderContext) context; 28 | 29 | if(ctx.getFFmpegPath() == null) 30 | throw new IOException("Please specify ffmpeg executable path"); 31 | Globals.addEnv(Globals.Vars.FFMPEG_EXECUTABLE_PATH, ctx.getFFmpegPath()); 32 | logger.info("Ffmpeg binary " + Globals.getEnv(Globals.Vars.FFMPEG_EXECUTABLE_PATH)); 33 | 34 | if(ctx.getHomeDirectory() == null) 35 | throw new IOException("Media server home directory not specified"); 36 | File home = new File(ctx.getHomeDirectory()); 37 | if(!home.exists()) throw new IOException("Invalid server home directory. Does not exist!"); 38 | Globals.addEnv(Globals.Vars.HOME_DIRECTORY, ctx.getHomeDirectory()); 39 | logger.info("Home directory " + ctx.getHomeDirectory()); 40 | 41 | 42 | if(ctx.getTemplateDirectory() == null) 43 | throw new IOException("Templates directory not specified"); 44 | File templatesHome = new File(ctx.getTemplateDirectory()); 45 | if(!templatesHome.exists()) throw new IOException("Invalid templates directory. Does not exist!"); 46 | Globals.addEnv(Globals.Vars.TEMPLATE_DIRECTORY, ctx.getTemplateDirectory()); 47 | logger.info("Templates directory " + ctx.getWorkingDirectory()); 48 | 49 | if(ctx.getWorkingDirectory() == null) 50 | throw new IOException("Global working directory not specified"); 51 | File working = new File(ctx.getWorkingDirectory()); 52 | if(!working.exists()) throw new IOException("Invalid working directory. Does nto exist!"); 53 | Globals.addEnv(Globals.Vars.WORKING_DIRECTORY, ctx.getWorkingDirectory()); 54 | logger.info("Working directory " + ctx.getWorkingDirectory()); 55 | 56 | if(ctx.getOperatingMediaServer().equalsIgnoreCase(null) || ctx.getOperatingMediaServer() == null || !TranscoderUtils.isValidMediaServer(ctx.getOperatingMediaServer())) 57 | throw new IllegalArgumentException("Invalid media server type"); 58 | Globals.addEnv(Globals.Vars.OPERATING_SERVER, ctx.getOperatingMediaServer()); 59 | logger.info("Media server " + ctx.getOperatingMediaServer()); 60 | } 61 | catch(Exception e) 62 | { 63 | logger.error("Transcoder initialization failed " + e.getMessage()); 64 | throw new TranscoderException(e); 65 | } 66 | 67 | // TODO Auto-generated method stub 68 | return false; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/command/InitializeVariables.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.command; 2 | 3 | import org.apache.commons.chain.Command; 4 | import org.apache.commons.chain.Context; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import com.flashvisions.server.rtmp.transcoder.context.TranscoderContext; 9 | import com.flashvisions.server.rtmp.transcoder.exception.TranscoderException; 10 | import com.flashvisions.server.rtmp.transcoder.pool.TranscodeSessionPool; 11 | 12 | 13 | public class InitializeVariables implements Command { 14 | 15 | private static Logger logger = LoggerFactory.getLogger(InitializeVariables.class); 16 | 17 | @Override 18 | public boolean execute(Context context) throws Exception { 19 | // TODO Auto-generated method stub 20 | 21 | logger.info("Initialize Variables"); 22 | 23 | try 24 | { 25 | TranscoderContext ctx = (TranscoderContext) context; 26 | TranscodeSessionPool pool = new TranscodeSessionPool(ctx); 27 | ctx.setPool(pool); 28 | } 29 | catch(Exception e) 30 | { 31 | logger.error("Transcoder initialization failed " + e.getMessage()); 32 | throw new TranscoderException(e); 33 | } 34 | 35 | return false; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/command/PostTranscodeCleanupCommand.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.command; 2 | 3 | 4 | import java.io.File; 5 | import java.util.ArrayList; 6 | 7 | import org.apache.commons.chain.Command; 8 | import org.apache.commons.chain.Context; 9 | import org.apache.commons.io.FileUtils; 10 | import org.apache.commons.io.FilenameUtils; 11 | 12 | import com.flashvisions.server.rtmp.transcoder.context.CleanUpContext; 13 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderResource; 14 | 15 | @SuppressWarnings("unused") 16 | public class PostTranscodeCleanupCommand implements Command { 17 | 18 | 19 | @Override 20 | public boolean execute(Context context) throws Exception { 21 | 22 | CleanUpContext ctx = (CleanUpContext) context; 23 | 24 | ITranscoderResource input = ctx.getInput(); 25 | ArrayList outputs = ctx.getOutputs(); 26 | String workingDirectory = ctx.getWorkingDirectory(); 27 | 28 | 29 | for(ITranscoderResource output : outputs) 30 | { 31 | switch(output.getContainer().getType()) 32 | { 33 | case SSEGMENT: 34 | String outName = output.getMediaName(); 35 | String outNameWithOutExt = FilenameUtils.removeExtension(outName); 36 | File sub = new File(workingDirectory + File.separator + outNameWithOutExt); 37 | if(sub.exists()) 38 | FileUtils.deleteDirectory(sub); 39 | break; 40 | 41 | default: 42 | break; 43 | } 44 | } 45 | 46 | 47 | return false; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/command/chain/TranscoderBootStrap.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.command.chain; 2 | 3 | import org.apache.commons.chain.impl.ChainBase; 4 | 5 | import com.flashvisions.server.rtmp.transcoder.command.BootstrapComplete; 6 | import com.flashvisions.server.rtmp.transcoder.command.CheckFFmpegLibraries; 7 | import com.flashvisions.server.rtmp.transcoder.command.InitializeEnvironment; 8 | import com.flashvisions.server.rtmp.transcoder.command.InitializeVariables; 9 | 10 | public class TranscoderBootStrap extends ChainBase { 11 | 12 | public TranscoderBootStrap() 13 | { 14 | super(); 15 | 16 | addCommand(new InitializeEnvironment()); 17 | addCommand(new CheckFFmpegLibraries()); 18 | addCommand(new InitializeVariables()); 19 | addCommand(new BootstrapComplete()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/context/CleanUpContext.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.context; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.apache.commons.chain.Context; 6 | import org.apache.commons.chain.impl.ContextBase; 7 | 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderResource; 9 | 10 | public class CleanUpContext extends ContextBase implements Context { 11 | 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = -710512383393541304L; 16 | 17 | 18 | private ITranscoderResource input; 19 | private ArrayList outputs; 20 | private String workingDirectory; 21 | 22 | 23 | 24 | public ITranscoderResource getInput() { 25 | return input; 26 | } 27 | public void setInput(ITranscoderResource input) { 28 | this.input = input; 29 | } 30 | public ArrayList getOutputs() { 31 | return outputs; 32 | } 33 | public void setOutputs(ArrayList outputs) { 34 | this.outputs = outputs; 35 | } 36 | public String getWorkingDirectory() { 37 | return workingDirectory; 38 | } 39 | public void setWorkingDirectory(String workingDirectory) { 40 | this.workingDirectory = workingDirectory; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/context/TranscodeRequest.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.context; 2 | 3 | 4 | public class TranscodeRequest { 5 | 6 | private String workingDirectoryPath; 7 | private String templateFileName; 8 | private boolean cleanUpSegmentsOnExit; 9 | 10 | 11 | public void setWorkingDirectory(String workingDirectoryPath) { 12 | // TODO Auto-generated method stub 13 | this.workingDirectoryPath = workingDirectoryPath; 14 | } 15 | 16 | public String getWorkingDirectory() { 17 | // TODO Auto-generated method stub 18 | return workingDirectoryPath; 19 | } 20 | 21 | public String getTemplateFileName() { 22 | return templateFileName; 23 | } 24 | 25 | public void setTemplateFileName(String templateFileName) { 26 | this.templateFileName = templateFileName; 27 | } 28 | 29 | public boolean isCleanUpSegmentsOnExit() { 30 | return cleanUpSegmentsOnExit; 31 | } 32 | 33 | public void setCleanUpSegmentsOnExit(boolean cleanUpSegmentsOnExit) { 34 | this.cleanUpSegmentsOnExit = cleanUpSegmentsOnExit; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/context/TranscoderOutputContext.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.context; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.apache.commons.chain.Context; 6 | import org.apache.commons.chain.impl.ContextBase; 7 | 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.ISession; 9 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderResource; 10 | 11 | 12 | public class TranscoderOutputContext extends ContextBase implements Context { 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = -6055565161013950468L; 18 | 19 | private ITranscoderResource input; 20 | private ArrayList outputs; 21 | private String workingDirectory; 22 | 23 | private ISession session; 24 | 25 | 26 | public TranscoderOutputContext(ISession session) 27 | { 28 | this.setSession(session); 29 | 30 | this.setInput(session.getInputSource()); 31 | this.setOutputs(session.getOutputs()); 32 | this.setWorkingDirectory(session.getWorkingDirectoryPath()); 33 | } 34 | 35 | public TranscoderOutputContext() 36 | { 37 | 38 | } 39 | 40 | public ITranscoderResource getInput() { 41 | return input; 42 | } 43 | 44 | public void setInput(ITranscoderResource input) { 45 | this.input = input; 46 | } 47 | 48 | public ArrayList getOutputs() { 49 | return outputs; 50 | } 51 | 52 | public void setOutputs(ArrayList outputs) { 53 | this.outputs = outputs; 54 | } 55 | 56 | public String getWorkingDirectory() { 57 | return workingDirectory; 58 | } 59 | 60 | public void setWorkingDirectory(String workingDirectory) { 61 | this.workingDirectory = workingDirectory; 62 | } 63 | 64 | public ISession getSession() { 65 | return session; 66 | } 67 | 68 | public void setSession(ISession session) { 69 | this.session = session; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/data/factory/AbstractDAOFactory.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.data.factory; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscodeDao; 4 | 5 | public abstract class AbstractDAOFactory { 6 | 7 | public static final int FROM_XML_TEMPLATE = 1; 8 | 9 | public abstract ITranscodeDao getTranscodeDao(String filename); 10 | 11 | /***** Using factory pattern to keep flexibility for future. This leaves flexibility to load template from database / file ******/ 12 | public static AbstractDAOFactory getDAOFactory(int type) 13 | { 14 | switch(type) 15 | { 16 | case FROM_XML_TEMPLATE: 17 | return new TemplateDAOFactory(); 18 | 19 | default: 20 | return new NullDAOFactory(); 21 | 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/data/factory/LibRtmpConfigurationFactory.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.data.factory; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.interfaces.ILibRtmpConfig; 4 | import com.flashvisions.server.rtmp.transcoder.librtmp.FMSLibRtmpConfig; 5 | import com.flashvisions.server.rtmp.transcoder.librtmp.Red5LibRtmpConfig; 6 | import com.flashvisions.server.rtmp.transcoder.librtmp.WowzaLibRtmpConfig; 7 | import com.flashvisions.server.rtmp.transcoder.pojo.io.enums.Server; 8 | 9 | public class LibRtmpConfigurationFactory { 10 | 11 | public static ILibRtmpConfig getLibRtmpConfiguration(Server type) 12 | { 13 | switch(type) 14 | { 15 | case RED5: 16 | return new Red5LibRtmpConfig(); 17 | 18 | case WOWZA: 19 | return new WowzaLibRtmpConfig(); 20 | 21 | case FMS: 22 | return new FMSLibRtmpConfig(); 23 | } 24 | 25 | return null; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/data/factory/NullDAOFactory.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.data.factory; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscodeDao; 4 | 5 | public class NullDAOFactory extends AbstractDAOFactory { 6 | 7 | @Override 8 | public ITranscodeDao getTranscodeDao(String filename) { 9 | // TODO Auto-generated method stub 10 | return null; 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/data/factory/TemplateDAOFactory.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.data.factory; 2 | 3 | import java.io.File; 4 | 5 | import com.flashvisions.server.rtmp.transcoder.data.dao.TemplateDao; 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscodeDao; 7 | import com.flashvisions.server.rtmp.transcoder.system.Globals; 8 | 9 | 10 | public class TemplateDAOFactory extends AbstractDAOFactory 11 | { 12 | @Override 13 | public ITranscodeDao getTranscodeDao(String filename) { 14 | // TODO Auto-generated method stub 15 | return new TemplateDao(Globals.getEnv(Globals.Vars.TEMPLATE_DIRECTORY) + File.separator + filename); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/data/factory/TranscodeConfigurationFactory.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.data.factory; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscode; 7 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscodeDao; 8 | 9 | 10 | /** 11 | * @author Rajdeep 12 | * 13 | * Factory responsible for creating and dispatching 14 | * transcode configuration object (ITranscode type). 15 | * 16 | * Uses cache to avoid reloading of template data 17 | * for a given template. 18 | */ 19 | public class TranscodeConfigurationFactory { 20 | 21 | private static TranscodeConfigurationFactory instance; 22 | private AbstractDAOFactory daoFactory; 23 | private static Map cache = null; 24 | 25 | 26 | private TranscodeConfigurationFactory(){ 27 | cache = new HashMap(); 28 | } 29 | 30 | public AbstractDAOFactory getDaoFactory() { 31 | return daoFactory; 32 | } 33 | 34 | public void setDaoSupplier(AbstractDAOFactory daoFactory) { 35 | this.daoFactory = daoFactory; 36 | } 37 | 38 | public ITranscode getTranscodeConfiguration(String template) 39 | { 40 | ITranscode config; 41 | 42 | try 43 | { 44 | if(!cache.containsKey(template)) 45 | throw new Exception("Configuration found not in cache"); 46 | 47 | config = cache.get(template); 48 | 49 | if(config == null) 50 | throw new Exception("Configuration is null"); 51 | 52 | } 53 | catch(Exception e) 54 | { 55 | config = buildTranscodeConfiguration(template); 56 | cache.put(template, config); 57 | } 58 | 59 | return config; 60 | } 61 | 62 | private ITranscode buildTranscodeConfiguration(String template) 63 | { 64 | ITranscodeDao dao = this.daoFactory.getTranscodeDao(template); 65 | ITranscode config = dao.getTranscodeConfig(); 66 | return config; 67 | } 68 | 69 | /** 70 | * @author Rajdeep 71 | * 72 | * singleton access method for this factory 73 | */ 74 | public static TranscodeConfigurationFactory getInstance() 75 | { 76 | if(instance == null) instance = new TranscodeConfigurationFactory(); 77 | return instance; 78 | } 79 | } -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/decorator/MutableDecorator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.decorator; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.decorator.PropertyDecorator; 4 | import com.flashvisions.server.rtmp.transcoder.interfaces.IMutable; 5 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderEntity; 6 | 7 | public class MutableDecorator extends PropertyDecorator implements IMutable { 8 | 9 | private boolean enabled; 10 | 11 | public MutableDecorator(ITranscoderEntity property) 12 | { 13 | super(property); 14 | } 15 | 16 | @Override 17 | public boolean getEnabled() { 18 | // TODO Auto-generated method stub 19 | return enabled; 20 | } 21 | 22 | @Override 23 | public void setEnabled(boolean enabled) { 24 | // TODO Auto-generated method stub 25 | this.enabled = enabled; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/decorator/PassThruDecorator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.decorator; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.decorator.PropertyDecorator; 4 | import com.flashvisions.server.rtmp.transcoder.interfaces.IPassThru; 5 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderEntity; 6 | 7 | public class PassThruDecorator extends PropertyDecorator implements IPassThru { 8 | 9 | private boolean sameAsSource; 10 | private boolean ignore = false; 11 | 12 | public PassThruDecorator(ITranscoderEntity property) 13 | { 14 | super(property); 15 | } 16 | 17 | @Override 18 | public void setSameAsSource(boolean sameAsSource) { 19 | // TODO Auto-generated method stub 20 | this.sameAsSource = sameAsSource; 21 | } 22 | 23 | @Override 24 | public boolean getSameAsSource() { 25 | // TODO Auto-generated method stub 26 | return sameAsSource; 27 | } 28 | 29 | @Override 30 | public void setIgnore(boolean ignore) { 31 | // TODO Auto-generated method stub 32 | this.ignore = ignore; 33 | } 34 | 35 | @Override 36 | public boolean getIgnore() { 37 | // TODO Auto-generated method stub 38 | return ignore; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/decorator/PropertyDecorator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.decorator; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderEntity; 4 | 5 | public abstract class PropertyDecorator implements ITranscoderEntity { 6 | 7 | protected ITranscoderEntity property; 8 | 9 | public PropertyDecorator(ITranscoderEntity property){ 10 | this.property = property; 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/decorator/RTMPTranscoderResource.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.decorator; 2 | 3 | import java.util.ArrayList; 4 | 5 | import com.flashvisions.server.rtmp.transcoder.exception.InvalidTranscoderResourceException; 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IMedia; 7 | import com.flashvisions.server.rtmp.transcoder.interfaces.IProperty; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderResource; 9 | import com.flashvisions.server.rtmp.transcoder.pojo.io.strategy.impl.RTMPInterpretStrategy; 10 | import com.flashvisions.server.rtmp.transcoder.pojo.io.strategy.interfaces.InterpretStrategy; 11 | 12 | public class RTMPTranscoderResource extends TranscoderResource implements ITranscoderResource{ 13 | 14 | public RTMPTranscoderResource(IMedia media) throws InvalidTranscoderResourceException{ 15 | super(media); 16 | setStrategy(new RTMPInterpretStrategy()); 17 | } 18 | 19 | public RTMPTranscoderResource(IMedia media, ArrayList flags) throws InvalidTranscoderResourceException{ 20 | super(media, flags); 21 | setStrategy(new RTMPInterpretStrategy()); 22 | } 23 | 24 | public RTMPTranscoderResource(IMedia media, InterpretStrategy strategy) throws InvalidTranscoderResourceException{ 25 | super(media, strategy); 26 | } 27 | 28 | public RTMPTranscoderResource(IMedia media, InterpretStrategy strategy, ArrayList flags) throws InvalidTranscoderResourceException{ 29 | super(media, strategy, flags); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/decorator/SimpleTranscoderResource.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.decorator; 2 | 3 | import java.util.ArrayList; 4 | 5 | import com.flashvisions.server.rtmp.transcoder.exception.InvalidTranscoderResourceException; 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IMedia; 7 | import com.flashvisions.server.rtmp.transcoder.interfaces.IProperty; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderResource; 9 | import com.flashvisions.server.rtmp.transcoder.pojo.io.strategy.interfaces.InterpretStrategy; 10 | 11 | public class SimpleTranscoderResource extends TranscoderResource implements ITranscoderResource{ 12 | 13 | public SimpleTranscoderResource(IMedia media) throws InvalidTranscoderResourceException{ 14 | super(media); 15 | } 16 | 17 | public SimpleTranscoderResource(IMedia media, ArrayList flags) throws InvalidTranscoderResourceException{ 18 | super(media, flags); 19 | } 20 | 21 | public SimpleTranscoderResource(IMedia media, InterpretStrategy strategy) throws InvalidTranscoderResourceException{ 22 | super(media, strategy); 23 | } 24 | 25 | public SimpleTranscoderResource(IMedia media, InterpretStrategy strategy, ArrayList flags) throws InvalidTranscoderResourceException{ 26 | super(media, strategy, flags); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/exception/InvalidCodecException.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.exception; 2 | 3 | public class InvalidCodecException extends Exception { 4 | 5 | 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = 1722410653282508611L; 10 | private Exception rootCauseException; 11 | private String message = null; 12 | 13 | public InvalidCodecException() { 14 | super(); 15 | } 16 | 17 | public InvalidCodecException(Exception rootCauseException) { 18 | super(rootCauseException); 19 | this.setRootCauseException(rootCauseException); 20 | this.message = rootCauseException.getMessage(); 21 | } 22 | 23 | public InvalidCodecException(String message) { 24 | super(message); 25 | this.message = message; 26 | } 27 | 28 | public InvalidCodecException(Throwable cause) { 29 | super(cause); 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return message; 35 | } 36 | 37 | @Override 38 | public String getMessage() { 39 | return message; 40 | } 41 | 42 | public Exception getRootCauseException() { 43 | return rootCauseException; 44 | } 45 | 46 | public void setRootCauseException(Exception rootCauseException) { 47 | this.rootCauseException = rootCauseException; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/exception/InvalidTranscoderResourceException.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.exception; 2 | 3 | public class InvalidTranscoderResourceException extends Exception { 4 | 5 | 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = 1722410653282508611L; 10 | private Exception rootCauseException; 11 | private String message = null; 12 | 13 | public InvalidTranscoderResourceException() { 14 | super(); 15 | } 16 | 17 | public InvalidTranscoderResourceException(Exception rootCauseException) { 18 | super(rootCauseException); 19 | this.setRootCauseException(rootCauseException); 20 | this.message = rootCauseException.getMessage(); 21 | } 22 | 23 | public InvalidTranscoderResourceException(String message) { 24 | super(message); 25 | this.message = message; 26 | } 27 | 28 | public InvalidTranscoderResourceException(Throwable cause) { 29 | super(cause); 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return message; 35 | } 36 | 37 | @Override 38 | public String getMessage() { 39 | return message; 40 | } 41 | 42 | public Exception getRootCauseException() { 43 | return rootCauseException; 44 | } 45 | 46 | public void setRootCauseException(Exception rootCauseException) { 47 | this.rootCauseException = rootCauseException; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/exception/MalformedTranscodeQueryException.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.exception; 2 | 3 | public class MalformedTranscodeQueryException extends Exception { 4 | 5 | 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = 1722410653282508611L; 10 | private Exception rootCauseException; 11 | private String message = null; 12 | 13 | public MalformedTranscodeQueryException() { 14 | super(); 15 | } 16 | 17 | public MalformedTranscodeQueryException(Exception rootCauseException) { 18 | super(rootCauseException); 19 | this.setRootCauseException(rootCauseException); 20 | this.message = rootCauseException.getMessage(); 21 | } 22 | 23 | public MalformedTranscodeQueryException(String message) { 24 | super(message); 25 | this.message = message; 26 | } 27 | 28 | public MalformedTranscodeQueryException(Throwable cause) { 29 | super(cause); 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return message; 35 | } 36 | 37 | @Override 38 | public String getMessage() { 39 | return message; 40 | } 41 | 42 | public Exception getRootCauseException() { 43 | return rootCauseException; 44 | } 45 | 46 | public void setRootCauseException(Exception rootCauseException) { 47 | this.rootCauseException = rootCauseException; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/exception/MediaIdentifyException.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.exception; 2 | 3 | public class MediaIdentifyException extends Exception { 4 | 5 | 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = 1722410653282508611L; 10 | private Exception rootCauseException; 11 | private String message = null; 12 | 13 | public MediaIdentifyException() { 14 | super(); 15 | } 16 | 17 | public MediaIdentifyException(Exception rootCauseException) { 18 | super(rootCauseException); 19 | this.setRootCauseException(rootCauseException); 20 | this.message = rootCauseException.getMessage(); 21 | } 22 | 23 | public MediaIdentifyException(String message) { 24 | super(message); 25 | this.message = message; 26 | } 27 | 28 | public MediaIdentifyException(Throwable cause) { 29 | super(cause); 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return message; 35 | } 36 | 37 | @Override 38 | public String getMessage() { 39 | return message; 40 | } 41 | 42 | public Exception getRootCauseException() { 43 | return rootCauseException; 44 | } 45 | 46 | public void setRootCauseException(Exception rootCauseException) { 47 | this.rootCauseException = rootCauseException; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/exception/TranscodeConfigurationException.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.exception; 2 | 3 | public class TranscodeConfigurationException extends Exception { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = 1L; 9 | 10 | private Exception rootCauseException; 11 | private String message = null; 12 | 13 | public TranscodeConfigurationException() { 14 | super(); 15 | } 16 | 17 | public TranscodeConfigurationException(Exception rootCauseException) { 18 | super(rootCauseException); 19 | this.setRootCauseException(rootCauseException); 20 | this.message = rootCauseException.getMessage(); 21 | } 22 | 23 | public TranscodeConfigurationException(String message) { 24 | super(message); 25 | this.message = message; 26 | } 27 | 28 | public TranscodeConfigurationException(Throwable cause) { 29 | super(cause); 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return message; 35 | } 36 | 37 | @Override 38 | public String getMessage() { 39 | return message; 40 | } 41 | 42 | public Exception getRootCauseException() { 43 | return rootCauseException; 44 | } 45 | 46 | public void setRootCauseException(Exception rootCauseException) { 47 | this.rootCauseException = rootCauseException; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/exception/TranscoderException.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.exception; 2 | 3 | public class TranscoderException extends Exception { 4 | 5 | 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = 1722410653282508611L; 10 | private Exception rootCauseException; 11 | private String message = null; 12 | 13 | public TranscoderException() { 14 | super(); 15 | } 16 | 17 | public TranscoderException(Exception rootCauseException) { 18 | super(rootCauseException); 19 | this.setRootCauseException(rootCauseException); 20 | this.message = rootCauseException.getMessage(); 21 | } 22 | 23 | public TranscoderException(String message) { 24 | super(message); 25 | this.message = message; 26 | } 27 | 28 | public TranscoderException(Throwable cause) { 29 | super(cause); 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return message; 35 | } 36 | 37 | @Override 38 | public String getMessage() { 39 | return message; 40 | } 41 | 42 | public Exception getRootCauseException() { 43 | return rootCauseException; 44 | } 45 | 46 | public void setRootCauseException(Exception rootCauseException) { 47 | this.rootCauseException = rootCauseException; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/facade/WowzaTranscoderFacade.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.facade; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.command.chain.TranscoderBootStrap; 7 | import com.flashvisions.server.rtmp.transcoder.context.TranscodeRequest; 8 | import com.flashvisions.server.rtmp.transcoder.context.TranscoderContext; 9 | import com.flashvisions.server.rtmp.transcoder.exception.TranscoderException; 10 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderFacade; 11 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderResource; 12 | import com.flashvisions.server.rtmp.transcoder.wowza.command.AbortTranscodeCommand; 13 | import com.flashvisions.server.rtmp.transcoder.wowza.command.DoTranscodeCommand; 14 | 15 | public class WowzaTranscoderFacade implements ITranscoderFacade { 16 | 17 | 18 | private static Logger logger = LoggerFactory.getLogger(WowzaTranscoderFacade.class); 19 | 20 | private static TranscoderContext context; 21 | private static volatile ITranscoderFacade instance; 22 | private static boolean bootstrap = false; 23 | 24 | 25 | private WowzaTranscoderFacade(){ 26 | context = new TranscoderContext(); 27 | } 28 | 29 | public static ITranscoderFacade getInstance() 30 | { 31 | if(instance == null) 32 | { 33 | synchronized (WowzaTranscoderFacade.class){ 34 | if(instance == null){ 35 | instance = new WowzaTranscoderFacade(); 36 | } 37 | } 38 | } 39 | 40 | return instance; 41 | } 42 | 43 | 44 | @Override 45 | public synchronized void init() throws TranscoderException { 46 | // TODO Auto-generated method stub 47 | try 48 | { 49 | if(!bootstrap) 50 | new TranscoderBootStrap().execute(context); 51 | } 52 | catch(Exception e) 53 | { 54 | logger.info(e.getMessage()); 55 | } 56 | finally 57 | { 58 | bootstrap = true; 59 | } 60 | } 61 | 62 | @Override 63 | public void setFFmpegPath(String ffmpegPath) { 64 | // TODO Auto-generated method stub 65 | context.setFFmpegPath(ffmpegPath); 66 | } 67 | 68 | @Override 69 | public String getFFmpegPath() { 70 | // TODO Auto-generated method stub 71 | return context.getFFmpegPath(); 72 | } 73 | 74 | @Override 75 | public void setOperatingMediaServer(String serverName) { 76 | // TODO Auto-generated method stub 77 | context.setOperatingMediaServer(serverName); 78 | } 79 | 80 | @Override 81 | public String getOperatingMediaServer() { 82 | // TODO Auto-generated method stub 83 | return context.getOperatingMediaServer(); 84 | } 85 | 86 | @Override 87 | public void setWorkingDirectory(String workingDirectoryPath) { 88 | // TODO Auto-generated method stub 89 | context.setWorkingDirectory(workingDirectoryPath); 90 | } 91 | 92 | @Override 93 | public String getWorkingDirectory() { 94 | // TODO Auto-generated method stub 95 | return context.getWorkingDirectory(); 96 | } 97 | 98 | @Override 99 | public void setTemplateDirectory(String templateDirectoryPath) { 100 | // TODO Auto-generated method stub 101 | context.setTemplateDirectory(templateDirectoryPath); 102 | } 103 | 104 | @Override 105 | public String getTemplateDirectory() { 106 | // TODO Auto-generated method stub 107 | return context.getTemplateDirectory(); 108 | } 109 | 110 | @Override 111 | public void setHomeDirectory(String homeDirectoryPath) { 112 | // TODO Auto-generated method stub 113 | context.setHomeDirectory(homeDirectoryPath); 114 | } 115 | 116 | @Override 117 | public String getHomeDirectory() { 118 | // TODO Auto-generated method stub 119 | return context.getHomeDirectory(); 120 | } 121 | 122 | @Override 123 | public void doTranscode(ITranscoderResource input, TranscodeRequest request) throws TranscoderException 124 | { 125 | try 126 | { 127 | new DoTranscodeCommand(input, request).execute(context); 128 | } 129 | catch (Exception e) 130 | { 131 | logger.error("doTranscode ->"+e.getMessage()); 132 | } 133 | } 134 | 135 | @Override 136 | public void abortTranscode() { 137 | 138 | try 139 | { 140 | new AbortTranscodeCommand().execute(context); 141 | } 142 | catch (Exception e) 143 | { 144 | logger.error(e.getMessage()); 145 | } 146 | 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/ffmpeg/Flags.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.ffmpeg; 2 | 3 | public class Flags { 4 | 5 | public static final String DASH = "-"; 6 | 7 | public static final String INPUT = DASH + "i"; 8 | 9 | public static final String DISABLE_AUDIO = DASH + "an"; 10 | public static final String DISABLE_VIDEO = DASH + "vn"; 11 | 12 | public static final String OVERWRITE = DASH + "y"; 13 | public static final String OUTPUT = DASH + "f"; 14 | 15 | public static final String VIDEO_BITRATE = DASH + "b:v"; 16 | public static final String VIDEO_BUFFER = DASH + "bufsize"; 17 | public static final String VIDEO_FRAMERATE = DASH + "r"; 18 | public static final String VIDEO_FRAMESIZE = DASH + "s"; 19 | public static final String VIDEO_GOP = DASH + "g"; 20 | public static final String VIDEO_MIN_KFI = DASH + "keyint_min"; 21 | public static final String VIDEO_MAXBITRATE = DASH + "maxrate"; 22 | public static final String VIDEO_MINBITRATE = DASH + "minrate"; 23 | public static final String VIDEO_CODEC = DASH + "codec:v"; 24 | 25 | public static final String AUDIO_BITRATE = DASH + "b:a"; 26 | public static final String AUDIO_CHANNEL = DASH + "ac"; 27 | public static final String AUDIO_SAMPLERATE = DASH + "ar"; 28 | public static final String AUDIO_CODEC = DASH + "codec:a"; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/generic/command/AbortTranscodeCommand.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.generic.command; 2 | 3 | import org.apache.commons.chain.Command; 4 | import org.apache.commons.chain.Context; 5 | 6 | public class AbortTranscodeCommand implements Command { 7 | 8 | @Override 9 | public boolean execute(Context context) throws Exception { 10 | // TODO Auto-generated method stub 11 | 12 | 13 | return false; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/generic/command/DoTranscodeCommand.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.generic.command; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.chain.Command; 7 | import org.apache.commons.chain.Context; 8 | 9 | import com.flashvisions.server.rtmp.transcoder.context.TranscodeRequest; 10 | import com.flashvisions.server.rtmp.transcoder.context.TranscoderContext; 11 | import com.flashvisions.server.rtmp.transcoder.interfaces.ISession; 12 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderResource; 13 | import com.flashvisions.server.rtmp.transcoder.pool.TranscodeSessionPool; 14 | import com.flashvisions.server.rtmp.transcoder.utils.IOUtils; 15 | 16 | @SuppressWarnings("unused") 17 | public class DoTranscodeCommand implements Command { 18 | 19 | ITranscoderResource input; 20 | TranscodeRequest request; 21 | 22 | public DoTranscodeCommand(ITranscoderResource input, TranscodeRequest request) 23 | { 24 | this.input = input; 25 | this.request = request; 26 | } 27 | 28 | 29 | @Override 30 | public boolean execute(Context context) throws Exception { 31 | // TODO Auto-generated method stub 32 | TranscoderContext ctx = (TranscoderContext) context; 33 | File workingDir = null; 34 | 35 | File templateFile = new File(ctx.getTemplateDirectory() + File.separator + this.request.getTemplateFileName()); 36 | if(!templateFile.exists()) throw new IOException("Template not found"); 37 | 38 | if(this.request.getWorkingDirectory() != null) { 39 | workingDir = new File(this.request.getWorkingDirectory()); 40 | if(!workingDir.exists()) throw new IOException("Working directory not found"); 41 | } 42 | 43 | IOUtils.IdentifyInput(input); 44 | String stream = input.getMediaName(); 45 | 46 | TranscodeSessionPool pool = ctx.getPool(); 47 | ISession session = pool.checkOut(input, request); 48 | session.setWorkingDirectoryPath(workingDir.getAbsolutePath()); 49 | 50 | session.start(); 51 | 52 | return true; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/handler/TranscodeSessionDestroyer.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.handler; 2 | 3 | import org.apache.commons.exec.ShutdownHookProcessDestroyer; 4 | import com.flashvisions.server.rtmp.transcoder.interfaces.TranscodeSessionProcessCallback; 5 | 6 | public class TranscodeSessionDestroyer extends ShutdownHookProcessDestroyer { 7 | 8 | private TranscodeSessionProcessCallback callback; 9 | 10 | public TranscodeSessionDestroyer(TranscodeSessionProcessCallback callback){ 11 | this.callback = callback; 12 | } 13 | 14 | 15 | @Override 16 | public boolean add(Process process) { 17 | // TODO Auto-generated method stub 18 | if(callback != null) 19 | callback.onTranscodeProcessAdded(process); 20 | 21 | return super.add(process); 22 | } 23 | 24 | @Override 25 | public boolean isAddedAsShutdownHook() { 26 | // TODO Auto-generated method stub 27 | return super.isAddedAsShutdownHook(); 28 | } 29 | 30 | @Override 31 | public boolean remove(Process process) { 32 | // TODO Auto-generated method stub 33 | if(callback != null) 34 | callback.onTranscodeProcessRemoved(process); 35 | 36 | return super.remove(process); 37 | } 38 | 39 | @Override 40 | public void run() { 41 | // TODO Auto-generated method stub 42 | super.run(); 43 | } 44 | 45 | @Override 46 | public int size() { 47 | // TODO Auto-generated method stub 48 | return super.size(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/handler/TranscodeSessionOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.handler; 2 | 3 | import java.io.IOException; 4 | import java.util.LinkedList; 5 | import java.util.Queue; 6 | 7 | import org.apache.commons.exec.LogOutputStream; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.flashvisions.server.rtmp.transcoder.interfaces.TranscodeSessionDataCallback; 12 | import com.flashvisions.server.rtmp.transcoder.pojo.Session; 13 | 14 | 15 | public class TranscodeSessionOutputStream extends LogOutputStream { 16 | 17 | private static Logger logger = LoggerFactory.getLogger(Session.class); 18 | private TranscodeSessionDataCallback callback; 19 | private static final int QUEUE_SIZE = 10; 20 | private final Queue lines = new LinkedList(); 21 | private long lastOutputTime = 0; 22 | 23 | public long getLastOutputTime() { 24 | return lastOutputTime; 25 | } 26 | 27 | public void setLastOutputTime(long lastOutputTime) { 28 | this.lastOutputTime = lastOutputTime; 29 | } 30 | 31 | public TranscodeSessionOutputStream(){ 32 | 33 | } 34 | 35 | public TranscodeSessionOutputStream(TranscodeSessionDataCallback callback){ 36 | this.callback = callback; 37 | } 38 | 39 | @Override 40 | protected void processLine(String line, int level) { 41 | 42 | if(!line.contains("frame")) 43 | logger.info(line); 44 | 45 | if(lines.size()>QUEUE_SIZE) 46 | lines.remove(); 47 | 48 | lines.add(line); 49 | lastOutputTime = System.currentTimeMillis(); 50 | 51 | if(this.callback != null){ 52 | if(lines.size() == 1) this.callback.onTranscodeProcessStart(lastOutputTime); 53 | this.callback.onTranscodeProcessData(line, lastOutputTime); 54 | } 55 | } 56 | 57 | /* Estimates if process is running by checking if there was output in last 5 seconds */ 58 | public boolean isRunning() 59 | { 60 | long diff = System.currentTimeMillis() - lastOutputTime; 61 | long diffSeconds = diff / 1000 % 60; 62 | return (diffSeconds>5)?false:true; 63 | } 64 | 65 | @Override 66 | public void close() throws IOException { 67 | // TODO Auto-generated method stub 68 | logger.info("closing output stream"); 69 | super.close(); 70 | } 71 | 72 | @Override 73 | public void flush() { 74 | // TODO Auto-generated method stub 75 | super.flush(); 76 | } 77 | 78 | @Override 79 | public int getMessageLevel() { 80 | // TODO Auto-generated method stub 81 | return super.getMessageLevel(); 82 | } 83 | 84 | @Override 85 | protected void processBuffer() { 86 | // TODO Auto-generated method stub 87 | super.processBuffer(); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/handler/TranscodeSessionResultHandler.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.handler; 2 | 3 | import org.apache.commons.exec.DefaultExecuteResultHandler; 4 | import org.apache.commons.exec.ExecuteException; 5 | import org.apache.commons.exec.ExecuteWatchdog; 6 | 7 | import com.flashvisions.server.rtmp.transcoder.interfaces.TranscodeSessionResultCallback; 8 | 9 | public class TranscodeSessionResultHandler extends DefaultExecuteResultHandler { 10 | 11 | private ExecuteWatchdog watchdog; 12 | private TranscodeSessionResultCallback callback; 13 | private long abortRequestTimestamp = 0; 14 | 15 | public TranscodeSessionResultHandler(ExecuteWatchdog watchdog){ 16 | this.setWatchdog(watchdog); 17 | } 18 | 19 | public TranscodeSessionResultHandler(ExecuteWatchdog watchdog, TranscodeSessionResultCallback callback){ 20 | this.setWatchdog(watchdog); 21 | this.setCallback(callback); 22 | } 23 | 24 | private void setWatchdog(ExecuteWatchdog watchdog) { 25 | this.watchdog = watchdog; 26 | } 27 | 28 | @Override 29 | public ExecuteException getException() { 30 | // TODO Auto-generated method stub 31 | return super.getException(); 32 | } 33 | 34 | @Override 35 | public int getExitValue() { 36 | // TODO Auto-generated method stub 37 | return super.getExitValue(); 38 | } 39 | 40 | @Override 41 | public boolean hasResult() { 42 | // TODO Auto-generated method stub 43 | return super.hasResult(); 44 | } 45 | 46 | @Override 47 | public void onProcessComplete(int exitValue) { 48 | // TODO Auto-generated method stub 49 | if(this.callback != null) 50 | this.callback.onTranscodeProcessComplete(exitValue, System.currentTimeMillis()); 51 | 52 | super.onProcessComplete(exitValue); 53 | } 54 | 55 | @Override 56 | public void onProcessFailed(ExecuteException e) { 57 | // TODO Auto-generated method stub 58 | 59 | if(this.callback != null) 60 | this.callback.onTranscodeProcessFailed(e, watchdog, System.currentTimeMillis()); 61 | 62 | super.onProcessFailed(e); 63 | } 64 | 65 | public ExecuteWatchdog getWatchdog() { 66 | return watchdog; 67 | } 68 | 69 | 70 | public TranscodeSessionResultCallback getCallback() { 71 | return callback; 72 | } 73 | 74 | public void setCallback(TranscodeSessionResultCallback callback) { 75 | this.callback = callback; 76 | } 77 | 78 | public long getAbortRequestTimestamp() { 79 | return abortRequestTimestamp; 80 | } 81 | 82 | public void setAbortRequestTimestamp(long abortRequestTimestamp) { 83 | this.abortRequestTimestamp = abortRequestTimestamp; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/helpers/TemplateTokenParser.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.helpers; 2 | 3 | import java.util.HashMap; 4 | import java.util.Iterator; 5 | import java.util.Map; 6 | 7 | import javax.xml.xpath.XPath; 8 | import javax.xml.xpath.XPathConstants; 9 | import javax.xml.xpath.XPathExpressionException; 10 | 11 | import org.w3c.dom.Document; 12 | import org.w3c.dom.NodeList; 13 | 14 | 15 | public class TemplateTokenParser { 16 | 17 | 18 | private static final Map VARIABLEMAP; 19 | static 20 | { 21 | VARIABLEMAP = new HashMap(); 22 | VARIABLEMAP.put("${SourceApplication}", "SourceApplication"); 23 | VARIABLEMAP.put("${SourceStreamName}", "SourceStreamName"); 24 | VARIABLEMAP.put("${homeDirectory}", "HomeDirectory"); 25 | } 26 | 27 | @SuppressWarnings("rawtypes") 28 | public static void updateDocumentWithVariables(Document document, XPath xpath) throws XPathExpressionException 29 | { 30 | Iterator it = VARIABLEMAP.entrySet().iterator(); 31 | 32 | while (it.hasNext()) 33 | { 34 | Map.Entry pair = (Map.Entry)it.next(); 35 | String xPathExpression = "//*[contains(text(), '" + pair.getKey() + "')]"; 36 | NodeList nodes = (NodeList) xpath.evaluate(xPathExpression, document, XPathConstants.NODESET); 37 | 38 | for (int idx = 0; idx < nodes.getLength(); idx++) { 39 | String variableName = (String) pair.getKey(); 40 | String replacementName = (String) pair.getValue(); 41 | String original = nodes.item(idx).getTextContent(); 42 | nodes.item(idx).setTextContent(original.replace(variableName , replacementName)); 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/helpers/TokenReplacer.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.helpers; 2 | 3 | import java.util.HashMap; 4 | import java.util.Iterator; 5 | import java.util.Map; 6 | 7 | public class TokenReplacer { 8 | 9 | /* Available tokens */ 10 | 11 | public class TOKEN 12 | { 13 | public static final String SOURCE_STREAM_TOKEN = "${SourceStreamName}"; 14 | public static final String SOURCE_STREAM_TOKEN_2 = "SourceStreamName"; 15 | public static final String SOURCE_APP_TOKEN = "${SourceApplication}"; 16 | public static final String SOURCE_APP_TOKEN_2 = "SourceApplication"; 17 | public static final String HOME_DIRECTORY_TOKEN = "${homeDirectory}"; 18 | public static final String HOME_DIRECTORY_TOKEN_2 = "HomeDirectory" ; 19 | public static final String CURRENT_DATE_TOKEN = "${currentDate}"; 20 | public static final String WORKING_DIRECTORY_TOKEN = "${workingDirectory}"; 21 | public static final String HLS_DIRECTORY_TOKEN = "${hlsDirectory}"; 22 | public static final String TEMPLATE_DIRECTORY = "${templateDirectory}"; 23 | public static final String OWN_SEGMENT_DIRECTORY = "${ownSegmentDirectory}"; 24 | public static final String HLS_SAMPLE_PLAYBACK_TEMPLATE = "${hlsPlaybackTemplate}"; 25 | public static final String FFMPEG_EXECUTABLE = "${ffmpegExecutable}"; 26 | public static final String INPUT_SOURCE = "${inputSource}"; 27 | } 28 | 29 | 30 | private HashMap tokenMap; 31 | 32 | public TokenReplacer() 33 | { 34 | tokenMap = new HashMap(); 35 | } 36 | 37 | public void setTokenValue(String token, String value) 38 | { 39 | tokenMap.put(token, value); 40 | } 41 | 42 | public String getTokenValue(String token) 43 | { 44 | return tokenMap.get(token); 45 | } 46 | 47 | public String asPlaceholder(String placeHolder) 48 | { 49 | return "\\" + placeHolder; 50 | } 51 | 52 | @SuppressWarnings("rawtypes") 53 | public String processReplacement(String subject) 54 | { 55 | Iterator it = tokenMap.entrySet().iterator(); 56 | while (it.hasNext()) { 57 | Map.Entry pair = (Map.Entry)it.next(); 58 | String token = (String) pair.getKey(); 59 | String value = (String) pair.getValue(); 60 | subject = subject.replace(token, value); 61 | //subject = subject.replaceAll(token, value); // TO DO 62 | } 63 | 64 | return subject; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IAudio.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | import java.util.ArrayList; 4 | 5 | public interface IAudio extends IMutable { 6 | 7 | public ICodec getCodec(); 8 | public void setCodec(ICodec codec); 9 | public ICodecImplementation getImplementation(); 10 | public void setImplementation(ICodecImplementation implementation); 11 | public IAudioBitrate getBitrate(); 12 | public void setBitrate(IAudioBitrate bitrate); 13 | public IAudioSampleRate getSamplerate(); 14 | public void setSamplerate(IAudioSampleRate samplerate); 15 | public IAudioChannel getChannel(); 16 | public void setChannel(IAudioChannel channels); 17 | public ArrayList getExtraParams(); 18 | public void setExtraParams(ArrayList extraParams); 19 | public ArrayList getExtraProperties(); 20 | public void setExtraProperties(ArrayList extraProperties); 21 | } 22 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IAudioBitrate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IAudioBitrate extends IPassThru, IParameter { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IAudioChannel.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IAudioChannel extends IPassThru, IParameter { 4 | public Integer getChannels(); 5 | } 6 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IAudioSampleRate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IAudioSampleRate extends IPassThru, IParameter { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IAverageBitrate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IAverageBitrate extends IParameter { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/ICodec.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | 4 | public interface ICodec extends IPassThru, IParameter,IMutable { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/ICodecImplementation.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface ICodecImplementation extends IParameter { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IContainer.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.pojo.io.enums.Format; 4 | 5 | public interface IContainer { 6 | public Format getType(); 7 | public void setType(Format type); 8 | } 9 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IDisposable.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IDisposable { 4 | public void dispose(); 5 | } 6 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IEncode.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | 4 | public interface IEncode extends IMutable { 5 | 6 | public String getName(); 7 | public void setName(String name); 8 | public IAudio getAudioConfig(); 9 | public void setAudioConfig(IAudio config); 10 | public IVideo getVideoConfig(); 11 | public void setVideoConfig(IVideo config); 12 | public ITranscodeOutput getOutput(); 13 | public void setOutput(ITranscodeOutput output); 14 | } 15 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IEncodeCollection.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | import java.util.List; 4 | 5 | public interface IEncodeCollection { 6 | public void addEncode(IEncode e); 7 | public void removeEncode(IEncode c); 8 | public int getTotalEncodes(); 9 | public void clear(); 10 | 11 | public IEncodeIterator iterator(); 12 | public List getEncodeList(); 13 | } 14 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IEncodeIterator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IEncodeIterator { 4 | public boolean hasNext(); 5 | public IEncode next(); 6 | } 7 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IFileMedia.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | import java.io.File; 4 | 5 | public interface IFileMedia extends IMedia { 6 | public File getFile(); 7 | public void setFile(File input); 8 | } 9 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IFrameRate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IFrameRate extends IPassThru, IParameter { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IFrameSize.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IFrameSize extends IPassThru, IParameter { 4 | public Object getWidth(); 5 | public void setWidth(Object width); 6 | public Object getHeight(); 7 | public void setHeight(Object height); 8 | } 9 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IKeyFrameInterval.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.pojo.video.Gop; 4 | import com.flashvisions.server.rtmp.transcoder.pojo.video.MinKeyframeInterval; 5 | 6 | public interface IKeyFrameInterval extends IPassThru { 7 | public MinKeyframeInterval getMinimunInterval(); 8 | public void setMinimunInterval(MinKeyframeInterval minimunInterval); 9 | public Gop getGop(); 10 | public void setGop(Gop gop); 11 | } 12 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/ILibRtmpConfig.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface ILibRtmpConfig { 4 | 5 | public int getTimeout(); 6 | public void setTimeout(int timeout); 7 | public String getRtmpApplication(); 8 | public void setRtmpApplication(String rtmpApplication); 9 | public String getStream(); 10 | public void setStream(String stream); 11 | public boolean isLive(); 12 | public void setLive(boolean live); 13 | public String getAppName(); 14 | public void setAppName(String appName); 15 | public String getPlayPath(); 16 | public void setPlayPath(String playPath); 17 | public String getTcUrl(); 18 | public void setTcUrl(String tcUrl); 19 | public String getSwfUrl(); 20 | public void setSwfUrl(String swfUrl); 21 | public String getPageUrl(); 22 | public void setPageUrl(String pageUrl); 23 | public String getConn(); 24 | public void setConn(String conn); 25 | public void prepareFrom(ITranscoderResource resource); 26 | } 27 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IMedia.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IMedia { 4 | 5 | public IContainer getContainer(); 6 | public void setContainer(IContainer container); 7 | public String getSourcePath(); 8 | public void setSourcePath(String source); 9 | public void setProtocol(String protocol); 10 | public String getProtocol(); 11 | public boolean isFile(); 12 | public boolean isStreamingMedia(); 13 | public String getMediaName(); 14 | public void setMediaName(String streamName); 15 | } 16 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IMutable.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IMutable extends Cloneable { 4 | public boolean getEnabled(); 5 | public void setEnabled(boolean enabled); 6 | } 7 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IMutableObject.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IMutableObject extends IMutable { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IOverlay.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | import java.io.IOException; 4 | 5 | public interface IOverlay extends IMutable { 6 | 7 | public String getLabel(); 8 | public void setLabel(String label); 9 | public int getZindex(); 10 | public void setZindex(int zindex); 11 | public String getOverlayImagePath(); 12 | public void setOverlayImagePath(String overlayImagePath) throws IOException; 13 | public int getOpacity(); 14 | public void setOpacity(int opacity); 15 | public IOverlayLocation getLocation(); 16 | public void setLocation(IOverlayLocation location); 17 | public int getOverlayImageHeight(); 18 | public int getOverlayImageWidth(); 19 | } 20 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IOverlayCollection.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IOverlayCollection { 4 | public void addOverlay(IOverlay o); 5 | public void removeOverlay(IOverlay o); 6 | public int getTotalOverlays(); 7 | public void clear(); 8 | 9 | public IOverlayIterator iterator(); 10 | } 11 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IOverlayIterator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | 4 | public interface IOverlayIterator { 5 | public boolean hasNext(); 6 | public IOverlay next(); 7 | } 8 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IOverlayLocation.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.pojo.video.Overlay.Location.ALIGNMENT; 4 | 5 | public interface IOverlayLocation { 6 | 7 | public int getX(); 8 | public void setX(int x); 9 | public int getY(); 10 | public void setY(int y); 11 | public int getWidth(); 12 | public void setWidth(int width); 13 | public int getHeight(); 14 | public void setHeight(int height); 15 | public ALIGNMENT getAlign(); 16 | public void setAlign(ALIGNMENT align); 17 | public void setAlign(String alignment); 18 | } 19 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IParameter.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IParameter extends ITranscoderEntity { 4 | public String getKey(); 5 | public void setKey(String key); 6 | public Object getValue(); 7 | public void setValue(Object value) ; 8 | public IParameter clone(); 9 | } 10 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IPassThru.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IPassThru { 4 | public void setSameAsSource(boolean same); 5 | public boolean getSameAsSource(); 6 | 7 | public void setIgnore(boolean ignore); 8 | public boolean getIgnore(); 9 | } 10 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IPassThruObject.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IPassThruObject extends IPassThru { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IProperty.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IProperty extends ITranscoderEntity { 4 | public String getData(); 5 | public void setData(String data); 6 | public IProperty clone(); 7 | } 8 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/ISession.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | import java.util.ArrayList; 4 | 5 | import com.flashvisions.server.rtmp.transcoder.pojo.io.enums.SessionEvent; 6 | 7 | 8 | 9 | public interface ISession extends IDisposable, TranscodeSessionProcessCallback, TranscodeSessionResultCallback, TranscodeSessionDataCallback { 10 | 11 | public long getId(); 12 | 13 | public ITranscoderResource getInputSource(); 14 | public ArrayList getOutputs(); 15 | public ITranscode getTranscodeConfig(); 16 | 17 | public String getWorkingDirectoryPath(); 18 | public void setWorkingDirectoryPath(String workingDirectoryPath); 19 | 20 | public void registerObserver(ISessionObserver observer); 21 | public void removeObserver(ISessionObserver observer); 22 | public void notifyObservers(SessionEvent event, Object data); 23 | 24 | public void start(); 25 | public boolean stop(); 26 | public boolean isRunning(); 27 | } -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/ISessionObserver.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface ISessionObserver { 4 | public void onSessionPreStart(ISession session); 5 | public void onSessionStart(ISession session, Object data); 6 | public void onSessionComplete(ISession session, Object data); 7 | public void onSessionFailed(ISession session, Object data); 8 | public void onSessionData(ISession session, Object data); 9 | public void onSessionProcessAdded(ISession session, Process proc); 10 | public void onSessionProcessRemoved(ISession session, Process proc); 11 | } 12 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IStreamingMedia.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface IStreamingMedia extends IMedia { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/ITranscode.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | 4 | 5 | public interface ITranscode extends IMutable { 6 | public String getLabel() ; 7 | public String getDescription(); 8 | public IEncodeCollection getEncodes(); 9 | } 10 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/ITranscodeDao.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface ITranscodeDao { 4 | 5 | public String getTemplate(); 6 | public void setTemplate(String templatePath); 7 | public ITranscode getTranscodeConfig(); 8 | } 9 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/ITranscodeOutput.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | import java.util.ArrayList; 4 | 5 | public interface ITranscodeOutput { 6 | public ITranscoderResource getMediaOutput(); 7 | public void setMediaOutput(ITranscoderResource output); 8 | public ArrayList getOutputProperties(); 9 | public void setOutputProperties(ArrayList extraProperties); 10 | public ArrayList getOutputIParameters(); 11 | public void setOutputIParameters(ArrayList extraParameters); 12 | } 13 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/ITranscoderEntity.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface ITranscoderEntity { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/ITranscoderFacade.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | 4 | import com.flashvisions.server.rtmp.transcoder.context.TranscodeRequest; 5 | import com.flashvisions.server.rtmp.transcoder.exception.TranscoderException; 6 | 7 | public interface ITranscoderFacade { 8 | 9 | public void init() throws TranscoderException; 10 | 11 | public void setFFmpegPath(String ffmpegPath); 12 | public String getFFmpegPath(); 13 | 14 | public void setOperatingMediaServer(String serverName); 15 | public String getOperatingMediaServer(); 16 | 17 | public void setWorkingDirectory(String workingDirectoryPath); 18 | public String getWorkingDirectory(); 19 | 20 | public void setHomeDirectory(String homeDirectoryPath); 21 | public String getHomeDirectory(); 22 | 23 | public void setTemplateDirectory(String templateDirectoryPath); 24 | public String getTemplateDirectory(); 25 | 26 | public void doTranscode(ITranscoderResource input, TranscodeRequest request) throws TranscoderException; 27 | 28 | public void abortTranscode(); 29 | } 30 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/ITranscoderResource.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | import java.util.ArrayList; 4 | 5 | import com.flashvisions.server.rtmp.transcoder.pojo.io.strategy.interfaces.InterpretStrategy; 6 | 7 | public interface ITranscoderResource extends IMedia { 8 | public String describe(); 9 | public InterpretStrategy getStrategy(); 10 | public void setStrategy(InterpretStrategy strategy); 11 | public ArrayList getOptionFlags(); 12 | public void setOptionFlags(ArrayList flags); 13 | } 14 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IVideo.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | import java.util.ArrayList; 4 | 5 | 6 | public interface IVideo extends IMutable { 7 | 8 | public ICodec getCodec(); 9 | public void setCodec(ICodec codec); 10 | public ICodecImplementation getImplementation(); 11 | public void setImplementation(ICodecImplementation implementation); 12 | public IFrameSize getFramesize(); 13 | public void setFramesize(IFrameSize framesize); 14 | public IFrameRate getFramerate(); 15 | public void setFramerate(IFrameRate framerate); 16 | public IVideoBitrate getBitrate(); 17 | public void setBitrate(IVideoBitrate bitrate); 18 | public IKeyFrameInterval getKeyFrameInterval(); 19 | public void setKeyFrameInterval(IKeyFrameInterval keyFrameInterval); 20 | public ArrayList getExtraParams(); 21 | public void setExtraParams(ArrayList extraParams); 22 | public ArrayList getExtraProperties(); 23 | public void setExtraProperties(ArrayList extraProperties); 24 | } 25 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/IVideoBitrate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | 4 | public interface IVideoBitrate extends IPassThruObject { 5 | 6 | public IParameter getAverage(); 7 | public void setAverage(IParameter average); 8 | public IParameter getMinimum(); 9 | public void setMinimum(IParameter minimum); 10 | public IParameter getMaximum(); 11 | public void setMaximum(IParameter maximum); 12 | public IParameter getDeviceBuffer(); 13 | public void setDeviceBuffer(IParameter deviceBuffer); 14 | } 15 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/TranscodeSessionDataCallback.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | 4 | public interface TranscodeSessionDataCallback { 5 | 6 | public void onTranscodeProcessStart(long timestamp); 7 | public void onTranscodeProcessData(Object data, long timestamp); 8 | } 9 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/TranscodeSessionProcessCallback.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | public interface TranscodeSessionProcessCallback { 4 | 5 | public void onTranscodeProcessAdded(Process proc); 6 | public void onTranscodeProcessRemoved(Process proc); 7 | } 8 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/interfaces/TranscodeSessionResultCallback.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.interfaces; 2 | 3 | import org.apache.commons.exec.ExecuteException; 4 | import org.apache.commons.exec.ExecuteWatchdog; 5 | 6 | public interface TranscodeSessionResultCallback { 7 | 8 | public void onTranscodeProcessComplete(int exitValue, long timestamp); 9 | public void onTranscodeProcessFailed(ExecuteException e, ExecuteWatchdog watchdog, long timestamp); 10 | } 11 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/librtmp/FMSLibRtmpConfig.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.librtmp; 2 | 3 | public class FMSLibRtmpConfig extends LibRtmpConfig { 4 | 5 | public FMSLibRtmpConfig(){ 6 | this.setTimeout(15); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/librtmp/Red5LibRtmpConfig.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.librtmp; 2 | 3 | public class Red5LibRtmpConfig extends LibRtmpConfig { 4 | 5 | public Red5LibRtmpConfig(){ 6 | this.setTimeout(2); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/librtmp/WowzaLibRtmpConfig.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.librtmp; 2 | 3 | public class WowzaLibRtmpConfig extends LibRtmpConfig { 4 | 5 | public WowzaLibRtmpConfig(){ 6 | this.setTimeout(15); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/managers/IOManager.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.managers; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Hashtable; 5 | import java.util.Iterator; 6 | import java.util.Map; 7 | import java.util.Map.Entry; 8 | 9 | import com.flashvisions.server.rtmp.transcoder.interfaces.ISession; 10 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderResource; 11 | 12 | public class IOManager { 13 | 14 | private static IOManager instance; 15 | private static Hashtable> resourceTable; 16 | 17 | private IOManager(){ 18 | resourceTable = new Hashtable>(); 19 | } 20 | 21 | public static IOManager getInstance() 22 | { 23 | if(instance == null) 24 | instance = new IOManager(); 25 | return instance; 26 | } 27 | 28 | public void registerTranscodeSession(ISession session) 29 | { 30 | resourceTable.remove(session.getInputSource()); 31 | } 32 | 33 | public void unRegisterTranscodeSession(ISession session) 34 | { 35 | resourceTable.remove(session.getInputSource()); 36 | } 37 | 38 | public boolean isTranscodeLoopSafe(ITranscoderResource input) 39 | { 40 | boolean safe = true; 41 | 42 | if(input.isFile()) 43 | return safe; 44 | 45 | Iterator>> iterator = resourceTable.entrySet().iterator(); 46 | while(iterator.hasNext()){ 47 | Map.Entry> entry = iterator.next(); 48 | ArrayList outputs = entry.getValue(); 49 | for(ITranscoderResource output : outputs){ 50 | if(output.isStreamingMedia()){ 51 | if(output.getSourcePath().equalsIgnoreCase(input.getSourcePath())){ 52 | safe = false; 53 | return safe; 54 | } 55 | } 56 | } 57 | } 58 | 59 | return safe; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/Codec.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | import com.flashvisions.server.rtmp.transcoder.interfaces.ICodec; 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 7 | import com.flashvisions.server.rtmp.transcoder.pojo.base.PassThruObject; 8 | 9 | public abstract class Codec extends PassThruObject implements ICodec { 10 | 11 | @NotNull 12 | private Object value; 13 | 14 | private boolean enabled = true; 15 | 16 | public Codec(){ 17 | 18 | } 19 | 20 | public Codec(ICodec object){ 21 | this.setSameAsSource(object.getSameAsSource()); 22 | this.setEnabled(object.getEnabled()); 23 | this.value = object.getValue(); 24 | } 25 | 26 | public Codec(Object name){ 27 | this.value = name; 28 | } 29 | 30 | @Override 31 | public boolean getEnabled() { 32 | // TODO Auto-generated method stub 33 | return enabled; 34 | } 35 | 36 | @Override 37 | public void setEnabled(boolean enabled) { 38 | // TODO Auto-generated method stub 39 | this.enabled = enabled; 40 | } 41 | 42 | @Override 43 | public String getKey() { 44 | // TODO Auto-generated method stub 45 | return null; 46 | } 47 | 48 | @Override 49 | public void setKey(String key) { 50 | // TODO Auto-generated method stub 51 | // 52 | } 53 | 54 | @Override 55 | public Object getValue() { 56 | // TODO Auto-generated method stub 57 | return value; 58 | } 59 | 60 | @Override 61 | public void setValue(Object value) { 62 | // TODO Auto-generated method stub 63 | this.value = value; 64 | } 65 | 66 | @Override 67 | public IParameter clone() { 68 | // TODO Auto-generated method stub 69 | return null; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/CodecImplementation.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | import com.flashvisions.server.rtmp.transcoder.interfaces.ICodecImplementation; 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 7 | 8 | public class CodecImplementation implements ICodecImplementation { 9 | 10 | private static final String key = "-strict"; 11 | 12 | @NotNull 13 | private Object value; 14 | 15 | public CodecImplementation(){ 16 | 17 | } 18 | 19 | public CodecImplementation(Object value){ 20 | this.value = value; 21 | } 22 | 23 | public CodecImplementation(CodecImplementation object){ 24 | this.value = object.getValue(); 25 | } 26 | 27 | @Override 28 | public String getKey() { 29 | // TODO Auto-generated method stub 30 | return CodecImplementation.key; 31 | } 32 | 33 | @Override 34 | public void setKey(String key) { 35 | // TODO Auto-generated method stub 36 | // NO OP 37 | } 38 | 39 | @Override 40 | public Object getValue() { 41 | // TODO Auto-generated method stub 42 | return this.value; 43 | } 44 | 45 | @Override 46 | public void setValue(Object value) { 47 | // TODO Auto-generated method stub 48 | this.value = value; 49 | } 50 | 51 | @Override 52 | public IParameter clone() { 53 | // TODO Auto-generated method stub 54 | return new CodecImplementation(this.getValue()); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/Container.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.interfaces.IContainer; 4 | import com.flashvisions.server.rtmp.transcoder.pojo.io.enums.Format; 5 | 6 | public class Container implements IContainer { 7 | 8 | private Format type; 9 | 10 | 11 | public Container(Format type){ 12 | this.setType(type); 13 | } 14 | 15 | @Override 16 | public Format getType() { 17 | // TODO Auto-generated method stub 18 | return type; 19 | } 20 | 21 | @Override 22 | public void setType(Format type) { 23 | // TODO Auto-generated method stub 24 | this.type = type; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | // TODO Auto-generated method stub 30 | return String.valueOf(this.type).toLowerCase(); 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/Encode.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo; 2 | 3 | 4 | import javax.validation.constraints.NotNull; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IAudio; 7 | import com.flashvisions.server.rtmp.transcoder.interfaces.IEncode; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscodeOutput; 9 | import com.flashvisions.server.rtmp.transcoder.interfaces.IVideo; 10 | import com.flashvisions.server.rtmp.transcoder.pojo.base.MutableObject; 11 | 12 | public class Encode extends MutableObject implements IEncode { 13 | 14 | @NotNull 15 | private String name; 16 | 17 | @NotNull 18 | private IVideo vConfig; 19 | 20 | @NotNull 21 | private IAudio aConfig; 22 | 23 | @NotNull 24 | private ITranscodeOutput output; 25 | 26 | 27 | public IAudio getAudioConfig() { 28 | return aConfig; 29 | } 30 | 31 | 32 | public void setAudioConfig(IAudio aConfig) { 33 | this.aConfig = aConfig; 34 | } 35 | 36 | 37 | public IVideo getVideoConfig() { 38 | return vConfig; 39 | } 40 | 41 | 42 | public void setVideoConfig(IVideo vConfig) { 43 | this.vConfig = vConfig; 44 | } 45 | 46 | 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | 52 | public void setName(String name) { 53 | this.name = name; 54 | } 55 | 56 | 57 | @Override 58 | public ITranscodeOutput getOutput() { 59 | // TODO Auto-generated method stub 60 | return output; 61 | } 62 | 63 | 64 | @Override 65 | public void setOutput(ITranscodeOutput output) { 66 | // TODO Auto-generated method stub 67 | this.output = output; 68 | } 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/Parameter.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 4 | 5 | public class Parameter implements IParameter { 6 | 7 | private String key; 8 | private Object value; 9 | 10 | public Parameter() { 11 | 12 | } 13 | 14 | public Parameter(String key, Object value) { 15 | this.key = key; this.value = value; 16 | } 17 | 18 | 19 | public String getKey() 20 | { 21 | return key; 22 | } 23 | 24 | public void setKey(String key) 25 | { 26 | this.key = key; 27 | } 28 | 29 | public Object getValue() 30 | { 31 | return value; 32 | } 33 | 34 | public void setValue(Object value) 35 | { 36 | this.value = value; 37 | } 38 | 39 | public IParameter clone() { 40 | // TODO Auto-generated method stub 41 | return (IParameter) new Parameter(this.key, this.value); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/Property.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo; 2 | 3 | 4 | import com.flashvisions.server.rtmp.transcoder.interfaces.IProperty; 5 | 6 | public class Property implements IProperty { 7 | 8 | private String data; 9 | 10 | public Property(String data) { 11 | this.data = data; 12 | } 13 | 14 | public Property() { 15 | } 16 | 17 | public String getData() { 18 | return data; 19 | } 20 | 21 | public void setData(String data) { 22 | this.data = data; 23 | } 24 | 25 | public IProperty clone() { 26 | // TODO Auto-generated method stub 27 | return (IProperty) new Property(this.data); 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/Transcode.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | import com.flashvisions.server.rtmp.transcoder.interfaces.IEncodeCollection; 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscode; 7 | import com.flashvisions.server.rtmp.transcoder.pojo.base.MutableObject; 8 | 9 | public class Transcode extends MutableObject implements ITranscode { 10 | 11 | @NotNull 12 | private String label; 13 | 14 | @NotNull 15 | private String description; 16 | 17 | @NotNull 18 | private IEncodeCollection encodes; 19 | 20 | 21 | private Transcode(Builder builder){ 22 | this.label = builder.label; 23 | this.description = builder.description; 24 | this.encodes = builder.encodes; 25 | this.setEnabled(builder.enabled); 26 | } 27 | 28 | public String getLabel() 29 | { 30 | return label; 31 | } 32 | 33 | public void setLabel(String label) 34 | { 35 | this.label = label; 36 | } 37 | 38 | public String getDescription() 39 | { 40 | return description; 41 | } 42 | 43 | public void setDescription(String description) 44 | { 45 | this.description = description; 46 | } 47 | 48 | public IEncodeCollection getEncodes() 49 | { 50 | return encodes; 51 | } 52 | 53 | public void setEncodes(IEncodeCollection encodes) 54 | { 55 | this.encodes = encodes; 56 | } 57 | 58 | public static class Builder 59 | { 60 | private boolean enabled; 61 | private String label; 62 | private String description; 63 | private IEncodeCollection encodes; 64 | 65 | public static Builder newTranscode(){ 66 | return new Builder(); 67 | } 68 | 69 | public Builder asValid(boolean valid) 70 | { 71 | this.enabled = valid; 72 | return this; 73 | } 74 | 75 | public Builder withLabel(String label){ 76 | this.label = label; 77 | return this; 78 | } 79 | 80 | public Builder withDescription(String description){ 81 | this.description = description; 82 | return this; 83 | } 84 | 85 | public Builder usingEncodes(IEncodeCollection encodes){ 86 | this.encodes = encodes; 87 | return this; 88 | } 89 | 90 | public ITranscode build() 91 | { 92 | return new Transcode(this); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/TranscodeOutput.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo; 2 | 3 | import java.util.ArrayList; 4 | 5 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IProperty; 7 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscodeOutput; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderResource; 9 | 10 | public class TranscodeOutput implements ITranscodeOutput{ 11 | 12 | private ITranscoderResource output; 13 | public ArrayList extraProperties; 14 | public ArrayList extraParameters; 15 | 16 | 17 | @Override 18 | public ITranscoderResource getMediaOutput() { 19 | // TODO Auto-generated method stub 20 | return output; 21 | } 22 | 23 | @Override 24 | public void setMediaOutput(ITranscoderResource output) { 25 | // TODO Auto-generated method stub 26 | this.output = output; 27 | } 28 | 29 | @Override 30 | public ArrayList getOutputProperties() { 31 | // TODO Auto-generated method stub 32 | return extraProperties; 33 | } 34 | 35 | @Override 36 | public void setOutputProperties(ArrayList extraProperties) { 37 | // TODO Auto-generated method stub 38 | this.extraProperties = extraProperties; 39 | } 40 | 41 | @Override 42 | public ArrayList getOutputIParameters() { 43 | // TODO Auto-generated method stub 44 | return extraParameters; 45 | } 46 | 47 | @Override 48 | public void setOutputIParameters(ArrayList extraParameters) { 49 | // TODO Auto-generated method stub 50 | this.extraParameters = extraParameters; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/audio/Audio.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.audio; 2 | 3 | import java.util.ArrayList; 4 | 5 | import javax.validation.constraints.NotNull; 6 | 7 | import com.flashvisions.server.rtmp.transcoder.interfaces.ICodecImplementation; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 9 | import com.flashvisions.server.rtmp.transcoder.interfaces.IAudio; 10 | import com.flashvisions.server.rtmp.transcoder.interfaces.IAudioBitrate; 11 | import com.flashvisions.server.rtmp.transcoder.interfaces.IAudioChannel; 12 | import com.flashvisions.server.rtmp.transcoder.interfaces.IAudioSampleRate; 13 | import com.flashvisions.server.rtmp.transcoder.interfaces.ICodec; 14 | import com.flashvisions.server.rtmp.transcoder.interfaces.IProperty; 15 | import com.flashvisions.server.rtmp.transcoder.pojo.base.MutableObject; 16 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidAudioBitrate; 17 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidAudioChannel; 18 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidAudioCodec; 19 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidAudioSampleRate; 20 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidCodecImplementation; 21 | 22 | public class Audio extends MutableObject implements IAudio { 23 | 24 | @NotNull 25 | @ValidAudioCodec 26 | private ICodec codec; 27 | 28 | @NotNull 29 | @ValidCodecImplementation 30 | private ICodecImplementation codecImplementation; 31 | 32 | @NotNull 33 | @ValidAudioBitrate 34 | private IAudioBitrate bitrate; 35 | 36 | @NotNull 37 | @ValidAudioSampleRate 38 | private IAudioSampleRate samplerate; 39 | 40 | @NotNull 41 | @ValidAudioChannel 42 | private IAudioChannel channel; 43 | 44 | @NotNull 45 | private ArrayList extraParams; 46 | 47 | @NotNull 48 | private ArrayList extraProperties; 49 | 50 | 51 | public ICodec getCodec() { 52 | return codec; 53 | } 54 | 55 | public void setCodec(ICodec codec) { 56 | this.codec = codec; 57 | } 58 | 59 | public IAudioBitrate getBitrate() { 60 | return bitrate; 61 | } 62 | 63 | public void setBitrate(IAudioBitrate bitrate) { 64 | this.bitrate = bitrate; 65 | } 66 | 67 | public IAudioSampleRate getSamplerate() { 68 | return samplerate; 69 | } 70 | 71 | public void setSamplerate(IAudioSampleRate samplerate) { 72 | this.samplerate = samplerate; 73 | } 74 | 75 | public IAudioChannel getChannel() { 76 | return channel; 77 | } 78 | 79 | public void setChannel(IAudioChannel channel) { 80 | this.channel = channel; 81 | } 82 | 83 | public ArrayList getExtraParams() { 84 | return extraParams; 85 | } 86 | 87 | public void setExtraParams(ArrayList extraParams) { 88 | this.extraParams = extraParams; 89 | } 90 | 91 | @Override 92 | public ArrayList getExtraProperties() { 93 | // TODO Auto-generated method stub 94 | return extraProperties; 95 | } 96 | 97 | @Override 98 | public void setExtraProperties(ArrayList extraProperties) { 99 | // TODO Auto-generated method stub 100 | this.extraProperties = extraProperties; 101 | } 102 | 103 | @Override 104 | public ICodecImplementation getImplementation() { 105 | // TODO Auto-generated method stub 106 | return this.codecImplementation; 107 | } 108 | 109 | @Override 110 | public void setImplementation(ICodecImplementation implementation) { 111 | // TODO Auto-generated method stub 112 | this.codecImplementation = implementation; 113 | } 114 | 115 | 116 | } 117 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/audio/AudioBitrate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.audio; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | import org.hibernate.validator.constraints.Range; 6 | 7 | import com.flashvisions.server.rtmp.transcoder.ffmpeg.Flags; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.IAudioBitrate; 9 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 10 | import com.flashvisions.server.rtmp.transcoder.pojo.base.PassThruObject; 11 | 12 | public class AudioBitrate extends PassThruObject implements IAudioBitrate 13 | { 14 | private static final String key = Flags.AUDIO_BITRATE; 15 | 16 | @NotNull 17 | @Range(min = 0, max = 1000, message = "{com.flashvisions.server.rtmp.transcoder.validation.audio.bitrate.invalid}") 18 | private Object value; 19 | 20 | 21 | /************ Copy constructor *********/ 22 | public AudioBitrate(IAudioBitrate object){ 23 | this.setSameAsSource(object.getSameAsSource()); 24 | this.value = object.getValue(); 25 | } 26 | 27 | public AudioBitrate(boolean sameAsSource){ 28 | this.setSameAsSource(sameAsSource); 29 | this.value = 0; 30 | } 31 | 32 | public AudioBitrate(Object bitrate){ 33 | this.value = bitrate; 34 | } 35 | 36 | public AudioBitrate(){ 37 | 38 | } 39 | 40 | @Override 41 | public String getKey() { 42 | // TODO Auto-generated method stub 43 | return AudioBitrate.key; 44 | } 45 | 46 | @Override 47 | public void setKey(String key) { 48 | // TODO Auto-generated method stub 49 | // NO OP 50 | } 51 | 52 | @Override 53 | public Object getValue() { 54 | // TODO Auto-generated method stub 55 | return this.value; 56 | } 57 | 58 | @Override 59 | public void setValue(Object value) { 60 | // TODO Auto-generated method stub 61 | this.value = value; 62 | } 63 | 64 | @Override 65 | public IParameter clone() { 66 | // TODO Auto-generated method stub 67 | return new AudioBitrate(this.getValue()); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/audio/AudioChannel.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.audio; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.ffmpeg.Flags; 4 | import com.flashvisions.server.rtmp.transcoder.interfaces.IAudioChannel; 5 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 6 | import com.flashvisions.server.rtmp.transcoder.pojo.base.PassThruObject; 7 | import com.flashvisions.server.rtmp.transcoder.pojo.io.enums.AudioChannelType; 8 | 9 | public class AudioChannel extends PassThruObject implements IAudioChannel { 10 | 11 | private static final String key = Flags.AUDIO_CHANNEL; 12 | private Object value; 13 | 14 | 15 | public AudioChannel(IAudioChannel object) 16 | { 17 | this.setSameAsSource(object.getSameAsSource()); 18 | this.value = object.getValue(); 19 | } 20 | 21 | public AudioChannel(Object type) 22 | { 23 | this.value = ((String)type).toUpperCase(); 24 | } 25 | 26 | public AudioChannel(boolean sameAsSource) 27 | { 28 | this.setSameAsSource(sameAsSource); 29 | this.value = null; 30 | } 31 | 32 | 33 | @Override 34 | public String getKey() { 35 | // TODO Auto-generated method stub 36 | return AudioChannel.key; 37 | } 38 | 39 | @Override 40 | public void setKey(String key) { 41 | // TODO Auto-generated method stub 42 | // NO OP 43 | } 44 | 45 | @Override 46 | public Object getValue() { 47 | // TODO Auto-generated method stub 48 | return this.value; 49 | } 50 | 51 | @Override 52 | public void setValue(Object value) { 53 | // TODO Auto-generated method stub 54 | this.value = ((String)value).toUpperCase(); 55 | } 56 | 57 | @Override 58 | public IParameter clone() { 59 | // TODO Auto-generated method stub 60 | return new AudioChannel(this.getValue()); 61 | } 62 | 63 | @Override 64 | public Integer getChannels() { 65 | // TODO Auto-generated method stub 66 | return ((Enum) AudioChannelType.valueOf(String.valueOf(this.getValue()))).ordinal()+1; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/audio/AudioCodec.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.audio; 2 | 3 | 4 | 5 | import com.flashvisions.server.rtmp.transcoder.ffmpeg.Flags; 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.ICodec; 7 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 8 | import com.flashvisions.server.rtmp.transcoder.pojo.Codec; 9 | 10 | 11 | public class AudioCodec extends Codec { 12 | 13 | private static final String key = Flags.AUDIO_CODEC; 14 | 15 | 16 | public AudioCodec(){ 17 | super(); 18 | } 19 | 20 | public AudioCodec(ICodec object) { 21 | super(object); 22 | } 23 | 24 | public AudioCodec(Object name) { 25 | super(name); 26 | } 27 | 28 | @Override 29 | public String getKey() { 30 | // TODO Auto-generated method stub 31 | return AudioCodec.key; 32 | } 33 | 34 | @Override 35 | public void setKey(String key) { 36 | // TODO Auto-generated method stub 37 | // NO OP 38 | } 39 | 40 | 41 | @Override 42 | public IParameter clone() { 43 | // TODO Auto-generated method stub 44 | return new AudioCodec(this.getValue()); 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/audio/AudioSampleRate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.audio; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.ffmpeg.Flags; 4 | import com.flashvisions.server.rtmp.transcoder.interfaces.IAudioSampleRate; 5 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 6 | import com.flashvisions.server.rtmp.transcoder.pojo.base.PassThruObject; 7 | 8 | public class AudioSampleRate extends PassThruObject implements IAudioSampleRate 9 | { 10 | private static final String key = Flags.AUDIO_SAMPLERATE; 11 | private Object value; 12 | 13 | /*************** Copy constructor ************/ 14 | public AudioSampleRate(IAudioSampleRate object) { 15 | this.setSameAsSource(object.getSameAsSource()); 16 | this.value = object.getValue(); 17 | } 18 | 19 | public AudioSampleRate(boolean sameAsSource, Object samplerate) { 20 | this.setSameAsSource(sameAsSource); 21 | this.value = samplerate; 22 | } 23 | 24 | public AudioSampleRate(boolean sameAsSource) { 25 | this.setSameAsSource(sameAsSource); 26 | this.value = -10; 27 | } 28 | 29 | public AudioSampleRate(Object samplerate) { 30 | this.value = samplerate; 31 | } 32 | 33 | 34 | @Override 35 | public String getKey() { 36 | // TODO Auto-generated method stub 37 | return AudioSampleRate.key; 38 | } 39 | 40 | @Override 41 | public void setKey(String key) { 42 | // TODO Auto-generated method stub 43 | // NO OP 44 | } 45 | 46 | @Override 47 | public Object getValue() { 48 | // TODO Auto-generated method stub 49 | return this.value; 50 | } 51 | 52 | @Override 53 | public void setValue(Object value) { 54 | // TODO Auto-generated method stub 55 | this.value = value; 56 | } 57 | 58 | @Override 59 | public IParameter clone() { 60 | // TODO Auto-generated method stub 61 | return null; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/base/MutableObject.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.base; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.interfaces.IMutableObject; 4 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderEntity; 5 | 6 | public abstract class MutableObject extends TranscoderEntity implements IMutableObject, ITranscoderEntity { 7 | 8 | private boolean enabled; 9 | 10 | @Override 11 | public boolean getEnabled() { 12 | // TODO Auto-generated method stub 13 | return enabled; 14 | } 15 | 16 | @Override 17 | public void setEnabled(boolean enabled) { 18 | // TODO Auto-generated method stub 19 | this.enabled = enabled; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/base/PassThruObject.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.base; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.interfaces.IPassThruObject; 4 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderEntity; 5 | 6 | public abstract class PassThruObject extends TranscoderEntity implements IPassThruObject, ITranscoderEntity { 7 | 8 | private boolean sameAsSource; 9 | private boolean ignore = false; 10 | 11 | @Override 12 | public void setSameAsSource(boolean sameAsSource) { 13 | // TODO Auto-generated method stub 14 | this.sameAsSource = sameAsSource; 15 | } 16 | 17 | @Override 18 | public boolean getSameAsSource() { 19 | // TODO Auto-generated method stub 20 | return sameAsSource; 21 | } 22 | 23 | @Override 24 | public void setIgnore(boolean ignore) { 25 | // TODO Auto-generated method stub 26 | this.ignore = ignore; 27 | } 28 | 29 | @Override 30 | public boolean getIgnore() { 31 | // TODO Auto-generated method stub 32 | return ignore; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/base/TranscoderEntity.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.base; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderEntity; 4 | 5 | public abstract class TranscoderEntity implements ITranscoderEntity { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/collection/EncodeCollection.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.collection; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IEncode; 7 | import com.flashvisions.server.rtmp.transcoder.interfaces.IEncodeCollection; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.IEncodeIterator; 9 | 10 | public class EncodeCollection implements IEncodeCollection { 11 | 12 | private List encodeList; 13 | 14 | public EncodeCollection() 15 | { 16 | encodeList = new ArrayList(); 17 | } 18 | 19 | public void addEncode(IEncode e) 20 | { 21 | // TODO Auto-generated method stub 22 | this.encodeList.add(e); 23 | } 24 | 25 | 26 | public void removeEncode(IEncode e) 27 | { 28 | // TODO Auto-generated method stub 29 | this.encodeList.remove(e); 30 | } 31 | 32 | 33 | public IEncodeIterator iterator() 34 | { 35 | // TODO Auto-generated method stub 36 | return new EncodeIterator(this.encodeList); 37 | } 38 | 39 | 40 | public List getEncodeList() 41 | { 42 | return encodeList; 43 | } 44 | 45 | public void setEncodeList(List encodeList) 46 | { 47 | this.encodeList = encodeList; 48 | } 49 | 50 | 51 | public void clear() 52 | { 53 | this.encodeList.clear(); 54 | } 55 | 56 | 57 | private class EncodeIterator implements IEncodeIterator { 58 | 59 | private List encodeList; 60 | private int position; 61 | 62 | public EncodeIterator(List encodeList) 63 | { 64 | this.encodeList = encodeList; 65 | this.position = 0; 66 | } 67 | 68 | 69 | public boolean hasNext() 70 | { 71 | if(position < encodeList.size()){ 72 | return true; 73 | } 74 | position++; 75 | return false; 76 | } 77 | 78 | public IEncode next() 79 | { 80 | IEncode e = encodeList.get(position); 81 | position++; 82 | return e; 83 | } 84 | } 85 | 86 | 87 | @Override 88 | public int getTotalEncodes() { 89 | // TODO Auto-generated method stub 90 | return this.encodeList.size(); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/collection/OverlayCollection.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.collection; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IOverlay; 7 | import com.flashvisions.server.rtmp.transcoder.interfaces.IOverlayCollection; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.IOverlayIterator; 9 | 10 | public class OverlayCollection implements IOverlayCollection { 11 | 12 | private List overlayList; 13 | 14 | public OverlayCollection() 15 | { 16 | overlayList = new ArrayList(); 17 | } 18 | 19 | public void addOverlay(IOverlay e) 20 | { 21 | // TODO Auto-generated method stub 22 | this.overlayList.add(e); 23 | } 24 | 25 | 26 | public void removeOverlay(IOverlay e) 27 | { 28 | // TODO Auto-generated method stub 29 | this.overlayList.remove(e); 30 | } 31 | 32 | 33 | public IOverlayIterator iterator() 34 | { 35 | // TODO Auto-generated method stub 36 | return new OverlayIterator(this.overlayList); 37 | } 38 | 39 | 40 | public List getoverlayList() 41 | { 42 | return overlayList; 43 | } 44 | 45 | public void setoverlayList(List overlayList) 46 | { 47 | this.overlayList = overlayList; 48 | } 49 | 50 | public void clear() 51 | { 52 | this.overlayList.clear(); 53 | } 54 | 55 | private class OverlayIterator implements IOverlayIterator { 56 | 57 | private List overlayList; 58 | private int position; 59 | 60 | public OverlayIterator(List overlayList) 61 | { 62 | this.overlayList = overlayList; 63 | this.position = 0; 64 | } 65 | 66 | 67 | public boolean hasNext() 68 | { 69 | if(position < overlayList.size()){ 70 | return true; 71 | } 72 | position++; 73 | return false; 74 | } 75 | 76 | public IOverlay next() 77 | { 78 | IOverlay e = overlayList.get(position); 79 | position++; 80 | return e; 81 | } 82 | } 83 | 84 | @Override 85 | public int getTotalOverlays() { 86 | // TODO Auto-generated method stub 87 | return overlayList.size(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/FileMedia.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io; 2 | 3 | import java.io.File; 4 | 5 | import com.flashvisions.server.rtmp.transcoder.interfaces.IContainer; 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IFileMedia; 7 | import com.flashvisions.server.rtmp.transcoder.pojo.io.base.Media; 8 | 9 | public class FileMedia extends Media implements IFileMedia { 10 | 11 | File file; 12 | 13 | public FileMedia(String source) { 14 | super(source); 15 | // TODO Auto-generated constructor stub 16 | } 17 | 18 | public FileMedia(String source, IContainer container){ 19 | super(source, container); 20 | } 21 | 22 | @Override 23 | public File getFile() { 24 | // TODO Auto-generated method stub 25 | return file; 26 | } 27 | 28 | @Override 29 | public void setFile(File file) { 30 | // TODO Auto-generated method stub 31 | this.file = file; 32 | } 33 | 34 | @Override 35 | public boolean isFile() { 36 | // TODO Auto-generated method stub 37 | return true; 38 | } 39 | 40 | @Override 41 | public boolean isStreamingMedia() { 42 | // TODO Auto-generated method stub 43 | return false; 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/StreamMedia.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io; 2 | 3 | 4 | import com.flashvisions.server.rtmp.transcoder.interfaces.IContainer; 5 | import com.flashvisions.server.rtmp.transcoder.interfaces.IStreamingMedia; 6 | import com.flashvisions.server.rtmp.transcoder.pojo.io.base.Media; 7 | 8 | public class StreamMedia extends Media implements IStreamingMedia { 9 | 10 | public StreamMedia(String source) { 11 | super(source); 12 | // TODO Auto-generated constructor stub 13 | } 14 | 15 | public StreamMedia(String source, IContainer container){ 16 | super(source, container); 17 | } 18 | 19 | @Override 20 | public boolean isFile() { 21 | // TODO Auto-generated method stub 22 | return false; 23 | } 24 | 25 | @Override 26 | public boolean isStreamingMedia() { 27 | // TODO Auto-generated method stub 28 | return true; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/base/Media.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io.base; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.interfaces.IContainer; 4 | import com.flashvisions.server.rtmp.transcoder.interfaces.IMedia; 5 | 6 | public class Media implements IMedia { 7 | 8 | 9 | private String streamName; 10 | private String protocol; 11 | private String source; 12 | private IContainer container; 13 | 14 | 15 | public Media(String source, IContainer container){ 16 | setSourcePath(source); 17 | setContainer(container); 18 | } 19 | 20 | public Media(String source){ 21 | setSourcePath(source); 22 | } 23 | 24 | @Override 25 | public String getSourcePath() { 26 | // TODO Auto-generated method stub 27 | return this.source; 28 | } 29 | 30 | @Override 31 | public void setSourcePath(String source) { 32 | // TODO Auto-generated method stub 33 | this.source = source; 34 | } 35 | 36 | @Override 37 | public String getProtocol() { 38 | // TODO Auto-generated method stub 39 | return this.protocol; 40 | } 41 | 42 | @Override 43 | public boolean isFile() { 44 | // TODO Auto-generated method stub 45 | return false; 46 | } 47 | 48 | @Override 49 | public boolean isStreamingMedia() { 50 | // TODO Auto-generated method stub 51 | return false; 52 | } 53 | 54 | @Override 55 | public IContainer getContainer() { 56 | // TODO Auto-generated method stub 57 | return this.container; 58 | } 59 | 60 | @Override 61 | public void setContainer(IContainer container) { 62 | // TODO Auto-generated method stub 63 | this.container = container; 64 | } 65 | 66 | @Override 67 | public String getMediaName() { 68 | // TODO Auto-generated method stub 69 | return streamName; 70 | } 71 | 72 | @Override 73 | public void setMediaName(String streamName) { 74 | // TODO Auto-generated method stub 75 | this.streamName = streamName; 76 | } 77 | 78 | @Override 79 | public void setProtocol(String protocol) { 80 | // TODO Auto-generated method stub 81 | this.protocol = protocol; 82 | } 83 | 84 | 85 | } 86 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/enums/AudioChannelType.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io.enums; 2 | 3 | import java.util.EnumSet; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | public enum AudioChannelType { 8 | 9 | MONO(0), 10 | STEREO(1); 11 | 12 | private static final Map lookup = new HashMap(); 13 | 14 | static { 15 | for(AudioChannelType w : EnumSet.allOf(AudioChannelType.class)) 16 | lookup.put(w.getCode(), w); 17 | } 18 | 19 | private int code; 20 | 21 | private AudioChannelType(int code) { 22 | this.code = code; 23 | } 24 | 25 | public int getCode() { return code; } 26 | 27 | public static AudioChannelType get(int code) { 28 | return lookup.get(code); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/enums/AudioCodecs.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io.enums; 2 | 3 | public enum AudioCodecs { 4 | 5 | LIBSPEEX, LIBMP3LAME, AAC, LIBFDK_AAC, LIBVO_AACENC, LIBFAAC, LIBVORBIS, NELLYMOSER 6 | } 7 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/enums/AudioSampleRates.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io.enums; 2 | 3 | public enum AudioSampleRates { 4 | SAMPLE_8000(8000), 5 | SAMPLE_11025(11025), 6 | SAMPLE_16000(16000), 7 | SAMPLE_22050(22050), 8 | SAMPLE_32000(32000), 9 | SAMPLE_37800(37800), 10 | SAMPLE_44056(44056), 11 | SAMPLE_44100(44100), 12 | SAMPLE_48000(48000); 13 | 14 | private final int value; 15 | 16 | private AudioSampleRates(final int newValue) { 17 | value = newValue; 18 | } 19 | 20 | public int getValue() { return value; } 21 | } 22 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/enums/CodecImplementations.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io.enums; 2 | 3 | public enum CodecImplementations { 4 | VERY, STRICT, NORMAL, UNOFFICIAL, EXPERIMENTAL 5 | } 6 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/enums/CodecOptions.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io.enums; 2 | 3 | public enum CodecOptions { 4 | COPY, DISABLE, SKIPTHRU 5 | } 6 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/enums/Format.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io.enums; 2 | 3 | public enum Format { 4 | 5 | FLV, MP4, SSEGMENT, RTSP, RTMP, RTP, MPEGTS, M3U8, MOV, AVI, F4V, MP3, AAC, OGV, WEBM, IMAGE2 6 | } 7 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/enums/Protocol.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io.enums; 2 | 3 | public enum Protocol { 4 | RTMPE, RTMPS, RTMPT, RTMP, RTSP, RTP, HTTP 5 | } 6 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/enums/Server.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io.enums; 2 | 3 | public enum Server { 4 | RED5, 5 | WOWZA, 6 | FMS 7 | } 8 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/enums/SessionEvent.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io.enums; 2 | 3 | public enum SessionEvent { 4 | 5 | PRESTART, START, STOP, DATA, FAILED, COMPLETE, PROCESSADDED, PROCESSREMOVED 6 | } 7 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/enums/VideoCodecs.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io.enums; 2 | 3 | public enum VideoCodecs { 4 | 5 | LIBX264, FLV, LIBTHEORA, H263, FLASHSV, MPEG4 6 | } 7 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/strategy/impl/DefaultInterpretStrategy.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io.strategy.impl; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderResource; 4 | import com.flashvisions.server.rtmp.transcoder.pojo.io.strategy.interfaces.InterpretStrategy; 5 | 6 | public class DefaultInterpretStrategy implements InterpretStrategy { 7 | 8 | @Override 9 | public String interpret(ITranscoderResource media) { 10 | // TODO Auto-generated method stub 11 | return media.getSourcePath(); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/strategy/impl/RTMPInterpretStrategy.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io.strategy.impl; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.data.factory.LibRtmpConfigurationFactory; 4 | import com.flashvisions.server.rtmp.transcoder.interfaces.ILibRtmpConfig; 5 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderResource; 6 | import com.flashvisions.server.rtmp.transcoder.pojo.io.enums.Server; 7 | import com.flashvisions.server.rtmp.transcoder.pojo.io.strategy.interfaces.InterpretStrategy; 8 | import com.flashvisions.server.rtmp.transcoder.system.Globals; 9 | 10 | public class RTMPInterpretStrategy implements InterpretStrategy { 11 | 12 | @Override 13 | public String interpret(ITranscoderResource resource) { 14 | // TODO Auto-generated method stub 15 | ILibRtmpConfig rtmpInterpretor = LibRtmpConfigurationFactory.getLibRtmpConfiguration(Server.valueOf(Globals.getEnv(Globals.Vars.OPERATING_SERVER).toUpperCase())); 16 | rtmpInterpretor.prepareFrom(resource); 17 | return rtmpInterpretor.toString(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/io/strategy/interfaces/InterpretStrategy.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.io.strategy.interfaces; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderResource; 4 | 5 | public interface InterpretStrategy { 6 | 7 | public String interpret(ITranscoderResource media); 8 | } 9 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/video/AverageBitrate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.video; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | import org.hibernate.validator.constraints.Range; 6 | 7 | import com.flashvisions.server.rtmp.transcoder.ffmpeg.Flags; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.IAverageBitrate; 9 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 10 | import com.flashvisions.server.rtmp.transcoder.pojo.Parameter; 11 | 12 | public class AverageBitrate extends Parameter implements IAverageBitrate { 13 | 14 | private static final String key = Flags.VIDEO_BITRATE; 15 | 16 | @NotNull 17 | @Range(min = 0, max = 5000, message = "{com.flashvisions.server.rtmp.transcoder.validation.video.bitrate.invalid.average}") 18 | private Object value; 19 | 20 | 21 | public AverageBitrate(){ 22 | 23 | } 24 | 25 | public AverageBitrate(Object value){ 26 | this.value = value; 27 | } 28 | 29 | public AverageBitrate(AverageBitrate object){ 30 | this.value = object.value; 31 | } 32 | 33 | @Override 34 | public String getKey() { 35 | // TODO Auto-generated method stub 36 | return AverageBitrate.key; 37 | } 38 | 39 | @Override 40 | public void setKey(String key) { 41 | // TODO Auto-generated method stub 42 | // NO OP 43 | } 44 | 45 | @Override 46 | public Object getValue() { 47 | // TODO Auto-generated method stub 48 | return this.value; 49 | } 50 | 51 | @Override 52 | public void setValue(Object value) { 53 | // TODO Auto-generated method stub 54 | this.value = value; 55 | } 56 | 57 | @Override 58 | public IParameter clone() { 59 | // TODO Auto-generated method stub 60 | return new AverageBitrate(this.value); 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/video/DeviceBuffer.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.video; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | import org.hibernate.validator.constraints.Range; 6 | 7 | import com.flashvisions.server.rtmp.transcoder.ffmpeg.Flags; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 9 | import com.flashvisions.server.rtmp.transcoder.pojo.Parameter; 10 | 11 | public class DeviceBuffer extends Parameter implements IParameter { 12 | 13 | private static final String key = Flags.VIDEO_BUFFER; 14 | 15 | @NotNull 16 | @Range(min = 0, max = 5000, message = "{com.flashvisions.server.rtmp.transcoder.validation.video.bitrate.invalid.devicebuffer}") 17 | private Object value; 18 | 19 | 20 | public DeviceBuffer(){ 21 | 22 | } 23 | 24 | public DeviceBuffer(Object value){ 25 | this.value = value; 26 | } 27 | 28 | public DeviceBuffer(DeviceBuffer object){ 29 | this.value = object.value; 30 | } 31 | 32 | @Override 33 | public String getKey() { 34 | // TODO Auto-generated method stub 35 | return DeviceBuffer.key; 36 | } 37 | 38 | @Override 39 | public void setKey(String key) { 40 | // TODO Auto-generated method stub 41 | // NO OP 42 | } 43 | 44 | @Override 45 | public Object getValue() { 46 | // TODO Auto-generated method stub 47 | return this.value; 48 | } 49 | 50 | @Override 51 | public void setValue(Object value) { 52 | // TODO Auto-generated method stub 53 | this.value = value; 54 | } 55 | 56 | @Override 57 | public IParameter clone() { 58 | // TODO Auto-generated method stub 59 | return new DeviceBuffer(this.value); 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/video/FrameRate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.video; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | import org.hibernate.validator.constraints.Range; 6 | 7 | import com.flashvisions.server.rtmp.transcoder.ffmpeg.Flags; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.IFrameRate; 9 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 10 | import com.flashvisions.server.rtmp.transcoder.pojo.base.PassThruObject; 11 | 12 | public class FrameRate extends PassThruObject implements IFrameRate { 13 | 14 | private static final String key = Flags.VIDEO_FRAMERATE; 15 | 16 | @NotNull 17 | @Range(min = 1, max = 60, message = "") 18 | private Object value; 19 | 20 | public FrameRate(){ 21 | } 22 | 23 | public FrameRate(IFrameRate object){ 24 | this.setSameAsSource(object.getSameAsSource()); 25 | this.value = object.getValue(); 26 | } 27 | 28 | public FrameRate(Object framerate){ 29 | this.value = framerate; 30 | } 31 | 32 | public FrameRate(boolean sameAsSource){ 33 | this.setSameAsSource(sameAsSource); 34 | this.value = 0; 35 | } 36 | 37 | 38 | @Override 39 | public String getKey() { 40 | // TODO Auto-generated method stub 41 | return FrameRate.key; 42 | } 43 | 44 | @Override 45 | public void setKey(String key) { 46 | // TODO Auto-generated method stub 47 | // NO OP 48 | } 49 | 50 | @Override 51 | public Object getValue() { 52 | // TODO Auto-generated method stub 53 | return this.value; 54 | } 55 | 56 | @Override 57 | public void setValue(Object value) { 58 | // TODO Auto-generated method stub 59 | this.value = value; 60 | } 61 | 62 | @Override 63 | public IParameter clone() { 64 | // TODO Auto-generated method stub 65 | return new FrameRate(this.value); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/video/FrameSize.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.video; 2 | 3 | 4 | 5 | import javax.validation.constraints.NotNull; 6 | import javax.validation.constraints.Size; 7 | 8 | import org.hibernate.validator.constraints.Range; 9 | 10 | import com.flashvisions.server.rtmp.transcoder.ffmpeg.Flags; 11 | import com.flashvisions.server.rtmp.transcoder.interfaces.IFrameSize; 12 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 13 | import com.flashvisions.server.rtmp.transcoder.pojo.base.PassThruObject; 14 | 15 | public class FrameSize extends PassThruObject implements IFrameSize { 16 | 17 | private static final String key = Flags.VIDEO_FRAMESIZE; 18 | 19 | 20 | @NotNull 21 | @Range(min = 1, max = 3840, message = "") 22 | private Object width = 0; 23 | 24 | @NotNull 25 | @Range(min = 1, max = 2040, message = "") 26 | private Object height = 0; 27 | 28 | @Size(min = 3, max = 9) 29 | private Object value; 30 | 31 | 32 | public FrameSize(){ 33 | 34 | } 35 | 36 | public FrameSize(IFrameSize object){ 37 | this.setSameAsSource(object.getSameAsSource()); 38 | this.width = object.getWidth(); 39 | this.height = object.getHeight(); 40 | } 41 | 42 | public FrameSize(boolean sameAsSource){ 43 | this.setSameAsSource(sameAsSource); 44 | this.width = 0; 45 | this.height = 0; 46 | } 47 | 48 | public FrameSize(Object width, Object height){ 49 | this.width = width; 50 | this.height = height; 51 | } 52 | 53 | public Object getWidth() 54 | { 55 | // TODO Auto-generated method stub 56 | return width; 57 | } 58 | 59 | public void setWidth(Object width) 60 | { 61 | // TODO Auto-generated method stub 62 | this.width = width; 63 | } 64 | 65 | public Object getHeight() 66 | { 67 | // TODO Auto-generated method stub 68 | return height; 69 | } 70 | 71 | public void setHeight(Object height) 72 | { 73 | // TODO Auto-generated method stub 74 | this.height = height; 75 | } 76 | 77 | @Override 78 | public String getKey() { 79 | // TODO Auto-generated method stub 80 | return FrameSize.key; 81 | } 82 | 83 | @Override 84 | public void setKey(String key) { 85 | // TODO Auto-generated method stub 86 | // NO OP 87 | } 88 | 89 | @Override 90 | public Object getValue() { 91 | // TODO Auto-generated method stub 92 | return this.width+"x"+this.height; 93 | } 94 | 95 | @Override 96 | public void setValue(Object value) { 97 | // TODO Auto-generated method stub 98 | // NO OP 99 | } 100 | 101 | @Override 102 | public IParameter clone() { 103 | // TODO Auto-generated method stub 104 | return new FrameSize(this.width, this.height); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/video/Gop.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.video; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | import org.hibernate.validator.constraints.Range; 6 | 7 | import com.flashvisions.server.rtmp.transcoder.ffmpeg.Flags; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 9 | import com.flashvisions.server.rtmp.transcoder.pojo.Parameter; 10 | 11 | public class Gop extends Parameter implements IParameter { 12 | 13 | private static final String key = Flags.VIDEO_GOP; 14 | 15 | @NotNull 16 | @Range(min = 0, max = 120) 17 | private Object value; 18 | 19 | public Gop(){ 20 | 21 | } 22 | 23 | public Gop(Object value){ 24 | this.value = value; 25 | } 26 | 27 | public Gop(Gop object){ 28 | this.value = (int) object.getValue(); 29 | } 30 | 31 | public Object getValue() 32 | { 33 | return this.value; 34 | } 35 | 36 | public String getKey() 37 | { 38 | return Gop.key; 39 | } 40 | 41 | @Override 42 | public void setKey(String key) { 43 | // TODO Auto-generated method stub 44 | // NO OP 45 | } 46 | 47 | @Override 48 | public void setValue(Object value) { 49 | // TODO Auto-generated method stub 50 | 51 | } 52 | 53 | @Override 54 | public IParameter clone() { 55 | // TODO Auto-generated method stub 56 | return new Gop(this.value); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/video/KeyFrameInterval.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.video; 2 | 3 | import com.flashvisions.server.rtmp.transcoder.interfaces.IKeyFrameInterval; 4 | import com.flashvisions.server.rtmp.transcoder.pojo.base.PassThruObject; 5 | 6 | public class KeyFrameInterval extends PassThruObject implements IKeyFrameInterval { 7 | 8 | private Gop gop; 9 | private MinKeyframeInterval minimunInterval; 10 | 11 | 12 | public KeyFrameInterval(){ 13 | 14 | } 15 | 16 | public KeyFrameInterval(IKeyFrameInterval object){ 17 | this.setSameAsSource(object.getSameAsSource()); 18 | this.gop = object.getGop(); 19 | this.minimunInterval = object.getMinimunInterval(); 20 | } 21 | 22 | public KeyFrameInterval(boolean sameAsSource){ 23 | this.setSameAsSource(sameAsSource); 24 | this.gop = new Gop(0); 25 | this.minimunInterval = new MinKeyframeInterval(0); 26 | } 27 | 28 | public KeyFrameInterval(Gop gop, MinKeyframeInterval minimunInterval){ 29 | this.gop = gop; 30 | this.minimunInterval = minimunInterval; 31 | } 32 | 33 | public MinKeyframeInterval getMinimunInterval() 34 | { 35 | return minimunInterval; 36 | } 37 | 38 | public void setMinimunInterval(MinKeyframeInterval minimunInterval) 39 | { 40 | this.minimunInterval = minimunInterval; 41 | } 42 | 43 | public Gop getGop() 44 | { 45 | return gop; 46 | } 47 | 48 | public void setGop(Gop gop) 49 | { 50 | this.gop = gop; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/video/MaximumBitrate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.video; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | import org.hibernate.validator.constraints.Range; 6 | 7 | import com.flashvisions.server.rtmp.transcoder.ffmpeg.Flags; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 9 | import com.flashvisions.server.rtmp.transcoder.pojo.Parameter; 10 | 11 | public class MaximumBitrate extends Parameter implements IParameter { 12 | 13 | private static final String key = Flags.VIDEO_MAXBITRATE; 14 | 15 | @NotNull 16 | @Range(min = 0, max = 5000, message = "{com.flashvisions.server.rtmp.transcoder.validation.video.bitrate.invalid.maximum}") 17 | private Object value; 18 | 19 | 20 | public MaximumBitrate(){ 21 | 22 | } 23 | 24 | public MaximumBitrate(Object value){ 25 | this.value = value; 26 | } 27 | 28 | public MaximumBitrate(MaximumBitrate object){ 29 | this.value = object.value; 30 | } 31 | 32 | @Override 33 | public String getKey() { 34 | // TODO Auto-generated method stub 35 | return MaximumBitrate.key; 36 | } 37 | 38 | @Override 39 | public void setKey(String key) { 40 | // TODO Auto-generated method stub 41 | // NO OP 42 | } 43 | 44 | @Override 45 | public Object getValue() { 46 | // TODO Auto-generated method stub 47 | return this.value; 48 | } 49 | 50 | @Override 51 | public void setValue(Object value) { 52 | // TODO Auto-generated method stub 53 | this.value = value; 54 | } 55 | 56 | @Override 57 | public IParameter clone() { 58 | // TODO Auto-generated method stub 59 | return new MaximumBitrate(this.value); 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/video/MinKeyframeInterval.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.video; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | import org.hibernate.validator.constraints.Range; 6 | 7 | import com.flashvisions.server.rtmp.transcoder.ffmpeg.Flags; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 9 | import com.flashvisions.server.rtmp.transcoder.pojo.Parameter; 10 | 11 | public class MinKeyframeInterval extends Parameter implements IParameter { 12 | 13 | private static final String key = Flags.VIDEO_MIN_KFI; 14 | 15 | @NotNull 16 | @Range(min = 0, max = 120) 17 | private Object value; 18 | 19 | public MinKeyframeInterval(){ 20 | 21 | } 22 | 23 | public MinKeyframeInterval(MinKeyframeInterval object){ 24 | this.value = object.getValue(); 25 | } 26 | 27 | public MinKeyframeInterval(Object value){ 28 | this.value = value; 29 | } 30 | 31 | @Override 32 | public String getKey() { 33 | // TODO Auto-generated method stub 34 | return MinKeyframeInterval.key; 35 | } 36 | 37 | @Override 38 | public void setKey(String key) { 39 | // TODO Auto-generated method stub 40 | // NO OP 41 | } 42 | 43 | @Override 44 | public Object getValue() { 45 | // TODO Auto-generated method stub 46 | return this.value; 47 | } 48 | 49 | @Override 50 | public void setValue(Object value) { 51 | // TODO Auto-generated method stub 52 | this.value = value; 53 | } 54 | 55 | @Override 56 | public IParameter clone() { 57 | // TODO Auto-generated method stub 58 | return new MinKeyframeInterval(this.value); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/video/MinimumBitrate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.video; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | import org.hibernate.validator.constraints.Range; 6 | 7 | import com.flashvisions.server.rtmp.transcoder.ffmpeg.Flags; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 9 | import com.flashvisions.server.rtmp.transcoder.pojo.Parameter; 10 | 11 | public class MinimumBitrate extends Parameter implements IParameter { 12 | 13 | private static final String key = Flags.VIDEO_MINBITRATE; 14 | 15 | @NotNull 16 | @Range(min = 0, max = 5000, message = "{com.flashvisions.server.rtmp.transcoder.validation.video.bitrate.invalid.minimum}") 17 | private Object value; 18 | 19 | 20 | public MinimumBitrate(){ 21 | 22 | } 23 | 24 | public MinimumBitrate(Object value){ 25 | this.value = value; 26 | } 27 | 28 | public MinimumBitrate(MinimumBitrate object){ 29 | this.value = object.value; 30 | } 31 | 32 | @Override 33 | public String getKey() { 34 | // TODO Auto-generated method stub 35 | return MinimumBitrate.key; 36 | } 37 | 38 | @Override 39 | public void setKey(String key) { 40 | // TODO Auto-generated method stub 41 | // NO OP 42 | } 43 | 44 | @Override 45 | public Object getValue() { 46 | // TODO Auto-generated method stub 47 | return this.value; 48 | } 49 | 50 | @Override 51 | public void setValue(Object value) { 52 | // TODO Auto-generated method stub 53 | this.value = value; 54 | } 55 | 56 | @Override 57 | public IParameter clone() { 58 | // TODO Auto-generated method stub 59 | return new MinimumBitrate(this.value); 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/video/Video.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.video; 2 | 3 | import java.util.ArrayList; 4 | 5 | import javax.validation.constraints.NotNull; 6 | 7 | import com.flashvisions.server.rtmp.transcoder.interfaces.ICodecImplementation; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 9 | import com.flashvisions.server.rtmp.transcoder.interfaces.ICodec; 10 | import com.flashvisions.server.rtmp.transcoder.interfaces.IFrameRate; 11 | import com.flashvisions.server.rtmp.transcoder.interfaces.IFrameSize; 12 | import com.flashvisions.server.rtmp.transcoder.interfaces.IKeyFrameInterval; 13 | import com.flashvisions.server.rtmp.transcoder.interfaces.IProperty; 14 | import com.flashvisions.server.rtmp.transcoder.interfaces.IVideo; 15 | import com.flashvisions.server.rtmp.transcoder.interfaces.IVideoBitrate; 16 | import com.flashvisions.server.rtmp.transcoder.pojo.base.MutableObject; 17 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidCodecImplementation; 18 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidVideoBitrate; 19 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidVideoCodec; 20 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidVideoFrameRate; 21 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidVideoFrameSize; 22 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidVideoKeyframeInterval; 23 | 24 | public class Video extends MutableObject implements IVideo { 25 | 26 | @NotNull 27 | @ValidVideoCodec 28 | private ICodec codec; 29 | 30 | @NotNull 31 | @ValidCodecImplementation 32 | private ICodecImplementation codecImplementation; 33 | 34 | @NotNull 35 | @ValidVideoFrameSize 36 | private IFrameSize framesize; 37 | 38 | @NotNull 39 | @ValidVideoFrameRate 40 | private IFrameRate framerate; 41 | 42 | @NotNull 43 | @ValidVideoBitrate 44 | private IVideoBitrate bitrate; 45 | 46 | @NotNull 47 | @ValidVideoKeyframeInterval 48 | private IKeyFrameInterval keyFrameInterval; 49 | 50 | @NotNull 51 | private ArrayList extraParams; 52 | 53 | @NotNull 54 | private ArrayList extraProperties; 55 | 56 | 57 | 58 | public ICodec getCodec() { 59 | return codec; 60 | } 61 | 62 | public void setCodec(ICodec codec) { 63 | this.codec = codec; 64 | } 65 | 66 | public IFrameSize getFramesize() { 67 | return framesize; 68 | } 69 | 70 | public void setFramesize(IFrameSize framesize) { 71 | this.framesize = framesize; 72 | } 73 | 74 | public IFrameRate getFramerate() { 75 | return framerate; 76 | } 77 | 78 | public void setFramerate(IFrameRate framerate) { 79 | this.framerate = framerate; 80 | } 81 | 82 | public IVideoBitrate getBitrate() { 83 | return bitrate; 84 | } 85 | 86 | public void setBitrate(IVideoBitrate bitrate) { 87 | this.bitrate = bitrate; 88 | } 89 | 90 | public IKeyFrameInterval getKeyFrameInterval() { 91 | return keyFrameInterval; 92 | } 93 | 94 | public void setKeyFrameInterval(IKeyFrameInterval keyFrameInterval) { 95 | this.keyFrameInterval = keyFrameInterval; 96 | } 97 | 98 | public ArrayList getExtraParams() { 99 | return extraParams; 100 | } 101 | 102 | public void setExtraParams(ArrayList extraParams) { 103 | this.extraParams = extraParams; 104 | } 105 | 106 | @Override 107 | public ArrayList getExtraProperties() { 108 | // TODO Auto-generated method stub 109 | return extraProperties; 110 | } 111 | 112 | @Override 113 | public void setExtraProperties(ArrayList extraProperties) { 114 | // TODO Auto-generated method stub 115 | this.extraProperties = extraProperties; 116 | } 117 | 118 | @Override 119 | public ICodecImplementation getImplementation() { 120 | // TODO Auto-generated method stub 121 | return this.codecImplementation; 122 | } 123 | 124 | @Override 125 | public void setImplementation(ICodecImplementation implementation) { 126 | // TODO Auto-generated method stub 127 | this.codecImplementation = implementation; 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/video/VideoBitrate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.video; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IVideoBitrate; 7 | import com.flashvisions.server.rtmp.transcoder.pojo.base.PassThruObject; 8 | 9 | public class VideoBitrate extends PassThruObject implements IVideoBitrate 10 | { 11 | @NotNull 12 | private IParameter minimum; 13 | 14 | @NotNull 15 | private IParameter maximum; 16 | 17 | @NotNull 18 | private IParameter average; 19 | 20 | @NotNull 21 | private IParameter deviceBuffer; 22 | 23 | 24 | public VideoBitrate(){ 25 | 26 | } 27 | 28 | 29 | public VideoBitrate(IVideoBitrate object){ 30 | this.setSameAsSource(object.getSameAsSource()); 31 | 32 | this.average = (AverageBitrate) object.getAverage(); 33 | this.minimum = (MinimumBitrate) object.getMinimum(); 34 | this.maximum = (MaximumBitrate) object.getMaximum(); 35 | this.deviceBuffer = (DeviceBuffer) object.getDeviceBuffer(); 36 | } 37 | 38 | public VideoBitrate(boolean sameAsSource){ 39 | this.setSameAsSource(sameAsSource); 40 | 41 | this.minimum = new MinimumBitrate(0); 42 | this.maximum = new MaximumBitrate(0); 43 | this.average = new AverageBitrate(0); 44 | this.deviceBuffer = new DeviceBuffer(0); 45 | } 46 | 47 | public VideoBitrate(IParameter average, IParameter minimum, IParameter maximum, IParameter deviceBuffer){ 48 | this.average = average; 49 | this.minimum = minimum; 50 | this.maximum = maximum; 51 | this.deviceBuffer = deviceBuffer; 52 | } 53 | 54 | public IParameter getMinimum() { 55 | return minimum; 56 | } 57 | 58 | public void setMinimum(IParameter minimum) { 59 | this.minimum = minimum; 60 | } 61 | 62 | public IParameter getMaximum() { 63 | return maximum; 64 | } 65 | 66 | public void setMaximum(IParameter maximum) { 67 | this.maximum = maximum; 68 | } 69 | 70 | public IParameter getDeviceBuffer() { 71 | return deviceBuffer; 72 | } 73 | 74 | public void setDeviceBuffer(IParameter deviceBuffer) { 75 | this.deviceBuffer = deviceBuffer; 76 | } 77 | 78 | @Override 79 | public IParameter getAverage() { 80 | // TODO Auto-generated method stub 81 | return average; 82 | } 83 | 84 | @Override 85 | public void setAverage(IParameter average) { 86 | // TODO Auto-generated method stub 87 | this.average = average; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/pojo/video/VideoCodec.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.pojo.video; 2 | 3 | 4 | import com.flashvisions.server.rtmp.transcoder.ffmpeg.Flags; 5 | import com.flashvisions.server.rtmp.transcoder.interfaces.ICodec; 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IParameter; 7 | import com.flashvisions.server.rtmp.transcoder.pojo.Codec; 8 | 9 | 10 | public class VideoCodec extends Codec { 11 | 12 | private static final String key = Flags.VIDEO_CODEC; 13 | 14 | 15 | public VideoCodec(){ 16 | super(); 17 | } 18 | 19 | public VideoCodec(ICodec codec) { 20 | super(codec); 21 | } 22 | 23 | public VideoCodec(Object name) { 24 | super(name); 25 | // TODO Auto-generated constructor stub 26 | } 27 | 28 | @Override 29 | public String getKey() { 30 | // TODO Auto-generated method stub 31 | return VideoCodec.key; 32 | } 33 | 34 | @Override 35 | public void setKey(String key) { 36 | // TODO Auto-generated method stub 37 | //NO OP 38 | } 39 | 40 | @Override 41 | public IParameter clone() { 42 | // TODO Auto-generated method stub 43 | return new VideoCodec(this.getValue()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/red5/command/AbortTranscodeCommand.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.red5.command; 2 | 3 | import org.apache.commons.chain.Command; 4 | import org.apache.commons.chain.Context; 5 | import org.red5.server.api.IConnection; 6 | import org.red5.server.api.Red5; 7 | 8 | import com.flashvisions.server.rtmp.transcoder.Constants; 9 | import com.flashvisions.server.rtmp.transcoder.context.TranscoderContext; 10 | import com.flashvisions.server.rtmp.transcoder.interfaces.ISession; 11 | import com.flashvisions.server.rtmp.transcoder.pool.TranscodeSessionPool; 12 | 13 | public class AbortTranscodeCommand implements Command { 14 | 15 | @Override 16 | public boolean execute(Context context) throws Exception { 17 | // TODO Auto-generated method stub 18 | TranscoderContext ctx = (TranscoderContext) context; 19 | TranscodeSessionPool pool = ctx.getPool(); 20 | IConnection connnection = Red5.getConnectionLocal(); 21 | 22 | String signature = (String) connnection.getAttribute(Constants.TRANSCODER_SESSION_ATTR); 23 | ISession session = pool.getSession(signature); 24 | session.stop(); 25 | 26 | return true; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/red5/command/DoTranscodeCommand.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.red5.command; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.chain.Command; 7 | import org.apache.commons.chain.Context; 8 | import org.red5.server.api.IConnection; 9 | import org.red5.server.api.Red5; 10 | 11 | import com.flashvisions.server.rtmp.transcoder.Constants; 12 | import com.flashvisions.server.rtmp.transcoder.context.TranscodeRequest; 13 | import com.flashvisions.server.rtmp.transcoder.context.TranscoderContext; 14 | import com.flashvisions.server.rtmp.transcoder.interfaces.ISession; 15 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderResource; 16 | import com.flashvisions.server.rtmp.transcoder.pool.TranscodeSessionPool; 17 | import com.flashvisions.server.rtmp.transcoder.utils.IOUtils; 18 | 19 | @SuppressWarnings("unused") 20 | public class DoTranscodeCommand implements Command { 21 | 22 | ITranscoderResource input; 23 | TranscodeRequest request; 24 | 25 | public DoTranscodeCommand(ITranscoderResource input, TranscodeRequest request) 26 | { 27 | this.input = input; 28 | this.request = request; 29 | } 30 | 31 | 32 | @Override 33 | public boolean execute(Context context) throws Exception { 34 | // TODO Auto-generated method stub 35 | TranscoderContext ctx = (TranscoderContext) context; 36 | File workingDir = null; 37 | 38 | File templateFile = new File(ctx.getTemplateDirectory() + File.separator + this.request.getTemplateFileName()); 39 | if(!templateFile.exists()) throw new IOException("Template not found"); 40 | 41 | if(this.request.getWorkingDirectory() != null) { 42 | workingDir = new File(this.request.getWorkingDirectory()); 43 | if(!workingDir.exists()) throw new IOException("Working directory not found"); 44 | } 45 | 46 | IOUtils.IdentifyInput(input); 47 | String stream = input.getMediaName(); 48 | 49 | TranscodeSessionPool pool = ctx.getPool(); 50 | 51 | ISession session = pool.checkOut(input, request); 52 | session.setWorkingDirectoryPath(workingDir.getAbsolutePath()); 53 | 54 | IConnection connnection = Red5.getConnectionLocal(); 55 | connnection.setAttribute(Constants.TRANSCODER_SESSION_ATTR, pool.getSignature(session)); 56 | 57 | session.start(); 58 | 59 | return true; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/system/Globals.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.system; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public final class Globals { 7 | 8 | public static class Vars{ 9 | public static final String FFMPEG_EXECUTABLE_PATH = "ffmpegExcutable"; 10 | public static final String OPERATING_SERVER = "operatingServer"; 11 | public static final String HOME_DIRECTORY = "homeDirectory"; 12 | public static final String HLS_DIRECTORY = "hlsDirectory"; 13 | public static final String WORKING_DIRECTORY = "workingDirectory"; 14 | public static final String TEMPLATE_DIRECTORY = "templateDirectory"; 15 | } 16 | 17 | private static Map envMap; 18 | 19 | private static void init() 20 | { 21 | envMap = new HashMap(); 22 | } 23 | 24 | public static void addEnv(String var, String value) 25 | { 26 | if(envMap == null) init(); 27 | envMap.put(var, value); 28 | } 29 | 30 | public static void removeEnv(String var) 31 | { 32 | if(envMap == null) init(); 33 | if(containsEnv(var)) envMap.remove(var); 34 | } 35 | 36 | public static boolean containsEnv(String var) 37 | { 38 | if(envMap == null) init(); 39 | return envMap.containsKey(var); 40 | } 41 | 42 | public static String getEnv(String var) 43 | { 44 | if(envMap == null) init(); 45 | if(containsEnv(var)) return envMap.get(var); 46 | return null; 47 | } 48 | 49 | public static Map getEnvs() 50 | { 51 | if(envMap == null) init(); 52 | return envMap; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/utils/SessionUtil.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.utils; 2 | 3 | import java.math.BigInteger; 4 | import java.security.MessageDigest; 5 | 6 | 7 | public class SessionUtil { 8 | 9 | public static String generateSessionSignature(String source, String template) 10 | { 11 | String content = source + template; 12 | MessageDigest md = null; 13 | byte[] thedigest = null; 14 | String hash = null; 15 | 16 | try 17 | { 18 | md = MessageDigest.getInstance("MD5"); 19 | md.reset(); 20 | md.update(content.getBytes()); 21 | thedigest = md.digest(); 22 | BigInteger bigInt = new BigInteger(1,thedigest); 23 | hash = bigInt.toString(16); 24 | while(hash.length() < 32 ){ 25 | hash = "0"+hash; 26 | } 27 | } 28 | catch(Exception e) 29 | { 30 | // TO DO 31 | } 32 | finally 33 | { 34 | md = null; 35 | thedigest = null; 36 | } 37 | 38 | return hash; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/utils/TranscoderUtils.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.utils; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.regex.Matcher; 6 | import java.util.regex.Pattern; 7 | 8 | import com.flashvisions.server.rtmp.transcoder.pojo.io.enums.Server; 9 | 10 | public class TranscoderUtils { 11 | 12 | public static boolean isValidMediaServer(String server) { 13 | 14 | for (Server c : Server.values()) { 15 | if (c.name().equals(server.toUpperCase())) { 16 | return true; 17 | } 18 | } 19 | 20 | return false; 21 | } 22 | 23 | public static List captureLibraries(String ffmpegOutput) 24 | { 25 | List libraries = new ArrayList(); 26 | Pattern p = Pattern.compile("--enable-[^\\s]*", Pattern.CASE_INSENSITIVE); 27 | Matcher matcher = p.matcher(ffmpegOutput); 28 | while(matcher.find()) { 29 | libraries.add(matcher.group().replace("--enable-", "")); 30 | } 31 | 32 | return libraries; 33 | } 34 | 35 | public static String captureVersion(String ffmpegOutput) 36 | { 37 | Pattern p2 = Pattern.compile("version[\\s][^\\s]*", Pattern.CASE_INSENSITIVE); 38 | Matcher matcher2 = p2.matcher(ffmpegOutput); 39 | if(matcher2.find()){ 40 | return matcher2.group().replace("version ", ""); 41 | } 42 | return null; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/impl/AudioBitrateValidator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.impl; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IAudioBitrate; 7 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidAudioBitrate; 8 | 9 | public class AudioBitrateValidator implements ConstraintValidator { 10 | 11 | ValidAudioBitrate constrain; 12 | 13 | @Override 14 | public void initialize(ValidAudioBitrate constrain) { 15 | // TODO Auto-generated method stub 16 | this.constrain = constrain; 17 | } 18 | 19 | @Override 20 | public boolean isValid(IAudioBitrate bitrate, ConstraintValidatorContext context) { 21 | // TODO Auto-generated method stub 22 | String message = null; 23 | boolean valid = true; 24 | 25 | try 26 | { 27 | // if follow source values 28 | if(bitrate.getSameAsSource()) 29 | return valid; 30 | 31 | if(!valid) { 32 | context.disableDefaultConstraintViolation(); 33 | context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); 34 | } 35 | } 36 | catch(Exception e) 37 | { 38 | valid = false; 39 | } 40 | 41 | return valid; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/impl/AudioChannelValidator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.impl; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IAudioChannel; 7 | import com.flashvisions.server.rtmp.transcoder.pojo.io.enums.AudioChannelType; 8 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidAudioChannel; 9 | 10 | public class AudioChannelValidator implements ConstraintValidator { 11 | 12 | ValidAudioChannel constrain; 13 | 14 | @Override 15 | public void initialize(ValidAudioChannel constrain) { 16 | // TODO Auto-generated method stub 17 | this.constrain = constrain; 18 | } 19 | 20 | @Override 21 | public boolean isValid(IAudioChannel channel, ConstraintValidatorContext context) { 22 | // TODO Auto-generated method stub 23 | String message = null; 24 | boolean valid = false; 25 | String channelType = (String) channel.getValue(); 26 | 27 | try 28 | { 29 | // if follow source values 30 | if(channel.getSameAsSource()) 31 | return valid; 32 | 33 | 34 | if(isInEnum(channelType, AudioChannelType.class)) 35 | { 36 | valid = true; 37 | } 38 | 39 | if(!valid) { 40 | context.disableDefaultConstraintViolation(); 41 | context.buildConstraintViolationWithTemplate(message+" "+channel.getValue()).addConstraintViolation(); 42 | } 43 | } 44 | catch(Exception e) 45 | { 46 | valid = false; 47 | } 48 | 49 | return valid; 50 | } 51 | 52 | public > boolean isInEnum(String value, Class enumClass) { 53 | for (E e : enumClass.getEnumConstants()) { 54 | if(e.name().equalsIgnoreCase(value)) { return true; } 55 | } 56 | return false; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/impl/AudioCodecValidator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.impl; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.ICodec; 7 | import com.flashvisions.server.rtmp.transcoder.pojo.io.enums.AudioCodecs; 8 | import com.flashvisions.server.rtmp.transcoder.pojo.io.enums.CodecOptions; 9 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidAudioCodec; 10 | 11 | public class AudioCodecValidator implements ConstraintValidator { 12 | 13 | ValidAudioCodec constrain; 14 | 15 | @Override 16 | public void initialize(ValidAudioCodec constrain) { 17 | // TODO Auto-generated method stub 18 | this.constrain = constrain; 19 | } 20 | 21 | @Override 22 | public boolean isValid(ICodec codec, ConstraintValidatorContext context) { 23 | // TODO Auto-generated method stub 24 | String message = null; 25 | boolean valid = true; 26 | 27 | try 28 | { 29 | String codecName = (String) codec.getValue(); 30 | 31 | if(!isInEnum(codecName, CodecOptions.class) && !isInEnum(codecName, AudioCodecs.class)) 32 | { 33 | valid = false; 34 | message = "{com.flashvisions.server.rtmp.transcoder.validation.audio.codec.invalid.generic}"; 35 | } 36 | 37 | if(isEnum(codecName, CodecOptions.COPY)) 38 | codec.setSameAsSource(true); 39 | 40 | if(isEnum(codecName, CodecOptions.DISABLE)) 41 | codec.setEnabled(false); 42 | 43 | if(isEnum(codecName, CodecOptions.SKIPTHRU)) 44 | codec.setIgnore(true); 45 | 46 | if(!valid) { 47 | context.disableDefaultConstraintViolation(); 48 | context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); 49 | } 50 | } 51 | catch(Exception e) 52 | { 53 | valid = false; 54 | } 55 | 56 | return valid; 57 | } 58 | 59 | public > boolean isInEnum(String value, Class enumClass) { 60 | for (E e : enumClass.getEnumConstants()) { 61 | if(e.name().equalsIgnoreCase(value)) { return true; } 62 | } 63 | return false; 64 | } 65 | 66 | public boolean isEnum(String element, Enum e) 67 | { 68 | return element.toLowerCase().equals(e.name().toLowerCase()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/impl/AudioSampleRateValidator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.impl; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IAudioSampleRate; 7 | import com.flashvisions.server.rtmp.transcoder.pojo.io.enums.AudioSampleRates; 8 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidAudioSampleRate; 9 | 10 | public class AudioSampleRateValidator implements ConstraintValidator { 11 | 12 | ValidAudioSampleRate constrain; 13 | 14 | @Override 15 | public void initialize(ValidAudioSampleRate constrain) { 16 | // TODO Auto-generated method stub 17 | this.constrain = constrain; 18 | } 19 | 20 | @Override 21 | public boolean isValid(IAudioSampleRate samplerate, ConstraintValidatorContext context) { 22 | // TODO Auto-generated method stub 23 | String message = null; 24 | boolean valid = false; 25 | 26 | try 27 | { 28 | // if follow source values 29 | if(samplerate.getSameAsSource()) 30 | return valid; 31 | 32 | for (AudioSampleRates rate : AudioSampleRates.values()) { 33 | if(rate.getValue() == (Integer)samplerate.getValue()) { 34 | valid = true; 35 | break; 36 | } 37 | } 38 | 39 | if(!valid) { 40 | context.disableDefaultConstraintViolation(); 41 | context.buildConstraintViolationWithTemplate(message+" "+samplerate.getValue()).addConstraintViolation(); 42 | } 43 | } 44 | catch(Exception e) 45 | { 46 | valid = false; 47 | } 48 | 49 | return valid; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/impl/CodecImplementationValidator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.impl; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.ICodecImplementation; 7 | import com.flashvisions.server.rtmp.transcoder.pojo.io.enums.CodecImplementations; 8 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidCodecImplementation; 9 | 10 | public class CodecImplementationValidator implements ConstraintValidator { 11 | 12 | ValidCodecImplementation constrain; 13 | @Override 14 | public void initialize(ValidCodecImplementation constrain) { 15 | // TODO Auto-generated method stub 16 | this.constrain = constrain; 17 | } 18 | 19 | @Override 20 | public boolean isValid(ICodecImplementation implementation, ConstraintValidatorContext context) { 21 | // TODO Auto-generated method stub 22 | String message = null; 23 | boolean valid = true; 24 | 25 | try 26 | { 27 | String implementationName = (String) implementation.getValue(); 28 | 29 | if(!isInEnum(implementationName, CodecImplementations.class)) 30 | { 31 | valid = false; 32 | message = "{com.flashvisions.server.rtmp.transcoder.validation.codec.implementation.invalid.generic}"; 33 | } 34 | 35 | if(!valid) { 36 | context.disableDefaultConstraintViolation(); 37 | context.buildConstraintViolationWithTemplate(message + " " + implementationName).addConstraintViolation(); 38 | } 39 | } 40 | catch(Exception e) 41 | { 42 | valid = false; 43 | } 44 | 45 | return valid; 46 | } 47 | 48 | public > boolean isInEnum(String value, Class enumClass) { 49 | for (E e : enumClass.getEnumConstants()) { 50 | if(e.name().equalsIgnoreCase(value)) { return true; } 51 | } 52 | return false; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/impl/VideoBitrateValidator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.impl; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IVideoBitrate; 7 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidVideoBitrate; 8 | 9 | public class VideoBitrateValidator implements ConstraintValidator { 10 | 11 | ValidVideoBitrate constrain; 12 | @Override 13 | public void initialize(ValidVideoBitrate constrain) { 14 | // TODO Auto-generated method stub 15 | this.constrain = constrain; 16 | } 17 | 18 | @Override 19 | public boolean isValid(IVideoBitrate videobitrate, ConstraintValidatorContext context) { 20 | // TODO Auto-generated method stub 21 | String message = null; 22 | boolean valid = true; 23 | 24 | try 25 | { 26 | // if follow source values 27 | if(videobitrate.getSameAsSource()) 28 | return valid; 29 | 30 | Integer min = (Integer) videobitrate.getMinimum().getValue(); 31 | Integer max = (Integer) videobitrate.getMaximum().getValue(); 32 | Integer avg = (Integer) videobitrate.getAverage().getValue(); 33 | Integer buff = (Integer) videobitrate.getDeviceBuffer().getValue(); 34 | 35 | 36 | if(min == 0 && max == 0 && avg == 0){ 37 | message = "{com.flashvisions.server.rtmp.transcoder.validation.video.bitrate.invalid.all}"; 38 | valid = false; 39 | } 40 | 41 | else if(max > 0 && buff <= 0){ 42 | message = "{com.flashvisions.server.rtmp.transcoder.validation.video.bitrate.invalid.devicebuffer}"; 43 | valid = false; 44 | } 45 | 46 | else if(min > (max)){ 47 | message = "{com.flashvisions.server.rtmp.transcoder.validation.video.bitrate.invalid.min.max.error}"; 48 | valid = false; 49 | } 50 | 51 | 52 | 53 | if(!valid) { 54 | context.disableDefaultConstraintViolation(); 55 | context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); 56 | } 57 | } 58 | catch(Exception e) 59 | { 60 | valid = false; 61 | } 62 | 63 | return valid; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/impl/VideoCodecValidator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.impl; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.ICodec; 7 | import com.flashvisions.server.rtmp.transcoder.pojo.io.enums.CodecOptions; 8 | import com.flashvisions.server.rtmp.transcoder.pojo.io.enums.VideoCodecs; 9 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidVideoCodec; 10 | 11 | public class VideoCodecValidator implements ConstraintValidator { 12 | 13 | ValidVideoCodec constrain; 14 | @Override 15 | public void initialize(ValidVideoCodec constrain) { 16 | // TODO Auto-generated method stub 17 | this.constrain = constrain; 18 | } 19 | 20 | @Override 21 | public boolean isValid(ICodec codec, ConstraintValidatorContext context) { 22 | // TODO Auto-generated method stub 23 | String message = null; 24 | boolean valid = true; 25 | 26 | try 27 | { 28 | String codecName = (String) codec.getValue(); 29 | 30 | if(!isInEnum(codecName, CodecOptions.class) && !isInEnum(codecName, VideoCodecs.class)) 31 | { 32 | valid = false; 33 | message = "{com.flashvisions.server.rtmp.transcoder.validation.video.codec.invalid.generic}"; 34 | } 35 | 36 | if(isEnum(codecName, CodecOptions.COPY)) 37 | codec.setSameAsSource(true); 38 | 39 | if(isEnum(codecName, CodecOptions.DISABLE)) 40 | codec.setEnabled(false); 41 | 42 | if(isEnum(codecName, CodecOptions.SKIPTHRU)) 43 | codec.setIgnore(true); 44 | 45 | if(!valid) { 46 | context.disableDefaultConstraintViolation(); 47 | context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); 48 | } 49 | } 50 | catch(Exception e) 51 | { 52 | valid = false; 53 | } 54 | 55 | return valid; 56 | } 57 | 58 | public > boolean isInEnum(String value, Class enumClass) { 59 | for (E e : enumClass.getEnumConstants()) { 60 | if(e.name().equalsIgnoreCase(value)) { return true; } 61 | } 62 | return false; 63 | } 64 | 65 | public boolean isEnum(String element, Enum e) 66 | { 67 | return element.toLowerCase().equals(e.name().toLowerCase()); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/impl/VideoFrameRateValidator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.impl; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IFrameRate; 7 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidVideoFrameRate; 8 | 9 | public class VideoFrameRateValidator implements ConstraintValidator { 10 | 11 | ValidVideoFrameRate constrain; 12 | 13 | @Override 14 | public void initialize(ValidVideoFrameRate constrain) { 15 | // TODO Auto-generated method stub 16 | this.constrain = constrain; 17 | } 18 | 19 | @Override 20 | public boolean isValid(IFrameRate framerate, ConstraintValidatorContext context) { 21 | // TODO Auto-generated method stub 22 | String message = null; 23 | boolean valid = true; 24 | 25 | try 26 | { 27 | // if follow source values 28 | if(framerate.getSameAsSource()) 29 | return valid; 30 | 31 | Integer fps = (Integer) framerate.getValue(); 32 | 33 | if(fps<=0) 34 | { 35 | valid = false; 36 | } 37 | 38 | if(fps>=60) 39 | { 40 | valid = false; 41 | message = "{com.flashvisions.server.rtmp.transcoder.validation.video.framerate.invalid.toohigh}"; 42 | } 43 | 44 | 45 | if(!valid) { 46 | context.disableDefaultConstraintViolation(); 47 | context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); 48 | } 49 | } 50 | catch(Exception e) 51 | { 52 | valid = false; 53 | } 54 | 55 | return valid; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/impl/VideoFrameSizeValidator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.impl; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IFrameSize; 7 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidVideoFrameSize; 8 | 9 | public class VideoFrameSizeValidator implements ConstraintValidator { 10 | 11 | ValidVideoFrameSize constrain; 12 | @Override 13 | public void initialize(ValidVideoFrameSize constrain) { 14 | // TODO Auto-generated method stub 15 | this.constrain = constrain; 16 | } 17 | 18 | @Override 19 | public boolean isValid(IFrameSize framesize, ConstraintValidatorContext context) { 20 | // TODO Auto-generated method stub 21 | String message = null; 22 | boolean valid = true; 23 | 24 | try 25 | { 26 | // if follow source values 27 | if(framesize.getSameAsSource()) 28 | return valid; 29 | 30 | 31 | Integer width = (Integer) framesize.getWidth(); 32 | Integer height = (Integer) framesize.getHeight(); 33 | 34 | if(width<=0 || height<=0) 35 | { 36 | valid = false; 37 | } 38 | 39 | if(width>=3840 || height>=2040) 40 | { 41 | valid = false; 42 | message = "{com.flashvisions.server.rtmp.transcoder.validation.video.framesize.invalid.outofrange}"; 43 | } 44 | 45 | if(height % 2 != 0 ) 46 | { 47 | valid = false; 48 | message = "{com.flashvisions.server.rtmp.transcoder.validation.video.framesize.invalid.height}"; 49 | } 50 | 51 | 52 | if(!valid) { 53 | context.disableDefaultConstraintViolation(); 54 | context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); 55 | } 56 | } 57 | catch(Exception e) 58 | { 59 | valid = false; 60 | } 61 | 62 | return valid; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/impl/VideoKeyframeIntervalValidator.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.impl; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | 6 | import com.flashvisions.server.rtmp.transcoder.interfaces.IKeyFrameInterval; 7 | import com.flashvisions.server.rtmp.transcoder.pojo.video.Gop; 8 | import com.flashvisions.server.rtmp.transcoder.pojo.video.MinKeyframeInterval; 9 | import com.flashvisions.server.rtmp.transcoder.validation.interfaces.ValidVideoKeyframeInterval; 10 | 11 | public class VideoKeyframeIntervalValidator implements ConstraintValidator { 12 | 13 | ValidVideoKeyframeInterval constrain; 14 | 15 | @Override 16 | public void initialize(ValidVideoKeyframeInterval constrain) { 17 | // TODO Auto-generated method stub 18 | this.constrain = constrain; 19 | } 20 | 21 | @SuppressWarnings("unused") 22 | @Override 23 | public boolean isValid(IKeyFrameInterval kfi, ConstraintValidatorContext context) { 24 | // TODO Auto-generated method stub 25 | String message = null; 26 | boolean valid = true; 27 | 28 | try 29 | { 30 | // if follow source values 31 | if(kfi.getSameAsSource()) 32 | return valid; 33 | 34 | 35 | Gop gop = kfi.getGop(); 36 | MinKeyframeInterval minkfi = kfi.getMinimunInterval(); 37 | 38 | 39 | if(!valid) { 40 | context.disableDefaultConstraintViolation(); 41 | context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); 42 | } 43 | } 44 | catch(Exception e) 45 | { 46 | valid = false; 47 | } 48 | 49 | return valid; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/interfaces/ValidAudioBitrate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.interfaces; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import javax.validation.Constraint; 10 | import javax.validation.Payload; 11 | 12 | import com.flashvisions.server.rtmp.transcoder.validation.impl.AudioBitrateValidator; 13 | 14 | @Documented 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ElementType.METHOD,ElementType.FIELD,ElementType.CONSTRUCTOR,ElementType.PARAMETER,ElementType.ANNOTATION_TYPE}) 17 | @Constraint(validatedBy=AudioBitrateValidator.class) 18 | public @interface ValidAudioBitrate { 19 | String message() default "{com.flashvisions.server.rtmp.transcoder.validation.audio.bitrate.invalid.generic}"; 20 | Class[] groups() default {}; 21 | Class[] payload() default {}; 22 | } 23 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/interfaces/ValidAudioChannel.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.interfaces; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import javax.validation.Constraint; 10 | import javax.validation.Payload; 11 | 12 | import com.flashvisions.server.rtmp.transcoder.validation.impl.AudioChannelValidator; 13 | 14 | @Documented 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ElementType.METHOD,ElementType.FIELD,ElementType.CONSTRUCTOR,ElementType.PARAMETER,ElementType.ANNOTATION_TYPE}) 17 | @Constraint(validatedBy=AudioChannelValidator.class) 18 | public @interface ValidAudioChannel { 19 | String message() default "{com.flashvisions.server.rtmp.transcoder.validation.audio.channel.invalid.generic}"; 20 | Class[] groups() default {}; 21 | Class[] payload() default {}; 22 | } 23 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/interfaces/ValidAudioCodec.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.interfaces; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import javax.validation.Constraint; 10 | import javax.validation.Payload; 11 | 12 | import com.flashvisions.server.rtmp.transcoder.validation.impl.AudioCodecValidator; 13 | 14 | @Documented 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ElementType.METHOD,ElementType.FIELD,ElementType.CONSTRUCTOR,ElementType.PARAMETER,ElementType.ANNOTATION_TYPE}) 17 | @Constraint(validatedBy=AudioCodecValidator.class) 18 | public @interface ValidAudioCodec { 19 | String message() default "{com.flashvisions.server.rtmp.transcoder.validation.audio.codec.invalid.generic}"; 20 | Class[] groups() default {}; 21 | Class[] payload() default {}; 22 | } 23 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/interfaces/ValidAudioSampleRate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.interfaces; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import javax.validation.Constraint; 10 | import javax.validation.Payload; 11 | 12 | import com.flashvisions.server.rtmp.transcoder.validation.impl.AudioSampleRateValidator; 13 | 14 | @Documented 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ElementType.METHOD,ElementType.FIELD,ElementType.CONSTRUCTOR,ElementType.PARAMETER,ElementType.ANNOTATION_TYPE}) 17 | @Constraint(validatedBy=AudioSampleRateValidator.class) 18 | public @interface ValidAudioSampleRate { 19 | String message() default "{com.flashvisions.server.rtmp.transcoder.validation.audio.samplerate.invalid.generic}"; 20 | Class[] groups() default {}; 21 | Class[] payload() default {}; 22 | } 23 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/interfaces/ValidCodecImplementation.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.interfaces; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import javax.validation.Constraint; 10 | import javax.validation.Payload; 11 | 12 | import com.flashvisions.server.rtmp.transcoder.validation.impl.CodecImplementationValidator; 13 | 14 | @Documented 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ElementType.METHOD,ElementType.FIELD,ElementType.CONSTRUCTOR,ElementType.PARAMETER,ElementType.ANNOTATION_TYPE}) 17 | @Constraint(validatedBy=CodecImplementationValidator.class) 18 | public @interface ValidCodecImplementation { 19 | String message() default "{com.flashvisions.server.rtmp.transcoder.validation.codec.implementation.invalid.generic}"; 20 | Class[] groups() default {}; 21 | Class[] payload() default {}; 22 | } 23 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/interfaces/ValidVideoBitrate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.interfaces; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import javax.validation.Constraint; 10 | import javax.validation.Payload; 11 | 12 | import com.flashvisions.server.rtmp.transcoder.validation.impl.VideoBitrateValidator; 13 | 14 | @Documented 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ElementType.METHOD,ElementType.FIELD,ElementType.CONSTRUCTOR,ElementType.PARAMETER,ElementType.ANNOTATION_TYPE}) 17 | @Constraint(validatedBy=VideoBitrateValidator.class) 18 | public @interface ValidVideoBitrate { 19 | String message() default "{com.flashvisions.server.rtmp.transcoder.validation.video.bitrate.invalid.generic}"; 20 | Class[] groups() default {}; 21 | Class[] payload() default {}; 22 | } 23 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/interfaces/ValidVideoCodec.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.interfaces; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import javax.validation.Constraint; 10 | import javax.validation.Payload; 11 | 12 | import com.flashvisions.server.rtmp.transcoder.validation.impl.VideoCodecValidator; 13 | 14 | @Documented 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ElementType.METHOD,ElementType.FIELD,ElementType.CONSTRUCTOR,ElementType.PARAMETER,ElementType.ANNOTATION_TYPE}) 17 | @Constraint(validatedBy=VideoCodecValidator.class) 18 | public @interface ValidVideoCodec { 19 | String message() default "{com.flashvisions.server.rtmp.transcoder.validation.video.codec.invalid.generic}"; 20 | Class[] groups() default {}; 21 | Class[] payload() default {}; 22 | } 23 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/interfaces/ValidVideoFrameRate.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.interfaces; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import javax.validation.Constraint; 10 | import javax.validation.Payload; 11 | 12 | import com.flashvisions.server.rtmp.transcoder.validation.impl.VideoFrameRateValidator; 13 | 14 | @Documented 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ElementType.METHOD,ElementType.FIELD,ElementType.CONSTRUCTOR,ElementType.PARAMETER,ElementType.ANNOTATION_TYPE}) 17 | @Constraint(validatedBy=VideoFrameRateValidator.class) 18 | public @interface ValidVideoFrameRate { 19 | String message() default "{com.flashvisions.server.rtmp.transcoder.validation.video.framerate.invalid.generic}"; 20 | Class[] groups() default {}; 21 | Class[] payload() default {}; 22 | } 23 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/interfaces/ValidVideoFrameSize.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.interfaces; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import javax.validation.Constraint; 10 | import javax.validation.Payload; 11 | 12 | import com.flashvisions.server.rtmp.transcoder.validation.impl.VideoFrameSizeValidator; 13 | 14 | @Documented 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ElementType.METHOD,ElementType.FIELD,ElementType.CONSTRUCTOR,ElementType.PARAMETER,ElementType.ANNOTATION_TYPE}) 17 | @Constraint(validatedBy=VideoFrameSizeValidator.class) 18 | public @interface ValidVideoFrameSize { 19 | String message() default "{com.flashvisions.server.rtmp.transcoder.validation.video.framesize.invalid.generic}"; 20 | Class[] groups() default {}; 21 | Class[] payload() default {}; 22 | } 23 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/validation/interfaces/ValidVideoKeyframeInterval.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.validation.interfaces; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import javax.validation.Constraint; 10 | import javax.validation.Payload; 11 | 12 | import com.flashvisions.server.rtmp.transcoder.validation.impl.VideoKeyframeIntervalValidator; 13 | 14 | @Documented 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ElementType.METHOD,ElementType.FIELD,ElementType.CONSTRUCTOR,ElementType.PARAMETER,ElementType.ANNOTATION_TYPE}) 17 | @Constraint(validatedBy=VideoKeyframeIntervalValidator.class) 18 | public @interface ValidVideoKeyframeInterval { 19 | String message() default "{com.flashvisions.server.rtmp.transcoder.validation.video.keyframeinterval.invalid.generic}"; 20 | Class[] groups() default {}; 21 | Class[] payload() default {}; 22 | } 23 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/vo/TranscoderExecutionError.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.vo; 2 | 3 | public class TranscoderExecutionError { 4 | 5 | public Exception e; 6 | public String cause; 7 | public long timestamp; 8 | 9 | public TranscoderExecutionError() 10 | { 11 | 12 | } 13 | 14 | public TranscoderExecutionError(Exception e, String cause, long timestamp) 15 | { 16 | this.e = e; 17 | this.cause = cause; 18 | this.timestamp = timestamp; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/wowza/command/AbortTranscodeCommand.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.wowza.command; 2 | 3 | import org.apache.commons.chain.Command; 4 | import org.apache.commons.chain.Context; 5 | 6 | public class AbortTranscodeCommand implements Command { 7 | 8 | @Override 9 | public boolean execute(Context context) throws Exception { 10 | // TODO Auto-generated method stub 11 | 12 | return false; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/com/flashvisions/server/rtmp/transcoder/wowza/command/DoTranscodeCommand.java: -------------------------------------------------------------------------------- 1 | package com.flashvisions.server.rtmp.transcoder.wowza.command; 2 | 3 | 4 | import org.apache.commons.chain.Command; 5 | import org.apache.commons.chain.Context; 6 | 7 | import com.flashvisions.server.rtmp.transcoder.context.TranscodeRequest; 8 | import com.flashvisions.server.rtmp.transcoder.interfaces.ITranscoderResource; 9 | 10 | public class DoTranscodeCommand implements Command { 11 | 12 | ITranscoderResource input; 13 | TranscodeRequest request; 14 | 15 | public DoTranscodeCommand(ITranscoderResource input, TranscodeRequest request) 16 | { 17 | this.input = input; 18 | this.request = request; 19 | } 20 | 21 | 22 | @Override 23 | public boolean execute(Context context) throws Exception { 24 | 25 | return false; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /ffmpeg-transcoder/src/main/java/uk/co/jaimon/SimpleImageInfo.java: -------------------------------------------------------------------------------- 1 | package uk.co.jaimon; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | 9 | @SuppressWarnings("all") 10 | public class SimpleImageInfo { 11 | private int height; 12 | private int width; 13 | private String mimeType; 14 | 15 | private SimpleImageInfo() { 16 | 17 | } 18 | 19 | public SimpleImageInfo(File file) throws IOException { 20 | InputStream is = new FileInputStream(file); 21 | try { 22 | processStream(is); 23 | } finally { 24 | is.close(); 25 | } 26 | } 27 | 28 | public SimpleImageInfo(InputStream is) throws IOException { 29 | processStream(is); 30 | } 31 | 32 | public SimpleImageInfo(byte[] bytes) throws IOException { 33 | InputStream is = new ByteArrayInputStream(bytes); 34 | try { 35 | processStream(is); 36 | } finally { 37 | is.close(); 38 | } 39 | } 40 | 41 | private void processStream(InputStream is) throws IOException { 42 | int c1 = is.read(); 43 | int c2 = is.read(); 44 | int c3 = is.read(); 45 | 46 | mimeType = null; 47 | width = height = -1; 48 | 49 | if (c1 == 'G' && c2 == 'I' && c3 == 'F') { // GIF 50 | is.skip(3); 51 | width = readInt(is,2,false); 52 | height = readInt(is,2,false); 53 | mimeType = "image/gif"; 54 | } else if (c1 == 0xFF && c2 == 0xD8) { // JPG 55 | while (c3 == 255) { 56 | int marker = is.read(); 57 | int len = readInt(is,2,true); 58 | if (marker == 192 || marker == 193 || marker == 194) { 59 | is.skip(1); 60 | height = readInt(is,2,true); 61 | width = readInt(is,2,true); 62 | mimeType = "image/jpeg"; 63 | break; 64 | } 65 | is.skip(len - 2); 66 | c3 = is.read(); 67 | } 68 | } else if (c1 == 137 && c2 == 80 && c3 == 78) { // PNG 69 | is.skip(15); 70 | width = readInt(is,2,true); 71 | is.skip(2); 72 | height = readInt(is,2,true); 73 | mimeType = "image/png"; 74 | } else if (c1 == 66 && c2 == 77) { // BMP 75 | is.skip(15); 76 | width = readInt(is,2,false); 77 | is.skip(2); 78 | height = readInt(is,2,false); 79 | mimeType = "image/bmp"; 80 | } else { 81 | int c4 = is.read(); 82 | if ((c1 == 'M' && c2 == 'M' && c3 == 0 && c4 == 42) 83 | || (c1 == 'I' && c2 == 'I' && c3 == 42 && c4 == 0)) { //TIFF 84 | boolean bigEndian = c1 == 'M'; 85 | int ifd = 0; 86 | int entries; 87 | ifd = readInt(is,4,bigEndian); 88 | is.skip(ifd - 8); 89 | entries = readInt(is,2,bigEndian); 90 | for (int i = 1; i <= entries; i++) { 91 | int tag = readInt(is,2,bigEndian); 92 | int fieldType = readInt(is,2,bigEndian); 93 | long count = readInt(is,4,bigEndian); 94 | int valOffset; 95 | if ((fieldType == 3 || fieldType == 8)) { 96 | valOffset = readInt(is,2,bigEndian); 97 | is.skip(2); 98 | } else { 99 | valOffset = readInt(is,4,bigEndian); 100 | } 101 | if (tag == 256) { 102 | width = valOffset; 103 | } else if (tag == 257) { 104 | height = valOffset; 105 | } 106 | if (width != -1 && height != -1) { 107 | mimeType = "image/tiff"; 108 | break; 109 | } 110 | } 111 | } 112 | } 113 | if (mimeType == null) { 114 | throw new IOException("Unsupported image type"); 115 | } 116 | } 117 | 118 | private int readInt(InputStream is, int noOfBytes, boolean bigEndian) throws IOException { 119 | int ret = 0; 120 | int sv = bigEndian ? ((noOfBytes - 1) * 8) : 0; 121 | int cnt = bigEndian ? -8 : 8; 122 | for(int i=0;i 2 | 3 | 4 | 5 | Sample HLS Template 6 | 7 | 8 | 9 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /transcoder/templates/hls-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 100 | -------------------------------------------------------------------------------- /transcoder/templates/image-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 93 | -------------------------------------------------------------------------------- /transcoder/templates/record-mp3-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 88 | -------------------------------------------------------------------------------- /transcoder/templates/record-mp4-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 88 | -------------------------------------------------------------------------------- /transcoder/templates/rtmp-to-rtmp-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 88 | --------------------------------------------------------------------------------