0

I'm trying to do gapless playback of segments generated using ffmpeg:

I use ffmpeg to encode 3 files from a source with exactly 240000 samples @ 48kHz, i.e. 5 seconds.

ffmpeg -i tone.wav -af atrim=start_sample=24000*0:end_sample=240000*1 -c:a opus 0.webm
ffmpeg -i tone.wav -af atrim=start_sample=24000*1:end_sample=240000*2 -c:a opus 1.webm
ffmpeg -i tone.wav -af atrim=start_sample=24000*2:end_sample=240000*3 -c:a opus 2.webm

When looking at the meta data (using ffprobe and ffmpeg -loglevel debug) from the file I get the following which seems to me inconsistent values:

Duration: 5.01,
Start 0.007
discard 648/900 samples
240312 samples decoded

If I have several of these files how would I play them seamlessly without gaps? i.e. in a browser I've tried:

sourceBuffer.timestampOffset = 5 * n - 648/48000; 
sourceBuffer.appendWindowStart = 5 * n; 
sourceBuffer.appendWindowEnd = 5 * (n+1);
sourceBuffer.appendBuffer(new Uint8Array(buffer[n]));

However, there are audible gaps.

How many samples am I actually supposed to discard? 0.007 * 48000, 648, or 240312 - 240000?

Here is a html page which can be opened in Chrome to test.

You need a simple http server to run it:

 << ls
 >> index.html 0.webm 1.webm 2.webm
 << npm install -g http-server
 << http-server --cors
ronag
  • 49,529
  • 25
  • 126
  • 221
  • did you try using frames:a flag? I'm not an expert in regards to opus/webm encoders... just like h.264 is limited for cutting at i frames, opus has a similar constrain (not sure if it's the encoder or the container). I assume trimming to wav file produces the exact length. Why do you use opus/webm, can you just use aac instead? – EladG Jul 02 '15 at 03:33
  • 240000 samples is exactly 250 frames in opus. The encoder needs some priming. I have the similar, worse, issues with aac. – ronag Jul 02 '15 at 04:47

0 Answers0