static void Main(string[] args)
        {
            var apiKey    = "5a2a846a26ace";
            var videoUrl  = "https://nyc3.s3.qencode.com/qencode/bbb_30s.mp4";
            var s3_path   = "s3://s3-eu-west-2.amazonaws.com/qencode-test";
            var s3_key    = "your_s3_key";
            var s3_secret = "your_s3_secret";

            try
            {
                var q = new QencodeApiClient(apiKey);
                Console.WriteLine("Access token: " + q.AccessToken);

                var task = q.GetMetadata(videoUrl);
                Console.WriteLine(task);
            }
            catch (QencodeApiException e)
            {
                Console.WriteLine("Qencode API exception: " + e.Message);
            }
            catch (QencodeException e)
            {
                Console.WriteLine("API call failed: " + e.Message);
            }
            Console.ReadKey();
        }
Exemple #2
0
 /// <summary> Creates new transcoding task </summary>
 /// <param name="api">a reference to QencodeApiClient object</param>
 /// <param name="taskToken">transcoding task token</param>
 public TranscodingTask(QencodeApiClient api, string taskToken, string uploadUrl)
 {
     this.api            = api;
     this.taskToken      = taskToken;
     this.statusUrl      = null;
     this.uploadUrl      = uploadUrl;
     OutputPathVariables = new Dictionary <string, string>();
 }
        static void Main(string[] args)
        {
            // You can find your API key under Project settings in your Dashboard on Qencode portal
            var apiKey = "your_api_key";

            // This loads API query from file.
            // Make sure you change source video url and destination params to some actual values.
            var transcodingParams = CustomTranscodingParams.FromFile("query.json");

            try
            {
                var q = new QencodeApiClient(apiKey);
                Console.WriteLine("Access token: " + q.AccessToken);

                var task = q.CreateTask();
                Console.WriteLine("Created new task: " + task.TaskToken);
                task.TaskCompleted = new RunWorkerCompletedEventHandler(
                    delegate(object o, RunWorkerCompletedEventArgs e)
                {
                    if (e.Error != null)
                    {
                        Console.WriteLine("Error: ", e.Error.Message);
                    }

                    var response = e.Result as TranscodingTaskStatus;
                    if (response.error == 1)
                    {
                        Console.WriteLine("Error: " + response.error_description);
                    }
                    else if (response.status == "completed")
                    {
                        Console.WriteLine("Video urls: ");
                        foreach (var video in response.videos)
                        {
                            Console.WriteLine(video.url);
                        }
                    }
                    else
                    {
                        Console.WriteLine(response.status);
                    }
                    Console.WriteLine("Done!");
                });

                var started = task.StartCustom(transcodingParams);
                Console.WriteLine("Status URL: " + started.status_url);
            }
            catch (QencodeApiException e)
            {
                Console.WriteLine("Qencode API exception: " + e.Message);
            }
            catch (QencodeException e)
            {
                Console.WriteLine("API call failed: " + e.Message);
            }
            Console.ReadKey();
        }
        static async Task Main(string[] args)
        {
            var apiKey = "your_api_key";
            var file   = new FileInfo(@"your_file_path");



            try
            {
                var             q = new QencodeApiClient(apiKey);
                TranscodingTask transcodingTask = q.CreateTask();
                Console.WriteLine("Access token: " + q.AccessToken);
                Console.WriteLine("Created new task: " + transcodingTask.TaskToken);
                var uploadUrl = $"{transcodingTask.UploadUrl}/{transcodingTask.TaskToken}";
                var res       = await TusTools.UploadAsync(file, uploadUrl, 1000);

                var fileUrl = res.url;

                var transcodingParams = new CustomTranscodingParams();

                transcodingParams.source = fileUrl;
                var format = new Format();
                format.output = "mp4";
                transcodingParams.format.Add(format);
                var startedTask = transcodingTask.StartCustom(transcodingParams);
                Console.WriteLine("Status URL: " + startedTask.status_url);
                TranscodingTaskStatus response;
                do
                {
                    Thread.Sleep(5000);
                    Console.Write("Checking status... ");
                    response = transcodingTask.GetStatus();
                    Console.WriteLine(String.Format("{0} - {1}%", response.status,
                                                    response.percent == null ? "0" : ((float)response.percent).ToString("0.00")));
                } while (response.status != "completed");
                if (response.videos.Count > 0)
                {
                    var video = response.videos[0];
                    Console.WriteLine("Playlist url: " + video.url);
                }
                if (response.error > 0)
                {
                    Console.WriteLine(response.error_description);
                }
                Console.WriteLine("Done!");
                var statusUrl = startedTask.status_url;
            }
            catch (QencodeApiException e)
            {
                Console.WriteLine("Qencode API exception: " + e.Message);
            }
            catch (QencodeException e)
            {
                Console.WriteLine("API call failed: " + e.Message);
            }
            Console.ReadKey();
        }
 public UploadTask(QencodeApiClient api, string taskToken, string upload_location, string file_fullName, long file_size, string file_sha1)
 {
     this.api             = api;
     this.taskToken       = taskToken;
     this.upload_location = upload_location;
     this.file_fullName   = file_fullName;
     this.file_size       = file_size;
     this.file_sha1       = file_sha1;
     OutputPathVariables  = new Dictionary <string, string>();
 }
        static void Main(string[] args)
        {
            var apiKey    = "your_api_key";
            var videoUrl  = "https://nyc3.s3.qencode.com/qencode/bbb_30s.mp4";
            var s3_path   = "s3://s3-eu-west-2.amazonaws.com/qencode-test";
            var s3_key    = "your_s3_key";
            var s3_secret = "your_s3_secret";

            var transcodingParams = new CustomTranscodingParams();

            transcodingParams.source = videoUrl;
            var format = new Format();

            //format.destination = new Destination();
            //format.destination.url = s3_path;
            //format.destination.key = s3_key;
            //format.destination.secret = s3_secret;
            format.output           = "advanced_hls";
            format.segment_duration = 6;
            format.start_time       = 0.2;
            format.duration         = 0.3;

            var stream = new Stream();

            stream.size          = "1920x1080";
            stream.audio_bitrate = 128;

            var vcodec_params = new Libx264_VideoCodecParameters();

            vcodec_params.vprofile        = "baseline";
            vcodec_params.level           = 31;
            vcodec_params.coder           = 0;
            vcodec_params.flags2          = "-bpyramid+fastpskip-dct8x8";
            vcodec_params.partitions      = "+parti8x8+parti4x4+partp8x8+partb8x8";
            vcodec_params.directpred      = 2;
            stream.video_codec_parameters = vcodec_params;

            format.stream = new List <Stream>();
            format.stream.Add(stream);

            transcodingParams.format.Add(format);

            try
            {
                var q = new QencodeApiClient(apiKey);
                Console.WriteLine("Access token: " + q.AccessToken);

                var task = q.CreateTask();
                Console.WriteLine("Created new task: " + task.TaskToken);
                TranscodingTaskStatus response;
                var started = task.StartCustom(transcodingParams);
                Console.WriteLine("Status URL: " + started.status_url);
                do
                {
                    Thread.Sleep(5000);
                    Console.Write("Checking status... ");
                    response = task.GetStatus();
                    Console.WriteLine(String.Format("{0} - {1}%", response.status,
                                                    response.percent == null ? "0" : ((float)response.percent).ToString("0.00")));
                } while (response.status != "completed");
                if (response.videos.Count > 0)
                {
                    var video = response.videos[0];
                    Console.WriteLine("Playlist url: " + video.url);
                }
                if (response.error > 0)
                {
                    Console.WriteLine(response.error_description);
                }
                Console.WriteLine("Done!");
            }
            catch (QencodeApiException e)
            {
                Console.WriteLine("Qencode API exception: " + e.Message);
            }
            catch (QencodeException e)
            {
                Console.WriteLine("API call failed: " + e.Message);
            }
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            //replace with your API Key
            var apiKey = "your_api_key";
            //replace with your transcoding profile ID
            var transcodingProfile = "5a670e6491581";
            var transferMethod     = "";
            var videoUrl           = "https://nyc3.s3.qencode.com/qencode/bbb_30s.mp4";

            try
            {
                var q = new QencodeApiClient(apiKey);
                Console.WriteLine("Access token: " + q.AccessToken);

                var task = q.CreateTask();
                task.StartTime = 60.015;
                task.Duration  = 10.575;
                task.OutputPathVariables.Add("SceneID", "17056");
                Console.WriteLine("Created new task: " + task.TaskToken);
                task.ProgressChanged = new ProgressChangedEventHandler(
                    delegate(object o, ProgressChangedEventArgs e)
                {
                    Console.WriteLine(string.Format("{0}% completed", e.ProgressPercentage));
                });

                task.TaskCompleted = new RunWorkerCompletedEventHandler(
                    delegate(object o, RunWorkerCompletedEventArgs e)
                {
                    if (e.Error != null)
                    {
                        Console.WriteLine("Error: ", e.Error.Message);
                    }

                    var response = e.Result as TranscodingTaskStatus;
                    if (response.error == 1)
                    {
                        Console.WriteLine("Error: " + response.error_description);
                    }
                    else if (response.status == "completed")
                    {
                        var video = response.videos[0];
                        Console.WriteLine(video.user_tag + ": " + video.url);
                    }
                    else
                    {
                        Console.WriteLine(response.status);
                    }
                    Console.WriteLine("Done!");
                });

                var started = task.Start(transcodingProfile, videoUrl, transferMethod);
                Console.WriteLine("Status URL: " + started.status_url);
            }
            catch (QencodeApiException e)
            {
                Console.WriteLine("Qencode API exception: " + e.Message);
            }
            catch (QencodeException e)
            {
                Console.WriteLine("API call failed: " + e.Message);
            }
            Console.ReadKey();
        }
Exemple #8
0
        /*
         * This example upload a local file,
         * transcode it and then,
         * download the transcoded file
         */

        static void Main(string[] args)
        {
            // You can find your API key under Project settings in your Dashboard on Qencode portal
            const string apiKey = "YOUR_API_KEY_HERE";
            const string relative_output_dir = "TranscodedOutput";             // relative output dir

            // This is the full file name of the source video
            string sourceVideoFullFileName = "E:\\dev\\My\\Sample720.flv";

            // if an argument is specified, the source video file will be readed from the first argument
            if (args.Length >= 1 && !string.IsNullOrEmpty(args[0]))
            {
                sourceVideoFullFileName = args[0];
            }

            try
            {
                // get access token
                Console.WriteLine("Requesting access token...");
                var q = new QencodeApiClient(apiKey);
                Console.WriteLine("\taccess token: '" + q.AccessToken + "'");

                // create a new task
                Console.WriteLine("Creating a new task...");
                var task = q.CreateTask();
                Console.WriteLine("\tcreated new task with token: '" + task.TaskToken + "' and url for direct video upload (TUS) '" + task.UploadUrl + "'");

                // direct video upload - initiate upload (get endpoint for task)
                Console.WriteLine("Initiate upload...");
                var srcFI  = new FileInfo(sourceVideoFullFileName);
                var client = new TusClient();
                var tusUploadLocationUrl = client.CreateAsync(task.UploadUrl + "/" + task.TaskToken, srcFI.Length).Result;
                Console.WriteLine("\tobtained TUS upload location: '" + tusUploadLocationUrl + "'");

                // direct video upload - send data
                var uploadOperation = client.UploadAsync(tusUploadLocationUrl, srcFI);
                Console.WriteLine("\ttransfer started");
                uploadOperation.Progressed += (transferred, total) =>
                {
                    Console.CursorLeft = 0;
                    Console.Write($"Progress: {transferred}/{total}");
                };
                Console.WriteLine();
                Console.WriteLine();
                uploadOperation.GetAwaiter().GetResult();
                Console.WriteLine("\tupload done");

                // define a custom task by reading query.json and filling the ##TUS_FILE_UUID## placeholder
                var tusFileUUID             = tusUploadLocationUrl.Substring(tusUploadLocationUrl.LastIndexOf('/') + 1);
                var customTrascodingJSON    = File.ReadAllText("query.json").Replace("##TUS_FILE_UUID##", tusFileUUID);
                var customTranscodingParams = CustomTranscodingParams.FromJSON(customTrascodingJSON);

                // start a custom task
                Console.WriteLine("Custom task starting..");
                Console.WriteLine(customTrascodingJSON);

                // start a custom task - set event handler
                bool taskCompletedOrError = false;
                task.TaskCompleted = new RunWorkerCompletedEventHandler(
                    delegate(object o, RunWorkerCompletedEventArgs e)
                {
                    if (e.Error != null)
                    {
                        taskCompletedOrError = true;
                        Console.WriteLine("Error: ", e.Error.Message);
                    }

                    var response = e.Result as TranscodingTaskStatus;
                    if (response.error == 1)
                    {
                        taskCompletedOrError = true;
                        Console.WriteLine("Error: " + response.error_description);
                    }
                    else if (response.status == "completed")
                    {
                        taskCompletedOrError = true;
                        Console.WriteLine("Video urls: ");
                        foreach (var video in response.videos)
                        {
                            Console.WriteLine(video.url);
                        }
                    }
                    else
                    {
                        Console.WriteLine(response.status);
                    }
                });
                // start a custom task - start
                Console.WriteLine("\tstarting...");
                var started = task.StartCustom(customTranscodingParams);                 // starts and poll

                // waiting
                Console.WriteLine("Waiting..");
                while (!taskCompletedOrError)
                {
                    Thread.Sleep(1000);
                }

                // get download url
                if (task.LastStatus == null)
                {
                    throw new InvalidOperationException("Unable to obtain download url");
                }
                var outputDownloadUrl = new Uri(task.LastStatus.videos.First().url);
                Console.WriteLine("Output download url: '" + outputDownloadUrl.ToString() + "'");
                string output_file_name = GetOutputFileName(sourceVideoFullFileName, outputDownloadUrl.Segments.Last());
                Console.WriteLine("Output file name: '" + output_file_name + "'");


                // download
                Console.WriteLine("Downloading..");
                HttpFileDownload(outputDownloadUrl, relative_output_dir, output_file_name);
                Console.WriteLine("\tdownload done");
                Environment.Exit(0);
            }
            catch (QencodeApiException e)
            {
                Console.WriteLine("Qencode API exception: " + e.Message);
                Environment.Exit(-1);
            }
            catch (QencodeException e)
            {
                Console.WriteLine("API call failed: " + e.Message);
                Environment.Exit(-1);
            }
        }
Exemple #9
0
 public Metadata(QencodeApiClient api, string taskToken, string uploadUrl) : base(api, taskToken, uploadUrl)
 {
     this.api       = api;
     this.taskToken = taskToken;
     this.uploadUrl = uploadUrl;
 }