11

I have a couple of ogg vorbis files, all encoded with the exact same properties that I want to concatenate into a single file.

I know that the ogg vorbis format supports plain concatenation of multiple files like:

$ cat file1.ogg file2.ogg > output.ogg

But sadly not all players are able to understand files created like that, for example my mobile audio player and I'd avoid to buy a new one. Other programs which don't understand it are gstreamer. That method also does not work if the input ogg files happen to all have the same stream id.

Additionally, since I'd like to throw away the original files and only keep the concatenated version, I'd like the concatenation to be done lossless, just as the cat solution.

I also want to avoid concatenating the files into a lossless format like flac as this would unnecessarily blow up the file size. If that would be okay, then I could keep the original ogg files and would use less space.

It seems that ffmpeg can sometimes do it using the concat demuxer:

$ cat inputs.txt
file 'in1.ogg'
file 'in2.ogg'
$ ffmpeg -f concat -i inputs.txt -c copy out.ogg

If I look at the raw hexdump of my input files, then I can find the vorbis packets exactly represented in the output file. So I guess really no re-encoding happens.

But this does not seem to work on all input files. Sometimes (not sure what triggers this), ffmpeg would give the warning:

Non-monotonous DTS in output stream 0:0; previous: 5011328, current: 5011200; changing to 5011329. This may result in incorrect timestamps in the output file.

And then I would hear a very faint "gap" between two files. Thus this certainly is not a global solution.

Since I couldn't find one I tried to write my own tool in this stackoverflow question.

Is there a way to concatenate multiple ogg vorbis files but without re-encoding them and with only a single stream per output? Which tool is able to do that job?

  • Have you looked at oggCat? en.flossmanuals.net/ogg-theora/command-line-editing/cat-files – Josh Rumbut Jul 7 '15 at 18:01
  • @JoshRumbut yes and it suffers from containing audible gaps where the files are joined for some input – josch Jul 7 '15 at 20:50
  • You could try using PiTiVi and placing the clips sequentially on the timeline. – harrymc Jul 27 '16 at 6:03
  • 1
    The OP (and me too) want a programmatic solution that does not involve user interaction after gathering the required files. – Villermen Jul 27 '16 at 13:05
  • 2
    @RalphRönnquist Sox re-encodes the input. – josch Jul 31 '16 at 15:21
2

ffmpeg -i "concat:ogg1.ogg|ogg2.ogg|ogg3.ogg" -c copy out.ogg creates a concatenated ogg file on my system, just a little bit smaller than the separate files combined (probably because of the shared metadata). It sounds the same to me, so the concatenation should be lossless. However, this doesn't add a small gap between the files.

ffmpeg -f concat -safe 0 -i ogg1.ogg -i ogg2.ogg -c copy out.ogg is supposed to work but it gives this error on my Homebrew (macOS) ffmpeg as of 3.3.2.

[concat @ 0x7f91e8800400] Line 1: unknown keyword 'OggS'
ogg1.ogg: Invalid data found when processing input

Source: https://trac.ffmpeg.org/wiki/Concatenate

  • I'm getting the same error – Housemd May 8 '18 at 19:19
0

You might want to take a look at FFmpeg. It has a lot of tools that I don't quite understand, but I do remember from the documentation that there's a tool to do exactly this. Otherwise, I think that you can use VLC Media Player's Command Line.

  • 1
    Can you expand your answer a bit? Just pointing to a product and its documentation doesn't really explain how to accomplish the solution. It's better to include some instructions here on how to use the product to solve the problem. Good guidance on recommending software here: meta.superuser.com/questions/5329/…. Thanks. – fixer1234 Dec 6 '16 at 19:55
  • Just using ffmpeg -f concat -i inputs.txt -c copy out.ogg doesn't work. I'm curious how you think this can be solved with ffmpeg. – josch Dec 7 '16 at 7:29

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.