1
Excuse the long question, I don't know an easier/shorter way to tell you my point.
I want to use ffmpeg to edit (fadeout etc.) AND split an audio file and merge it back together after. (I can't use -c copy because I use filters)
Using mp3 the split position obviously breaks when merging back together. So I tried using a raw, linear format but that produces artifacts at the split point, too.
Is there an audio codec that can be used for my purpose or do you have any other idea that could solve my problem? Thanks in advance!
As a starting point, here is my commands right now:
ffmpeg -t 20 -i song.mp3 -filter_complex afade=t=in:ss=0:d=2 -vn -f u16le part1.raw
ffmpeg -ss 20 -i song.mp3 -filter_complex afade=t=out:ss=60:d=2 -vn -f u16le part2.raw
^ I know this can be done without splitting, but I will later pipe the output etc. in a live environment so I need to split/merge...
ffmpeg -f u16le -i "concat:part1.raw|part2.raw" -vn output.mp3
MP3s don't have timestamps, so demuxer seeking is inexact. Switch to decoder seeking i.e. place ss/t after the input name. – Gyan – 2018-02-20T13:58:08.270
I will try that, thanks! But I am not too optimistic because I tried converting the mp3s to raws beforehand and that did not work either. – Henry – 2018-02-20T14:15:35.533
I was able to reproduce your issue using commands of your form, and avoid it by switching to decoder seek. – Gyan – 2018-02-21T08:44:50.853
Thanks dude! Will try that right now. Another thing, why didn't you post your first comment as an answer? I am new to this platform. – Henry – 2018-02-21T16:06:25.907
This doesn't work for me. Thing is I am using a continuous stream at the end. What I am writing to a pipe: Song1, Crossfade, first 10 secs Song2 -> Song2 -ss 10, Crossfade, first 10 secs Song3 ... - that goes into one instance that is then encoding an icecast stream + a mp3 file. That instance throws errors when using mp3: "Header missing / Invalid data found when processing input / Audio packet is invalid" etc. - when using raw it doesn't throw errors but there are artifacts at each cut. Any idea how I can achieve this? Can I tell the instances to merge with the last part of the stream? – Henry – 2018-02-21T17:14:52.380
So what is the exact series of commands you're using? – Gyan – 2018-02-21T17:25:27.927
Songs sample: ffmpeg -t 20 -i song1.mp3 -i song2.mp3 -filter_complex acrossfade=d=2 -vn -f mp3 -ss 10 -t 20 pipe:1 ; Stream: ffmpeg -f mp3 -i pipe:0 -y -vn icecast://source:pw@example.com:8000/stream.mp3 stream.mp3 (-t 20 on input for crossfade placement - also using mp3 now for the pipe as it makes no difference + mp3 shows errors in the stream instance) – Henry – 2018-02-21T18:32:05.357
That still uses demuxer seek to limit song1. The decoder delay may also be coming into play. Wrap your MP3s in a container like MKV and check. – Gyan – 2018-02-21T19:25:05.027
I've done some more testing and now think the problem is the delay before the next song starts. Do you know if it is possible to have a buffer in a pipe (so the song generation is ahead)? Another possibility would be to change inputs of the stream instance while running, but I think that's not possible... – Henry – 2018-02-21T20:28:47.433
After a lot of experimenting with nodejs streams (I am integrating this via fluent-ffmpeg) I managed to increase the stream buffer size and now have a fluent stream - thanks so much for your help! – Henry – 2018-02-22T09:19:09.337
If you have successfully resolved the issue, it would be worth writing up a summary and posting the steps as an answer to your question. – JonathanDavidArndt – 2018-04-10T02:01:49.713