16

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?

josch
  • 867
  • 9
  • 16
  • Have you looked at oggCat? http://en.flossmanuals.net/ogg-theora/command-line-editing/cat-files/ – Josh Rumbut Jul 07 '15 at 18:01
  • @JoshRumbut yes and it suffers from containing audible gaps where the files are joined for some input – josch Jul 07 '15 at 20:50
  • You could try using [PiTiVi](http://en.flossmanuals.net/ogg-theora/ch040_pitivi/) and placing the clips sequentially on the timeline. – harrymc Jul 27 '16 at 06: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
  • if you can avoid copyright issues, sample files on which the problem occurs might be helpful – the8472 Jul 27 '16 at 22:27
  • Have you tried the [Ogg Video Tools](http://dev.streamnik.de/files.html) as mentioned in [this Answer](http://superuser.com/a/370546/314828)? – UeliDeSchwert Jul 28 '16 at 06:03
  • Have tried using `sox`? – Ralph Rönnquist Jul 30 '16 at 02:42
  • 2
    @RalphRönnquist Sox re-encodes the input. – josch Jul 31 '16 at 15:21
  • I think you will at least have to reencode the gap, possibly even everything afterwards (as your discontinuity will just be moved to the end of the reencoded part of the file). – allo Jul 06 '17 at 15:13

2 Answers2

7

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 – The Onin May 08 '18 at 19:19
  • @TheOnin The error is because you have to provide a textfile of the form "file 'MYFILE1'\n file 'MYFILE2'" etc to the program and make sure the in your filenames all the `'` characters are escaped – Dominik Jul 17 '22 at 11:29
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.

Nato Boram
  • 186
  • 11
  • 2
    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: http://meta.superuser.com/questions/5329/how-do-i-recommend-software-in-my-answers. Thanks. – fixer1234 Dec 06 '16 at 19:55
  • 3
    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 07 '16 at 07:29