Search code examples
ffmpegtransloadit

If multiple channels, merge then take sample length from audio file and save it to s3


I am using transloadit to extract the audio from a video file, which is then saved to S3. This works great, but I wanted to know how to:

  1. check if the file has multiple channels and then squash it inot one as per https://transloadit.com/demos/audio-encoding/merging-multiple-audio-streams/ - do I need to check for this or do i default to use this robot?

  2. extract a small sample from the audio file - and save this as a separate file.

For example, I have a 2h audio file from which I want to take 5% of the length and save this as sample.mp3

In ffmpeg, i can cut:

ffmpeg -ss 0 -t 30 -i original.mp3 sample.mp3

but I am unsure how to chain this workflow, here is what i have thus far:

const opts = {
  params: {
    notify_url: `${ process.env.SELF }/services/trans/${ jwToken }`,
    steps:      {
      import: {
        robot:  '/s3/import',
        use:    ':original',
        bucket: process.env.S3_INGEST,
        path:   ingest.key,
        key:    process.env.AWS_ID,
        secret: process.env.AWS_SECRET,
      },
      encode: {
        robot:        '/audio/encode',
        use:          'import',
        ffmpeg_stack: 'v2.2.3',
        preset:       'aac',
        ffmpeg:       {
          ab:  '128k',
        },
      },
      export: {
        robot:   '/s3/store',
        use:     'encode',
        bucket:  s3Export,
        path:    `${ prefix }/${ token }.m4a`,
        headers: {
          'Content-Type': 'audio/mp4',
          'x-amz-server-side-encryption': 'AES256',
        },
        key:    process.env.AWS_ID,
        secret: process.env.AWS_SECRET,
      },
    },
  },
};

in the docs, https://transloadit.com/docs/conversion-robots/ i can't see how to do this?

any advice is much appreciated.


Solution

  • Transloadit supports injection of ffmpeg params. So you can easily add your params into ffmpeg object as following.

    ffmpeg:{
    ab:  '128k',
    "ss": "0",
    "t": "30"
    }
    

    Please let us know if you have another question on support@transloadit.com