由于所需的依赖性,我的模块正在停止加载我的Wowza应用程序

时间:2014-09-29 21:30:59

标签: java wowza

本地 - Wowza Streaming Engine 4.1.0,Windows 8,Java版本1.7.0_67
服务器 - Wowza流引擎AMI here。 Java版本1.7.0_65

我在本地和EC2实例上运行Wowza。

在本地它工作正常,我可以连接并发布流到我的应用程序没有问题。但是,我无法将流连接或发布到我的服务器上的应用程序。

我删除了与应用程序一起使用的.jar(模块),我能够连接并发布到我的应用程序,虽然它给了我一个警告,它找不到相关的模块,这是预期的

我重新安装了模块,重新启动了服务器,但我无法连接。

我的.jar文件似乎因某种原因停止加载应用程序。

这是我的模块的来源:

package com.xxxxxxxxxxxxxxx.recorder;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.S3ClientOptions;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.wowza.wms.application.*;
import com.wowza.wms.amf.*;
import com.wowza.wms.client.*;
import com.wowza.wms.module.*;
import com.wowza.wms.request.*;
import com.wowza.wms.stream.*;
import com.wowza.wms.rtp.model.*;
import com.wowza.wms.httpstreamer.model.*;
import com.wowza.wms.httpstreamer.cupertinostreaming.httpstreamer.*;
import com.wowza.wms.httpstreamer.smoothstreaming.httpstreamer.*;

public class RecorderModules extends ModuleBase implements AWSCredentialsProvider {

    IApplicationInstance appInstance;
    private String videoBucket;
    private String thumbBucket;
    private String videoDistro;
    private String thumbnailDistro;
    private String region;
    private AmazonS3Client s3;
    private String dir;
    public void onAppStart(IApplicationInstance appInstance) {

        String fullname = appInstance.getApplication().getName() + "/"
                + appInstance.getName();
        getLogger().info("onAppStart: " + fullname);
        this.appInstance = appInstance;

        try{
            videoBucket = appInstance.getProperties().getPropertyStr("videoBucket");
            getLogger().info("Video bucket is " + videoBucket);
            thumbBucket = appInstance.getProperties().getPropertyStr("thumbBucket");
            getLogger().info("Thumb bucket is " + thumbBucket);
            videoDistro = appInstance.getProperties().getPropertyStr("videoDistro");
            getLogger().info("Video distro is " + videoDistro);
            thumbnailDistro =appInstance.getProperties().getPropertyStr("thumbnailDistro");
            getLogger().info("thumbnail distro is " + thumbnailDistro);
            region = appInstance.getProperties().getPropertyStr("region");
            getLogger().info("region is " + region);
            s3 = new AmazonS3Client();
            s3.setEndpoint(region);
            getLogger().info("AmazonS3Client is created");
        }catch(Exception e){
            getLogger().info("Could not read config " + e);
        }
    }

    public void doSave(IClient client, RequestFunction function, AMFDataList params) {
        getLogger().info("doSave hit ");
        new File(dir + params.getString(3) + ".flv").renameTo(new File(dir+params.getString(4)+".flv"));
        getLogger().info("Starting upload");
        String thumbName = params.getString(4).replace("vid_", "thumb_")+".jpg";
        String flvName = params.getString(4)+".flv";
        String mp4Name = params.getString(4)+".mp4";
        try{
            PutObjectRequest p = new PutObjectRequest(videoBucket,flvName, new File(dir+flvName));
            p.setRequestCredentials(getCredentials());
            p.setCannedAcl(CannedAccessControlList.BucketOwnerFullControl);

            getLogger().info("attempting to upload " + flvName + " to " + videoBucket);
            s3.putObject(p);
            getLogger().info("flv upload complete " + videoBucket + " " + flvName);

            PutObjectRequest p2 = new PutObjectRequest(thumbBucket,thumbName, new File(dir+thumbName));
            p2.setRequestCredentials(getCredentials());
            p2.setCannedAcl(CannedAccessControlList.PublicRead);

            getLogger().info("attempting to upload " + thumbName + " to " + thumbBucket);
            s3.putObject(p2);
            getLogger().info("thumb upload complete " + thumbBucket + " " + thumbName);

            String[] info = new String[5];
            info[0] =  videoDistro+params.getString(4);
            info[1] = thumbnailDistro+thumbName;
            info[2] = params.getString(4);
            info[3] = videoBucket;
            info[4] = thumbBucket;
            getLogger().info("sending info to client " + info[0]);
            //client.call("uploadDone", null,(Object[])info);
        }catch(Exception e){
            getLogger().info("Upload failed");
            getLogger().info(e);
            //client.call("uploadFailed")
        }

        //transcode
        //-crf 23 -refs 3 -profile:v baseline -level 3.0 -pix_fmt yuv420p -preset veryslow
        String[] command = {"ffmpeg",
                "-i", dir+params.getString(4)+".flv",
                "-crf", "23",
                "-refs","3",
                "-profile:v","baseline",
                "-level","3.0",
                "-pix_fmt","yuv420p",
                "-preset","veryslow",
                dir+params.getString(4)+".mp4"};
        try { 
            ProcessBuilder builder = new ProcessBuilder(command);
            builder.redirectErrorStream(true);
            getLogger().info("Starting process");
            Process process = builder.start();
            BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = null;
            while((line = in.readLine()) != null) {
              System.out.println(line);
            }
            process.waitFor();

            PutObjectRequest p = new PutObjectRequest(videoBucket,mp4Name, new File(dir+mp4Name));
            p.setRequestCredentials(getCredentials());
            p.setCannedAcl(CannedAccessControlList.BucketOwnerFullControl);

            getLogger().info("transcoding completed");
            s3.putObject(p);
            getLogger().info("mp4 file uploaded");

        } catch (Exception e) {
            getLogger().info("Error running ffmpeg");
            e.printStackTrace();
        }

        deleteFiles(params.getString(4).replace("vid_",""));

    }

    public void saveThumbnail(IClient client, RequestFunction function, AMFDataList params){
        String dir = client.getAppInstance().getStreamStoragePath()+"/"+"thumb_"+params.getString(4).split(",")[2]+".jpg";
        getLogger().info(params);
        Path path = Paths.get(dir);
        byte[] byteArr = (byte[])((AMFDataByteArray)params.get(3)).getValue();
        try {
            Files.write(path, byteArr, StandardOpenOption.CREATE_NEW);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public void onAppStop(IApplicationInstance appInstance) {
        String fullname = appInstance.getApplication().getName() + "/"
                + appInstance.getName();
        getLogger().info("onAppStop: " + fullname);
    }

    public void onConnect(IClient client, RequestFunction function, AMFDataList params) {
        getLogger().info("onConnect: " + client.getClientId());
    }

    public void onConnectAccept(IClient client) {
        getLogger().info("onConnectAccept: " + client.getClientId());
    }

    public void onConnectReject(IClient client) {
        getLogger().info("onConnectReject: " + client.getClientId());
    }

    public void onDisconnect(IClient client) {
        getLogger().info("onDisconnect: " + client.getClientId());
    }

    public void onStreamCreate(IMediaStream stream) { 
        getLogger().info("onStreamCreate: " + stream.getSrc());
    }

    public void onStreamDestroy(IMediaStream stream) {
        getLogger().info("onStreamDestroy: " + stream.getSrc());
    }

    public void onHTTPSessionCreate(IHTTPStreamerSession httpSession) {
        getLogger().info("onHTTPSessionCreate: " + httpSession.getSessionId());
    }

    public void onHTTPSessionDestroy(IHTTPStreamerSession httpSession) {
        getLogger().info("onHTTPSessionDestroy: " + httpSession.getSessionId());
    }

    public void onHTTPCupertinoStreamingSessionCreate(HTTPStreamerSessionCupertino httpSession) {
        getLogger().info(
                "onHTTPCupertinoStreamingSessionCreate: "
                        + httpSession.getSessionId());
    }

    public void onHTTPCupertinoStreamingSessionDestroy(HTTPStreamerSessionCupertino httpSession) {
        getLogger().info(
                "onHTTPCupertinoStreamingSessionDestroy: "
                        + httpSession.getSessionId());
    }

    public void onHTTPSmoothStreamingSessionCreate( HTTPStreamerSessionSmoothStreamer httpSession) {
        getLogger().info(
                "onHTTPSmoothStreamingSessionCreate: "
                        + httpSession.getSessionId());
    }

    public void onHTTPSmoothStreamingSessionDestroy( HTTPStreamerSessionSmoothStreamer httpSession) {
        getLogger().info(
                "onHTTPSmoothStreamingSessionDestroy: "
                        + httpSession.getSessionId());
    }

    public void onRTPSessionCreate(RTPSession rtpSession) {
        getLogger().info("onRTPSessionCreate: " + rtpSession.getSessionId());
    }

    public void onRTPSessionDestroy(RTPSession rtpSession) {
        getLogger().info("onRTPSessionDestroy: " + rtpSession.getSessionId());
    }

    public void onCall(String handlerName, IClient client, RequestFunction function, AMFDataList params) {
        getLogger().info("onCall: " + handlerName);
    }

    /* Overwritten method: Delete content of the same name before starting */
    public void publish(IClient client, RequestFunction function, AMFDataList params) {
        getLogger().info("publish hit");
        String name = params.getString(3).replace("flv:","").replace("vid_","").replace("_temp", "");
        getLogger().info("name:" + name);
        dir = appInstance.decodeStorageDir("${com.wowza.wms.AppHome}"+"/content/recorder/");
        deleteFiles(name);
        invokePrevious(client,function,params);
    }
    private void deleteFiles(String name){
        getLogger().info("deleting " + name);
        try {
            if(Files.exists(Paths.get(dir+"thumb_"+name+".jpg"))){
                getLogger().info("deleting  thumbnail");
                Files.delete(Paths.get(dir+"thumb_"+name+".jpg"));
            }
            if(Files.exists((Paths.get(dir+"vid_"+name+".flv")))){
                getLogger().info("deleting  video");
                Files.delete(Paths.get(dir+"vid_"+name+".flv"));
            }
            if(Files.exists((Paths.get(dir+"vid_"+name+".mp4")))){
                getLogger().info("deleting  mp4 video");
                Files.delete(Paths.get(dir+"vid_"+name+".mp4"));
            }
            if(Files.exists((Paths.get(dir+"vid_"+name+"_temp.flv")))){
                getLogger().info("deleting  temp video");
                Files.delete(Paths.get(dir+"vid_"+name+"_temp.flv"));
            }
        } catch (IOException e) {
            getLogger().info("Could not delete old files");
        }
    }

    @Override
    public AWSCredentials getCredentials() {
        getLogger().info("getting credentials");
        return new BasicAWSCredentials(appInstance.getProperties().getPropertyStr("accessKey"),appInstance.getProperties().getPropertyStr("secretKey"));
    }

    @Override
    public void refresh() {
        // TODO Auto-generated method stub

    }
}

可能与此有关: http://www.wowza.com/forums/showthread.php?36693-Aws-plugin-breaks-application-with-no-errors

这可能意味着我的.jar文件没有使用所需的依赖项(AWS的东西)构建。

编辑:

所以我包含了所有的依赖项,确保AWS的东西在.jar中(我用winrar查看),现在它给了我“应用程序启动时找不到或无法加载模块类” 。我可以看到应用程序在那里。

这可能与我在Eclipse中遇到的这个错误有关,当我尝试创建一个提取所有依赖项的可运行jar时:“无法从给定的启动配置中找到main方法。”即使我收到此错误,它似乎也有效,因为.jar文件的大小增长了几倍。

2 个答案:

答案 0 :(得分:1)

确保应用程序文件夹确实存在;在你的wowza-install-folder中必须有一个名为“applications”的子文件夹。如果不存在,请手动创建。

在Wowza 4.x中,您必须使用Engine Manager来创建应用程序并对其进行管理。打开引擎管理器(http://your.ec2.server:8088)并选择特定应用程序;然后选择“传入安全性”并检查“RTMP发布”下的内容。如果您不需要任何保护,请将其更改为“打开(无需身份验证)”;否则,在与NetConnection连接时,您必须从AS3代码发送凭据。

您可能还想检查[wowza-install-folder] / logs中的Wowza日志 - 如果连接失败,日志中应该有一条消息可能会为您提供有用的信息。

PS:我通常使用Pre-Built AMIs from Wowza's website来启动新实例。

答案 1 :(得分:0)

我通过在新服务器上安装所有内容来解决它。

我使用了自动生成的.jar文件,以及它所依赖的两个jar文件,commons-codec-1.9和aws-java-sdk-1.4.7,并使用"启动包& #34;方法,而不是稍后通过ftp传输依赖项。

一切正常。