I am working on VOD feature and for the past few days I am unable to output generated HLS playlist and files to GCP. I am using fluent-ffmpeg for uploading hls playlist to GCP. Here is the test code environment for uploading HLS to GCP using Node.js
const path = require('path');
const { Storage } = require('@google-cloud/storage');
const { createHLSPlaylist } = require('./utils/ffmpeg');
//* Creates a client, keyFileName is link to service account authentication credentials
const storage = new Storage({
keyFilename: path.join(
__dirname,
'./config/FILE.json'
),
projectId: process.env.GCP_PROJECT_ID,
});
//* To be used in upload GCP videos controller (copy this file contents within controller)
const url = 'URL';
const bucket = storage.bucket('BUCKETNAME');
const playlistName = 'file.m3u8';
const newFile = bucket.file(playlistName);
createHLSPlaylist(url, newFile.createWriteStream());
and here is the ffmpeg code that transcodes video in url to hls playlist
const ffmpeg = require('fluent-ffmpeg');
const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg');
ffmpeg.setFfmpegPath(ffmpegInstaller.path);
const createHLSPlaylist = (url, stream) => {
const command = ffmpeg(url, { timeout: 432000 })
.addOption([
'-profile:v baseline',
'-level 3.0',
'-start_number 0',
'-hls_time 10',
'-hls_list_size 0',
'-f hls',
])
.on('end', (stdout, stderr) => {
console.log('Transcoding succeeded !');
process.exit(1);
})
.on('start', (commandLine) => {
console.log('start', commandLine);
})
.on('codecData', (data) => {
console.log(`Input is ${data.audio} audio with ${data.video} video`);
})
.on('progress', (progress) => {
console.log(`Processing. Timemark: -> ${progress.timemark}`);
})
.on('stderr', (stderrLine) => {
// do nothing
})
.on('error', (err, stdout, stderr) => {
console.log(`error1: ${err}`);
console.log(`error2: ${stdout}`);
console.log(`error3: ${stderr}`);
console.log(`Cannot process video: ${err.message}`);
})
.on('data', (chunk) => {
console.log(`ffmpeg just wrote ${chunk.length} bytes`);
})
.pipe(stream, { end: true }); //end = true, close output stream after writing
};
module.exports = {
createHLSPlaylist,
};
I get the following messages via console.log
Processing. Timemark: -> 00:00:28.62
Processing. Timemark: -> 00:00:28.62
Processing. Timemark: -> 00:00:28.62
Processing. Timemark: -> 00:00:28.89
Transcoding succeeded !
But nothing in GCP bucket, any pointers will be appreciated
EDIT: I also converted URL to readStream and followed the following answer on github but this time no progress is showed.