# Merge an audio file with a video file, keeping the shortest input stream duration intact

With [🤖/video/merge](/docs/robots/video-merge.md), you can easily compose a new video from an audio track and video, or a series of still images. However, when this Robot generates its output, it will retain the longest input file duration for the resulted output. This means that if you choose to merge a 20 second audio file with a 5 second video file, a still image of the final frame from your input video will be present while the remaining 15 seconds from your audio track finish.

To get around this and ensure that your merged video has a consistent length without any floating streams from either input, we use FFmpeg's `-shortest` flag. What this flag does is set encoding to finish when the shortest input stream comes to an end.

Step 1

### Handle uploads

We can handle uploads of your users directly. [Learn more ›](/services/handling-uploads.md)

[big-buck-bunny-5s.mp4](https://demos.transloadit.com/d7/e1d02b531b45dbb35aef0e428d99e4/big-buck-bunny-5s.mp4)

Video · 998 KB · 5s · 1024 × 768

[joakim\_karud-rock\_angel.mp3](https://demos.transloadit.com/3f/611cb3590f43c0ae447868952d5976/joakim%5Fkarud-rock%5Fangel.mp3)

Audio · 8.9 MB · 233s

```
":original": {
  "robot": "/upload/handle"
}
```

🤖 [/upload/handle](/docs/robots/upload-handle.md)

This bot receives uploads that your users throw at you from browser or apps, or that you throw at us programmatically

Step 2

### Filter files

We let you reject, or direct files against different encoding Steps. [Learn more ›](/services/file-filtering.md)

[joakim\_karud-rock\_angel.mp3](https://demos.transloadit.com/3f/611cb3590f43c0ae447868952d5976/joakim%5Fkarud-rock%5Fangel.mp3)

Audio · 8.9 MB · 233s

```
"audio_filtered": {
  "use": ":original",
  "robot": "/file/filter",
  "result": true,
  "accepts": [
    [
      "${file.mime}",
      "regex",
      "audio"
    ]
  ],
  "error_on_decline": false
}
```

🤖 [/file/filter](/docs/robots/file-filter.md)

This bot directs files to different encoding Steps based on your conditions

Step 3

### Filter files

We let you reject, or direct files against different encoding Steps. [Learn more ›](/services/file-filtering.md)

[big-buck-bunny-5s.mp4](https://demos.transloadit.com/d7/e1d02b531b45dbb35aef0e428d99e4/big-buck-bunny-5s.mp4)

Video · 998 KB · 5s · 1024 × 768

```
"video_filtered": {
  "use": ":original",
  "robot": "/file/filter",
  "result": true,
  "accepts": [
    [
      "${file.mime}",
      "regex",
      "video"
    ]
  ],
  "error_on_decline": false
}
```

🤖 [/file/filter](/docs/robots/file-filter.md)

This bot directs files to different encoding Steps based on your conditions

Step 4

### Merge video, audio, images into one video

We offer a variety of video encoding features like optimizing for different devices, merging, injecting ads, changing audio tracks, or adding company logos. [Learn more ›](/services/video-encoding.md)

[joakim\_karud-rock\_angel.mp4](https://demos.transloadit.com/23/a9189258af4acb9048cfd62407db25/joakim%5Fkarud-rock%5Fangel.mp4)

Video · 837 KB · 5s · 1024 × 768

```
"audio_added": {
  "use": {
    "steps": [
      {
        "name": "audio_filtered",
        "as": "audio"
      },
      {
        "name": "video_filtered",
        "as": "video"
      }
    ]
  },
  "robot": "/video/merge",
  "result": true,
  "ffmpeg": {
    "shortest": null
  },
  "ffmpeg_stack": "v7",
  "preset": "ipad-high"
}
```

🤖 [/video/merge](/docs/robots/video-merge.md)

This bot composes a new video by adding an audio track to existing still image(s) or video

Step 5

### Export files to Amazon S3

We export to the storage platform of your choice. [Learn more ›](/services/file-exporting.md)

`:original`

* [https://demos.transloadit.com/d7/e1d02b531b45dbb35aef0e428d99e4/big-buck-bunny-5s.mp4⁠](https://demos.transloadit.com/d7/e1d02b531b45dbb35aef0e428d99e4/big-buck-bunny-5s.mp4)
* [https://demos.transloadit.com/3f/611cb3590f43c0ae447868952d5976/joakim\_karud-rock\_angel.mp3⁠](https://demos.transloadit.com/3f/611cb3590f43c0ae447868952d5976/joakim%5Fkarud-rock%5Fangel.mp3)

`audio_filtered`

* [https://demos.transloadit.com/3f/611cb3590f43c0ae447868952d5976/joakim\_karud-rock\_angel.mp3⁠](https://demos.transloadit.com/3f/611cb3590f43c0ae447868952d5976/joakim%5Fkarud-rock%5Fangel.mp3)

`video_filtered`

* [https://demos.transloadit.com/d7/e1d02b531b45dbb35aef0e428d99e4/big-buck-bunny-5s.mp4⁠](https://demos.transloadit.com/d7/e1d02b531b45dbb35aef0e428d99e4/big-buck-bunny-5s.mp4)

`audio_added`

* [https://demos.transloadit.com/23/a9189258af4acb9048cfd62407db25/joakim\_karud-rock\_angel.mp4⁠](https://demos.transloadit.com/23/a9189258af4acb9048cfd62407db25/joakim%5Fkarud-rock%5Fangel.mp4)

```
"exported": {
  "use": [
    "audio_filtered",
    "video_filtered",
    "audio_added",
    ":original"
  ],
  "robot": "/s3/store",
  "credentials": "demo_s3_credentials",
  "url_prefix": "https://demos.transloadit.com/"
}
```

🤖 [/s3/store](/docs/robots/s3-store.md)

This bot exports encoding results to Amazon S3

## Live Demo. See for yourself

Loading Uppy demo…

This live demo is powered by [Uppy⁠](https://uppy.io/docs/guides/uppy-transloadit/), our open source file uploader that you can also use without Transloadit, and [tus⁠](https://tus.io), our open protocol for resumable file uploads that is making uploading more reliable across the world.

## Build this in your own language

```
<!-- This pulls Uppy from our CDN -->
<!-- For smaller self-hosted bundles, install Uppy and plugins manually: -->
<!-- npm i --save @uppy/core @uppy/dashboard @uppy/remote-sources @uppy/transloadit ... -->
<link
  href="https://releases.transloadit.com/uppy/v3.10.0/uppy.min.css"
  rel="stylesheet"
/>
<button id="browse">Select Files</button>
<script type="module">
  import {
    Uppy,
    Dashboard,
    ImageEditor,
    RemoteSources,
    Transloadit,
  } from 'https://releases.transloadit.com/uppy/v3.10.0/uppy.min.mjs'
  const uppy = new Uppy()
    .use(Transloadit, {
      waitForEncoding: true,
      alwaysRunAssembly: true,
      assemblyOptions: {
        params: {
          // It's often better store encoding instructions in your account
          // and use a `template_id` instead of adding these steps inline
          steps: {
            ':original': {
              robot: '/upload/handle',
            },
            audio_filtered: {
              use: ':original',
              robot: '/file/filter',
              result: true,
              accepts: [['${file.mime}', 'regex', 'audio']],
              error_on_decline: false,
            },
            video_filtered: {
              use: ':original',
              robot: '/file/filter',
              result: true,
              accepts: [['${file.mime}', 'regex', 'video']],
              error_on_decline: false,
            },
            audio_added: {
              use: {
                steps: [
                  {
                    name: 'audio_filtered',
                    as: 'audio',
                  }, 
,                  {
                    name: 'video_filtered',
                    as: 'video',
                  }, 
                ],
              },
              robot: '/video/merge',
              result: true,
              ffmpeg: {
                shortest: null,
              },
              ffmpeg_stack: 'v7',
              preset: 'ipad-high',
            },
            exported: {
              use: ['audio_filtered', 'video_filtered', 'audio_added', ':original'],
              robot: '/s3/store',
              credentials: 'demo_s3_credentials',
              url_prefix: 'https://demos.transloadit.com/',
            },
          },
        },
      },
    })
    .use(Dashboard, { trigger: '#browse' })
    .use(ImageEditor, { target: Dashboard })
    .use(RemoteSources, {
      companionUrl: 'https://api2.transloadit.com/companion',
    })
    .on('complete', ({ transloadit }) => {
      // Due to `waitForEncoding:true` this is fired after encoding is done.
      // Alternatively, set `waitForEncoding` to `false` and provide a `notify_url`
      console.log(transloadit) // Array of Assembly Statuses
      for (const assembly of transloadit) {
        console.log(assembly.results) // Array of all encoding results
      }
    })
    .on('error', (error) => {
      console.error(error)
    })
</script>

```

[Read docs: Browsers](/docs/sdks/uppy.md)

## So many ways to integrate

Transloadit is a service for companies with developers. And there are many ways developers can put Transloadit to good use inside your company to automate media processing.

#### Bulk imports

Add one of our [import Robots](/services/file-importing.md) to acquire and transcode massive media libraries.

#### Handling uploads

We are *the* experts at reliably [handling uploads](/services/handling-uploads.md). We wrote the [protocol⁠](https://tus.io/) for it.

#### Front-end integration

We integrate with web browsers via our next-gen file uploader [Uppy⁠](https://uppy.io/docs/guides/uppy-transloadit/) and SDKs for Android and iOS.

#### Back-end integration

Send us batch jobs in any server language using one of our [SDKs](/docs/sdks.md) or directly interfacing with our [REST API](/docs/api.md).

#### Pingbacks

Configure a [notify\_url](/services/content-delivery.md) to let your server receive transcoding results JSON in the `transloadit` POST field.

#### On-demand

Use our [Smart CDN](/services/file-importing.md) to adapt files on-demand and stream them directly to your users.

[Browsers](/docs/sdks/uppy.md)[TransloaditKit](/docs/sdks/transloaditkit.md)[Ruby SDK](/docs/sdks/ruby-sdk.md)[HTTP REST API](/docs/api.md)[Python SDK](/docs/sdks/python-sdk.md)[PHP SDK](/docs/sdks/php-sdk.md)[Node.js SDK](/docs/sdks/node-sdk.md)[Java SDK](/docs/sdks/java-sdk.md)[Go SDK](/docs/sdks/go-sdk.md)[cURL](/docs/sdks/curl.md)[Convex](/docs/sdks/convex.md)

[Browsers](/docs/sdks/uppy.md)[TransloaditKit](/docs/sdks/transloaditkit.md)[Ruby SDK](/docs/sdks/ruby-sdk.md)[HTTP REST API](/docs/api.md)[Python SDK](/docs/sdks/python-sdk.md)[PHP SDK](/docs/sdks/php-sdk.md)[Node.js SDK](/docs/sdks/node-sdk.md)[Java SDK](/docs/sdks/java-sdk.md)[Go SDK](/docs/sdks/go-sdk.md)[cURL](/docs/sdks/curl.md)[Convex](/docs/sdks/convex.md)

[Browsers](/docs/sdks/uppy.md)[TransloaditKit](/docs/sdks/transloaditkit.md)[Ruby SDK](/docs/sdks/ruby-sdk.md)[HTTP REST API](/docs/api.md)[Python SDK](/docs/sdks/python-sdk.md)[PHP SDK](/docs/sdks/php-sdk.md)[Node.js SDK](/docs/sdks/node-sdk.md)[Java SDK](/docs/sdks/java-sdk.md)[Go SDK](/docs/sdks/go-sdk.md)[cURL](/docs/sdks/curl.md)[Convex](/docs/sdks/convex.md)

## Other cool demos

* [View demo→Video EncodingAdd an audio track to video footage](/demos/video-encoding/add-audio-track-to-video-footage.md)
* [View demo→Video EncodingAdd an empty audio track to still video](/demos/video-encoding/add-empty-audio-track-to-still-video.md)
* [View demo→Document ProcessingAdd a header or footer to a PDF](/demos/document-processing/add-header-or-footer-to-pdf.md)

Try Transloadit

## Ready to get started?

Join thousands of developers who trust Transloadit for their file processing needs.

Building file processing from scratch

Ready-to-use API & SDKs

Scaling infrastructure headaches

Auto-scaling global infrastructure

Managing codec updates

Always up-to-date processing

Handling file security

Enterprise-grade security

Supporting all file formats

1000+ formats & codecs supported

Unpredictable costs

Transparent pricing

GDPR

GDPR

HIPAA

HIPAA

ISO 27001ISO27001

ISO 27001

AES-256

AES-256

SOC 2 Type II

SOC 2 Type II

[Try Transloadit for Free](/c/signup/)

[Try Transloadit for Free](/c/signup/)

No credit card needed · 5 GB included in the free plan · Cancel anytime
