# Splitting audiofile / inserting new audiofile into the middle of existing

**URL:** <https://community.transloadit.com/t/splitting-audiofile-inserting-new-audiofile-into-the-middle-of-existing/15606>\
**Category:** Transloadit\
**Created:** [February 16, 2021, 7:27am UTC](https://community.transloadit.com/t/splitting-audiofile-inserting-new-audiofile-into-the-middle-of-existing/15606 "2021-02-16T07:27:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jesper](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/jesper/32/289_2.png) [@Jesper](https://community.transloadit.com/u/Jesper)\
**Post date:** [February 16, 2021, 7:27am UTC](https://community.transloadit.com/t/splitting-audiofile-inserting-new-audiofile-into-the-middle-of-existing/15606/1 "2021-02-16T07:27:02Z")

</div>

Hi there,  
I’m very pleased with audio concat, using it to append and prepend audio files. However, I’m faced with the challenge of inserting a file in the middle of another. At a given time stamp. So I guess the flow could be to split audiofile A into pieces: A1, A2 - append the new file B onto A1, append A2 onto (A1B) resulting in (A1BA2). Anyone know if this can be achieved, or if there’s an entirely different way? Thanks so much in advance 🙂

---

<div class="post-metadata">

**Author:** ![WardenScotland](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/wardenscotland/32/323_2.png) [@WardenScotland](https://community.transloadit.com/u/WardenScotland)\
**Post date:** [February 16, 2021, 2:11pm UTC](https://community.transloadit.com/t/splitting-audiofile-inserting-new-audiofile-into-the-middle-of-existing/15606/2 "2021-02-16T14:11:12Z")

</div>

Hello, we can achieve your use case using two /audio/encode Robots with some custom ffmpeg code to cut the audio file into two halves; then, using our /audio/concat Robot, you can sandwich a third imported audio file between your previously halved audio file.

The one shortfall of this method is that you need to specify where your audio file’s middle point is (see -ss and -t flag).

I used a minute-long audio file to test this template.

```auto
{
  "steps": {
    ":original": {
      "robot": "/upload/handle"
    },
    "audio_imported": {
      "robot": "/http/import",
      "result": true,
      "url": "https://demos.transloadit.com/inputs/powered-by.mp3"
    },
    "first_half": {
      "use": ":original",
      "robot": "/audio/encode",
      "result": true,
      "ffmpeg": {
        "ss": "00:00:00",
        "t": 30
      },
      "ffmpeg_stack": "v3.3.3",
      "preset": "mp3"
    },
    "second_half": {
      "use": ":original",
      "robot": "/audio/encode",
      "result": true,
      "ffmpeg": {
        "ss": "00:00:30",
        "t": 30
      },
      "ffmpeg_stack": "v3.3.3",
      "preset": "mp3"
    },
      "merged": {
        "robot": "/audio/concat",
        "preset": "mp3",
        "ffmpeg_stack": "v3.3.3",
        "use": {
          "steps": [
            {
              "name": "first_half",
              "as": "audio_1"
            },
            {
              "name": "audio_imported",
              "as": "audio_2"
            },
            {
              "name": "second_half",
              "as": "audio_3"
            }
          ]
        }
      }
    }
}

```

---

<div class="post-metadata">

**Author:** ![Jesper](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/jesper/32/289_2.png) [@Jesper](https://community.transloadit.com/u/Jesper)\
**Post date:** [February 16, 2021, 2:30pm UTC](https://community.transloadit.com/t/splitting-audiofile-inserting-new-audiofile-into-the-middle-of-existing/15606/3 "2021-02-16T14:30:10Z")

</div>

Thanks so much Warden! This is brilliant. Will get to it first thing tomorrow! Now that I have you 🙂 I don’t suppose it would be possible to have ffmpeg detect the insertion spot by “listening” for at cue, like a high pitched beep, out of our ears range? Would make this work flow significantly more automatic 🙂

---

<div class="post-metadata">

**Author:** ![WardenScotland](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/wardenscotland/32/323_2.png) [@WardenScotland](https://community.transloadit.com/u/WardenScotland)\
**Post date:** [February 16, 2021, 6:14pm UTC](https://community.transloadit.com/t/splitting-audiofile-inserting-new-audiofile-into-the-middle-of-existing/15606/4 "2021-02-16T18:14:28Z")

</div>

Unfortunately, as far as I’m aware this isn’t an available feature FFmpeg has. Funnily enough, I looked for an API to do this a few weeks ago and didn’t find anything.

---

<div class="post-metadata">

**Author:** ![Jesper](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/jesper/32/289_2.png) [@Jesper](https://community.transloadit.com/u/Jesper)\
**Post date:** [February 17, 2021, 8:13am UTC](https://community.transloadit.com/t/splitting-audiofile-inserting-new-audiofile-into-the-middle-of-existing/15606/5 "2021-02-17T08:13:06Z")

</div>

Thanks again for your help. I look into it and post here if I discover something useful.

---

<div class="post-metadata">

**Author:** ![Jesper](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/jesper/32/289_2.png) [@Jesper](https://community.transloadit.com/u/Jesper)\
**Post date:** [February 18, 2021, 7:53am UTC](https://community.transloadit.com/t/splitting-audiofile-inserting-new-audiofile-into-the-middle-of-existing/15606/6 "2021-02-18T07:53:24Z")

</div>

> [@WardenScotland](#):
>
> `"ss": "00:00:30",`

I’ve successfully integrated this on my server and all is looking good! One question though: I can’t seem to get milliseconds to work, can you confirm this is not supported? A second is a pretty long span under certain circumstances.

---

<div class="post-metadata">

**Author:** ![WardenScotland](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/wardenscotland/32/323_2.png) [@WardenScotland](https://community.transloadit.com/u/WardenScotland)\
**Post date:** [February 18, 2021, 4:30pm UTC](https://community.transloadit.com/t/splitting-audiofile-inserting-new-audiofile-into-the-middle-of-existing/15606/7 "2021-02-18T16:30:17Z")

</div>

So to represent millisends you need to use a decimal value. I just successfully tested with the flag and value `"ss": "00:00:30.50"`.

---

<div class="post-metadata">

**Author:** ![Jesper](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/jesper/32/289_2.png) [@Jesper](https://community.transloadit.com/u/Jesper)\
**Post date:** [February 22, 2021, 2:39pm UTC](https://community.transloadit.com/t/splitting-audiofile-inserting-new-audiofile-into-the-middle-of-existing/15606/8 "2021-02-22T14:39:18Z")

</div>

I don’t know how I missed that, thanks 🙂
