0

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
 const projectId = 'clirnet-dev';
 const location = 'asia-south1';
 const inputUri = 'gs://video-test/video.mp4';
 const outputUri = 'gs://video-test/';
 //const templateId = 'my-job-template';
 const config = {
     "elementaryStreams": [
       {
         "videoStream": {
           "codecSettings": "h264",
           "h264": {
             "heightPixels": "360",
             "widthPixels": "640",
             "bitrateBps": "400000",
             "frameRate": "30",
           },
           "tune": 'zerolatency',
           "preset": 'superfast',
           //"heightPixels": 360,
           //"widthPixels": 640,
           //"bitrateBps": 400000,
           "rateControlMode": "vbr",
           //"frameRate": 30,
           "crfLevel": 26,
           //"gopMode": { "gopDuration": "1.0s",  }
         },
         "key": "video-stream0"
       },
       {
         "videoStream": {
           "codecSettings": "h264",
           "h264": {
             "heightPixels": "480",
             "widthPixels": "854",
             "bitrateBps": "1500000",
             "frameRate": "30",
           },
           "tune": 'zerolatency',
           "preset": 'superfast',
           //"heightPixels": 480,
           //"widthPixels": 854,
           //"bitrateBps": 1500000,
           "rateControlMode": "vbr",
           //"frameRate": 60,
           "crfLevel": 26,
           //"gopMode": { "gopDuration": "1.0s",  }
         },
         "key": "video-stream1"
       },
       {
         "videoStream": {
           "codecSettings": "h264",
           "h264": {
             "heightPixels": "720",
             "widthPixels": "1280",
             "bitrateBps": "3000000",
             "frameRate": "30",
           },
           "tune": 'zerolatency',
           "preset": 'superfast',
           //"heightPixels": 720,
           //"widthPixels": 1280,
           //"bitrateBps": 3000000,
           "rateControlMode": "vbr",
           //"frameRate": 60,
           "crfLevel": 26,
           //"gopMode": { "gopDuration": "1.0s",  }
         },
         "key": "video-stream2"
       },
       {
         "key": "audio-stream0",
         "audioStream":  {
           "codec":  "aac",
           "bitrateBps":  128000,
           "channelCount": 2,
           "channelLayout": ["fl", "fr"],
           "sampleRateHertz": 48000,
         }
       }
     ],
     "muxStreams": [
       {
         "key": "video-only-sd",
         "container": "fmp4",
         "elementaryStreams": [ "video-stream0" ],
         /*"segmentSettings": { 
           "segmentDuration": { "seconds": "2.0s" },
           "individualSegments": true 
         },*/
       },
       {
         "key": "video-only-md",
         "container": "fmp4",
         "elementaryStreams": [ "video-stream1" ],
         /*"segmentSettings": { 
           "segmentDuration": { "seconds": "2.0s" },
           "individualSegments": true 
         },*/
       },
       {
         "key": "video-only-hd",
         "container": "fmp4",
         "elementaryStreams": [ "video-stream2" ],
         /*"segmentSettings": { 
           "segmentDuration": { "seconds": "2.0s" },
           "individualSegments": true 
         },*/
       },
       {
         "key": "audio-only",
         "container": "fmp4",
         "elementaryStreams": [ "audio-stream0" ],
         /*"segmentSettings": { 
           "segmentDuration": { "seconds": "2.0s" },
           "individualSegments": true 
         }*/
       }
     ],
     "manifests": [
       {
         "fileName": "master.m3u8",
         "type": "HLS",
         "muxStreams": [
           "video-only-sd",
           "video-only-md",
           "video-only-hd",
           "audio-only"
         ]
       }
     ],
 };
 
 // Imports the Transcoder library
 const {TranscoderServiceClient} =
   require('@google-cloud/video-transcoder').v1;
 
 // Instantiates a client
 const transcoderServiceClient = new TranscoderServiceClient();
 
 async function createJobFromAdHoc() {
   // Construct request
   const request = {
     parent: transcoderServiceClient.locationPath(projectId, location),
     job: {
         inputUri: inputUri,
         outputUri: outputUri,
         config: config
     },
   };
 
   // Run request
   const [response] = await transcoderServiceClient.createJob(request);
   console.log(`Job: ${response.name}`);
 }
 
 createJobFromAdHoc();

This code is running perfectly when I have written in google cloud shell console. But Getting an error when I have written this in my local machine. I have service_account_credential.json and key.json for oauth2.0 But main problem is authorization. When I have written in cloud shell, it is automatically authorize. But when I am running from local machine I couldn't found the code for authorization. I found the code for bucket authorization(

const storage = new Storage({keyFilename: 'service_account_credential.json'});

) but couldn't found the code for video transcoder authorization.

I tried from https://cloud.google.com/transcoder/docs/samples/transcoder-create-job-from-ad-hoc

I have service_account_credential.json and key.json for oauth2.0

I want to transcode a video which is stored in google bucket, and I want to run a node js project from my local machine, and the result will be stored in google bucket also. I have all types of credential but couldn't run it in locally. My local node js code is below

const projectId = 'clirnet-dev';
 const location = 'asia-south1';
 const inputUri = 'gs://video-test/video.mp4';
 const outputUri = 'gs://video-test/';
 //const templateId = 'my-job-template';
 const config = {
     "elementaryStreams": [
       {
         "videoStream": {
           "codecSettings": "h264",
           "h264": {
             "heightPixels": "360",
             "widthPixels": "640",
             "bitrateBps": "400000",
             "frameRate": "30",
           },
           "tune": 'zerolatency',
           "preset": 'superfast',
           //"heightPixels": 360,
           //"widthPixels": 640,
           //"bitrateBps": 400000,
           "rateControlMode": "vbr",
           //"frameRate": 30,
           "crfLevel": 26,
           //"gopMode": { "gopDuration": "1.0s",  }
         },
         "key": "video-stream0"
       },
       {
         "videoStream": {
           "codecSettings": "h264",
           "h264": {
             "heightPixels": "480",
             "widthPixels": "854",
             "bitrateBps": "1500000",
             "frameRate": "30",
           },
           "tune": 'zerolatency',
           "preset": 'superfast',
           //"heightPixels": 480,
           //"widthPixels": 854,
           //"bitrateBps": 1500000,
           "rateControlMode": "vbr",
           //"frameRate": 60,
           "crfLevel": 26,
           //"gopMode": { "gopDuration": "1.0s",  }
         },
         "key": "video-stream1"
       },
       {
         "videoStream": {
           "codecSettings": "h264",
           "h264": {
             "heightPixels": "720",
             "widthPixels": "1280",
             "bitrateBps": "3000000",
             "frameRate": "30",
           },
           "tune": 'zerolatency',
           "preset": 'superfast',
           //"heightPixels": 720,
           //"widthPixels": 1280,
           //"bitrateBps": 3000000,
           "rateControlMode": "vbr",
           //"frameRate": 60,
           "crfLevel": 26,
           //"gopMode": { "gopDuration": "1.0s",  }
         },
         "key": "video-stream2"
       },
       {
         "key": "audio-stream0",
         "audioStream":  {
           "codec":  "aac",
           "bitrateBps":  128000,
           "channelCount": 2,
           "channelLayout": ["fl", "fr"],
           "sampleRateHertz": 48000,
         }
       }
     ],
     "muxStreams": [
       {
         "key": "video-only-sd",
         "container": "fmp4",
         "elementaryStreams": [ "video-stream0" ],
         /*"segmentSettings": { 
           "segmentDuration": { "seconds": "2.0s" },
           "individualSegments": true 
         },*/
       },
       {
         "key": "video-only-md",
         "container": "fmp4",
         "elementaryStreams": [ "video-stream1" ],
         /*"segmentSettings": { 
           "segmentDuration": { "seconds": "2.0s" },
           "individualSegments": true 
         },*/
       },
       {
         "key": "video-only-hd",
         "container": "fmp4",
         "elementaryStreams": [ "video-stream2" ],
         /*"segmentSettings": { 
           "segmentDuration": { "seconds": "2.0s" },
           "individualSegments": true 
         },*/
       },
       {
         "key": "audio-only",
         "container": "fmp4",
         "elementaryStreams": [ "audio-stream0" ],
         /*"segmentSettings": { 
           "segmentDuration": { "seconds": "2.0s" },
           "individualSegments": true 
         }*/
       }
     ],
     "manifests": [
       {
         "fileName": "master.m3u8",
         "type": "HLS",
         "muxStreams": [
           "video-only-sd",
           "video-only-md",
           "video-only-hd",
           "audio-only"
         ]
       }
     ],
 };
const {TranscoderServiceClient} =
   require('@google-cloud/video-transcoder').v1;
   require('dotenv').config();
   //const fs = require('fs');
   //const util = require('util');
   // Instantiates a client
 const transcoderServiceClient = new TranscoderServiceClient();
 
 async function createJobFromAdHoc() {
   // Construct request
   const request = {
     parent: transcoderServiceClient.locationPath(projectId, location),
     job: {
         inputUri: inputUri,
         outputUri: outputUri,
         config: config
     },
   };
 
   // Run request
   const [response] = await transcoderServiceClient.createJob(request);
   console.log(`Job: ${response.name}`);
 }
 
 createJobFromAdHoc();

and .env file is

GOOGLE_APPLICATION_CREDENTIALS=service_account_credential.json

I want to step by step process how to run it from local machine.

Note: I have kept the bucket public

0 Answers0