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 🙂
Splitting audiofile / inserting new audiofile into the middle of existing
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.
{
"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"
}
]
}
}
}
}
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 🙂
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.
Thanks again for your help. I look into it and post here if I discover something useful.
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.
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".
I don’t know how I missed that, thanks 🙂