Wowza Community

ffmpeg transcode MP4 from WowzaStreamRecorder error

Hello

My project need to store the recorded stream within Google Cloud Storage (1st bucket) and then transcode again to normalize them to the format we need (2nd bucket).

The first path is fine. Recorded files is uploaded to store correctly. When the uploading is finish, it will trigger Google Cloud Function and try to convert the file and then problem occur.

The output file is corrupted. It’s almost 0 byte. However, the MP4 file from the other source in not corrupted, FLV from Wowza Recorder as well. Only MP4 from Wowza Recorder

This Node.js code below is google cloud function I use

const storage = require('@google-cloud/storage')();
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const ffmpeg = require('fluent-ffmpeg');
const transcodedBucket = storage.bucket('MY-TRANSCODED-BUCKET');
const uploadBucket = storage.bucket('MY-UPLOAD-BUCKET');
ffmpeg.setFfmpegPath(ffmpegPath);
exports.transcodeVideo = function transcodeVideo(event, callback) {
  const file = event.data;

  const remoteWriteStream = transcodedBucket.file('transcoded-' + file.name)
    .createWriteStream({
      metadata: {
        metadata: file.metadata,
        contentType: 'video/mp4',
      },
    });
  const remoteReadStream = uploadBucket.file(file.name).createReadStream();
  // Transcode
  ffmpeg()
    .input(remoteReadStream)
    .outputOptions('-c:v copy')
    .outputOptions('-c:a aac')
    .outputOptions('-b:a 160k')
    .outputOptions('-f mp4')
    .outputOptions('-preset fast')
    .outputOptions('-movflags frag_keyframe+empty_moov')
    .on('start', (cmdLine) => {
      console.log('Started ffmpeg with command:', cmdLine);
    })
    .on('end', () => {
      console.log('Successfully re-encoded video.');
      callback();
    })
    .on('progress', function(progress) {
      console.log('Processing: @' + progress.currentFps + ' fps');
    })
    .on('error', (err, stdout, stderr) => {
      console.error('An error occured during encoding', err.message);
      console.error('stdout:', stdout);
      console.error('stderr:', stderr);
      callback(err);
    })
    .pipe(remoteWriteStream, { end: true });
};

FYI: to be more specific,

ffmpeg()
  .input(fs.createReadStream('input_filename.mp4'))
  .output('output_filename.mp4')
  .run()

The code above is not working (input is a read stream) but the below one is (input is directly file)

ffmpeg()
  .input('input_filename.mp4')
  .output('output_filename.mp4')
  .run(

Regards,