Concatenating ogg video files from the command line

19

2

Okay. I've got a few ogg files I've created using a desktop recording tool. I've transcoded them using ffmpeg once (mainly to clip out the beginnings and the ends).

Now, I have 3 such files which I want to concatenate into a single .ogv file. I tried using oggCat, it crashed with some kind of error (I tried concatenating a file to itself using oggCat and that failed too leading me to believe that my distro is shipping a broken version of the package). Simply cating the files works but I can't seek which is not cool. mencoder run like this mencoder -ovc lavc -oac lavc file1.ogv file2.ogv file3.ogv -o complete.ogv. It transcodes the files into an avi and clips off a little of the 3 videos.

So, how do I do this?

Update 1: My current workaround is to transcode the 3 files into .mpg using ffmpeg, then cating them together and then transcoding them back into ogv.

Update 2: PiTiVi works for this kind of thing but I need something from the command line that I can automate and script.

Noufal Ibrahim

Posted 2011-12-13T17:34:20.937

Reputation: 659

@gry, What is missing from the current answer? – soandos – 2011-12-29T08:10:00.123

@gry, but you want the exact same features, but a different name? or is there a functionality difference you are looking for. I disagree that this is what the OP was asking for. He wanted his files concatenated, and oggCat was not working. Now it is, so I don't follow as to what is missing. – soandos – 2011-12-29T08:44:44.627

@soandos: The original question was "oggCat does not work for me, is there an alternative?" and though the asker got it to work, it could be useful to find possible alternatives as originally expected. – None – 2011-12-29T08:47:00.680

@gry, it 1) is fixed now (see last comment on my answer) and 2) I can't find the comment you are citing. – soandos – 2011-12-29T08:47:29.620

1My main intention was to get the videos concatenated. By the time the answers came up, I moved away from ogv and so didn't really care about the question too much. I explicitly mentioned that I didn't want to use oggCat because it wasn't working for me when I asked the question. – Noufal Ibrahim – 2011-12-29T18:07:50.960

@Noufal: I reproduce failure on Ubuntu 12.04 with error OggRingbuffer::getNextPageLength: ERROR ogg packet not aligned. Launchpad issue here, claims fixed in 12.10. What system are you in?

– Ciro Santilli 新疆改造中心法轮功六四事件 – 2014-03-15T21:09:12.317

Answers

9

Ogg Video Tools seems to do what you are looking for.

Short description:

Sometimes it would be nice to concatenate (join) two or more video files. For that you can use oggCat, which creates a continuous Ogg video file from the given files.

# oggCat newFile.ogv file1.ogv file2.ogv [ file3.ogv [...] ]

Note: The video files must correspond in framerate, keyframe gap, framesize etc.

See more here and here.

soandos

Posted 2011-12-13T17:34:20.937

Reputation: 22 744

2I've mentioned my experiences with oggCat in my question. Didn't work even when I tried to concatenate the file to itself. – Noufal Ibrahim – 2011-12-22T07:59:11.567

Have you tried downloading the package directly? And what was the error? – soandos – 2011-12-22T08:13:45.240

1I tried compiling it from source. I got a very large hexdump and then a segfault. – Noufal Ibrahim – 2011-12-22T08:21:55.047

this file? You might want to try an earlier version if compiling this fails. – soandos – 2011-12-22T08:25:03.947

1Not sure if this is any use to you, but the binary version I downloaded works. – soandos – 2011-12-22T08:30:27.663

Looks like there were Debian specific patches that messed it up. It seems to work when I compiled it directly from source. Thanks. Moot point though. Most of my viewers are having trouble viewing ogv files and so I switched to webM and flv. – Noufal Ibrahim – 2011-12-22T08:44:57.030

6

I would use ffmpeg's concat demuxer for this (requires a recent version of ffmpeg).

First, create a file called inputs.txt (or any arbitrary name), containing lines like:

file '/path/to/input1.ogv'
file '/path/to/input2.ogv'
file '/path/to/input3.ogv'

Note that that can be a relative or an absolute file path. If your files are all in the same directory and named in a pattern similar to input1.ogv, input2.ogv..., you can use a for loop to generate inputs.txt:

rm inputs.txt; for f in input*.ogv; do echo "$f" >> inputs.txt; done

Once you've created your file, you can losslessly concatenate the ogv files like so:

ffmpeg -f concat -i inputs.txt -c copy output.ogv

evilsoup

Posted 2011-12-13T17:34:20.937

Reputation: 10 085

Heh, found this answer right after figuring this by myself.. The oggCat solution didn't work for me due to some strange errors. This worked well.. – Jindra Helcl – 2014-10-04T22:57:23.010

1

http://www.xiph.org/oggz/ has a feature,

  • merge Merge Ogg files together, interleaving pages in order ofpresentation time.

Edit: This does not do what you want as you want to play one video after another one.


http://sox.sourceforge.net might work too, the syntax ( http://sox.sourceforge.net/sox.html ):

 sox infile1 infile2 outfile

Edit: this handles audio only.


You could try to compile the oggvideotools and see if oggCat works then.

Edit: this worked for you...


You could ask at http://sourceforge.net/projects/oggvideotools/support to fix the issues with your distribution, including the text of error messages that you have when you 1) run the binary you get from your distribution repositories 2) compile 3) run the compiled version.

Edit: you are looking for alternative programs to do the concatenation.


Try using mkvtoolnix to concatenate ogg files into single mkv, then extract ogg from it using the same tool

user89272

Posted 2011-12-13T17:34:20.937

Reputation:

1Merging is different from concatenation and doesn't do what I want. sox is audio only and doesn't handle videos. – Noufal Ibrahim – 2011-12-19T05:46:09.677

1It "interleaves pages in order of presentation time". I want to concatenate. One should play after the other is over. – Noufal Ibrahim – 2011-12-19T06:50:28.060

1Since this is the only answer, I guess Stack Exchange will award it the bounty even though it doesn't answer the question at all. – Noufal Ibrahim – 2011-12-19T17:24:32.613

I've already tried that. – Noufal Ibrahim – 2011-12-20T02:28:05.690

1I can get any of these tools "fixed" by asking on the respective mailing lists, issue trackers. I'm searching for alternatives to the ones I've specified. – Noufal Ibrahim – 2011-12-20T16:12:23.417

1I'll try mkvtoolnix although I'd prefer something like oggCat which actually works. I've given up on ogg though. Many people can't seem to play it. I've switched to webm and an flv fallback. – Noufal Ibrahim – 2011-12-21T06:12:30.073

1

Have you tried using PiTiVi? Place the three clips sequentially on the timeline and then save the result as one file.

Shane Wealti

Posted 2011-12-13T17:34:20.937

Reputation: 307

Yes but it's not command line. I can't automate this using a script if I use PiTiVi. – Noufal Ibrahim – 2011-12-22T07:35:06.187

1I've mentioned the point in my question now. – Noufal Ibrahim – 2011-12-22T07:36:24.670