Introducing the audio delay parameter

One of the more unique tools available to the /video/merge Robot is its audio_delay parameter, which allows you to pause your audio for a defined amount of seconds. At first, adding an audio delay to a video may seem like a very specific use case. A quick search online for the term "audio delay" will give you pages of information on how to fix audio delay, rather than intentionally create it. However, after playing around with the /video/merge Robot for a little while, I quickly found one nifty use for the parameter that I want to share with you today 😄

Preparing the video and audio

In a similar vein to my last post showing off the new watermark parameters, I will be using a free video from Pexels videos to take us through a quick showcase of the parameter. Additionally, we'll need some audio to get started, so I'm going to use the free music track 'Hey Mercy' by Pierce Murphy released on the CC BY 4.0 license.

/video/merge Robot

Syncing things up

Using the /video/merge Robot, we can merge the aforementioned video and audio files together pretty easily. Here's an example of an implementation I created to extract the video and audio files stored on my Dropbox, merge them together, and upload the final video onto YouTube.

const TransloaditClient = require('transloadit')

const transloadit = new TransloaditClient({
  authKey: process.env.TRANSLOADIT_AUTH_KEY,
  authSecret: process.env.TRANSLOADIT_SECRET_KEY,
})

const options = {
  params: {
    steps: {
      dropbox_imported_video: {
        robot: '/dropbox/import',
        result: 'true',
        credentials: 'my_videos',
        path: `Videos/${process.argv[2]}`,
      },
      dropbox_imported_mp3: {
        robot: '/dropbox/import',
        result: 'true',
        credentials: 'my_videos',
        path: `Music/${process.argv[3]}`,
      },
      merged: {
        use: {
          steps: [
            {
              name: 'dropbox_imported_video',
              as: 'video',
            },
            {
              name: 'dropbox_imported_mp3',
              as: 'audio',
            },
          ],
        },
        robot: '/video/merge',
        result: 'true',
        audio_delay: 2.5,
        ffmpeg_stack: 'v3.3.3',
        preset: 'hls-1080p',
      },
      exported: {
        use: ['merged'],
        robot: '/youtube/store',
        credentials: 'youtube_auth_xxxxxxxxxx',
        title: process.argv[4],
        description: 'Using the /video/merge Robot I can merge audio and video!',
        keywords: 'music',
        category: 'education',
        visibility: 'unlisted',
      },
    },
  },
}

transloadit.createAssembly(options, (err, result) => {
  if (err) {
    throw err
  }
  console.log({ result })
})

And here we can see the result:

Doesn't seem to fit too well, does it? This is where the audio_delay parameter has its time to shine. Let's add it to the /video/merge part of the implementation, like so:

merged:{
  use: {
    steps: [
      {
        name: "dropbox_imported_video",
        as: "video"
      },
      {
        name: "dropbox_imported_mp3",
        as: "audio"
      }
    ]
  },
  robot: "/video/merge",
  result: true,
  audio_delay: 2.5,
  ffmpeg_stack: "v6.0.0",
  preset: "hls-1080p"
}

We can set the number of seconds to define when we want the audio to start playing. In our original video, it looks like the needle drops at around 2.5 seconds, so let's have our audio play from that point. After running the code again, I'm eager to take a look at the resulting video:

Hey presto! Our audio and video are synced up nicely together thanks to the audio delay parameter. In my opinion, this is one of the more unique parameters available to our Robots here at Transloadit. I hope this post will be able to spark some creativity, or at least help out anyone looking for that proverbial needle in the haystack: how to create — rather than fix — audio delay on a video!