public static string UploadVideoToLocation(Stream fs, String folder, String subFolder, String filename)
        {
            filename = filename.Replace("+", "");
            String filePath = folder.Replace("+", "") + "/" + subFolder.Replace("+", "") + "/" + Guid.NewGuid() + filename;

            if (string.IsNullOrEmpty(Path.GetExtension(filePath)))
            {
                filePath += ".mp4";
            }

            var client = s3Client;
            {
                PutObjectRequest request = new PutObjectRequest {
                    BucketName  = "videoToconvert",
                    CannedACL   = S3CannedACL.PublicRead,
                    Key         = filePath,
                    InputStream = fs
                };
                client.PutObject(request);
            }
            String finalOriginalPath = UrlPublic + filePath;

            finalOriginalPath = finalOriginalPath.Replace("+", "%2B");

            var etsClient = new AmazonElasticTranscoderClient(bucketRegion);

            var notifications = new Notifications()
            {
                Completed   = "arn:aws:sns:us-west-2:277579135337:Transcode",
                Error       = "arn:aws:sns:us-west-2:277579135337:Transcode",
                Progressing = "arn:aws:sns:us-west-2:277579135337:Transcode",
                Warning     = "arn:aws:sns:us-west-2:277579135337:Transcode"
            };

            var pipeline = new Pipeline();

            if (etsClient.ListPipelines().Pipelines.Count == 0)
            {
                pipeline = etsClient.CreatePipeline(new CreatePipelineRequest()
                {
                    Name          = "MyTranscodedVideos",
                    InputBucket   = "videoToconvert",
                    OutputBucket  = "videoToconvert",
                    Notifications = notifications,
                    Role          = "arn:aws:iam::277579135337:role/Elastic_Transcoder_Default_Role",
                }).Pipeline; //createpipelineresult
            }
            else
            {
                pipeline = etsClient.ListPipelines().Pipelines.First();
            }

            etsClient.CreateJob(new CreateJobRequest()
            {
                PipelineId = pipeline.Id,
                Input      = new JobInput()
                {
                    AspectRatio = "auto",
                    Container   = "mp4", //H.264
                    FrameRate   = "auto",
                    Interlaced  = "auto",
                    Resolution  = "auto",
                    Key         = filePath
                },
                Output = new CreateJobOutput()
                {
                    ThumbnailPattern = "thumbnnail{count}",
                    Rotate           = "0",
                    PresetId         = "1351620000001-000010", //Generic-720 px
                    Key = finalOriginalPath
                }
            });

            var delClient = s3Client;

            {
                //delClient.DeleteObject("VideoToConvert", filePath);
            }

            return(finalOriginalPath);
        }
Example #2
0
        private static bool UploadVideoToLocation()
        {
            try
            {
                var strSamplePath = GetAppSetting("SamplePath");
                var strFilePath   = strSamplePath;
                var strFilename   = Path.GetFileName(strSamplePath);
                var strExtension  = Path.GetExtension(strFilePath);
                var strRand       = GetRandomString();
                var strKey        = $"mwstag/ElasticTranscoder/Video/{strRand}/{strFilename}";

                if (string.IsNullOrEmpty(strExtension))
                {
                    strFilePath += ".mp4";
                }

                //Upload the video to the input bucket
                if (!UploadFile(strFilePath, strKey))
                {
                    Console.WriteLine("The video upload did not go well!!");
                    return(false);
                }

                //Create the pipelines
                var      strAWSAccessKey = GetAppSetting("AWSAccessKeyID");
                var      strAWSSecretKey = GetAppSetting("AWSSecretKey");
                var      objAmazonElasticTranscoderClient = new AmazonElasticTranscoderClient(strAWSAccessKey, strAWSSecretKey, RegionEndpoint.EUWest1);
                var      lstPipelines = objAmazonElasticTranscoderClient.ListPipelines();
                Pipeline objPipeline;
                if (!objAmazonElasticTranscoderClient.ListPipelines().Pipelines.Any())
                {
                    objPipeline = objAmazonElasticTranscoderClient.CreatePipeline(new CreatePipelineRequest
                    {
                        Name         = GetAppSetting("PipelineName"),
                        InputBucket  = GetAppSetting("Bucket"),
                        OutputBucket = GetAppSetting("Bucket"),
                        Role         = GetAppSetting("AWSRole")
                    }).Pipeline; //createpipelineresult
                }
                else
                {
                    objPipeline = objAmazonElasticTranscoderClient.ListPipelines().Pipelines.First();
                }


                //Create the job
                objAmazonElasticTranscoderClient.CreateJob(new CreateJobRequest
                {
                    PipelineId = objPipeline.Id,
                    Input      = new JobInput
                    {
                        AspectRatio = "auto",
                        Container   = "mp4", //H.264
                        FrameRate   = "auto",
                        Interlaced  = "auto",
                        Resolution  = "auto",
                        Key         = strKey
                    },
                    Output = new CreateJobOutput
                    {
                        ThumbnailPattern = $"{GetRandomString()}{{count}}",
                        Rotate           = "0",
                        PresetId         = "1351620000001-000010", //Generic-720 px
                        Key = $"mwstag/ElasticTranscoder/Video/{strRand}/output/{strFilename}"
                    }
                });
                return(true);
            }
            catch (Exception objException)
            {
                WriteToLog(objException.Message);
                return(false);
            }
        }