Concatenating Videos
#I’ve been cracking my head trying to figure out how to concatenate my dashcam videos, which get chopped by my dashcam into 15 minutes chunks. The most obvious one is ffmpeg, where I would use this:
$ ffmpeg -i “concat:
<a class="zem_slink" title="Ls" href="http://en.wikipedia.org/wiki/Ls" target="_blank" rel="wikipedia">ls -l</a> | <a class="zem_slink" title="Grep" href="http://en.wikipedia.org/wiki/Grep" target="_blank" rel="wikipedia">egrep</a> -i "apr\ \ 2" | awk 'BEGIN {ORS="|"} { print $9 }'
” -c copy output.AVI
What this does is concatenates all of the videos with a date stamp of April 2nd (the “apr \ \ 2”), sticks a “|” between then, and pipes them to ffmpeg as a parameter:
$ echo ffmpeg -i “concat:
ls -l | egrep -i "apr\ \ 2" | awk 'BEGIN {ORS="|"} { print $9 }'
” -c copy output.AVI
ffmpeg -i concat:PICT0001.AVI|PICT0002.AVI|PICT0003.AVI|PICT0004.AVI|PICT0005.AVI|PICT0006.AVI|PICT0007.AVI|PICT0008.AVI|PICT0009.AVI|PICT0010.AVI| -c copy output.AVI
However, here’s where linux version matters. On Fedora 18, I have ffmpeg V1.0.5:
$ ffmpeg -version
ffmpeg version 1.0.5
On Lubuntu 13.10 (Raring Ringtail), I have ffmpeg/avconv V0.8.6:
$ ffmpeg -version
ffmpeg version 0.8.6-6:0.8.6-0ubuntu0.12.10.1, Copyright (c) 2000-2013 the Libav developers
built on Apr 2 2013 17:07:34 with gcc 4.7.2
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
$ avconv -version
avconv version 0.8.6-6:0.8.6-0ubuntu0.12.10.1, Copyright (c) 2000-2013 the Libav developers
built on Apr 2 2013 17:07:34 with gcc 4.7.2
avconv 0.8.6-6:0.8.6-0ubuntu0.12.10.1
As a consequence, this is what happens when I run this the ffmpeg line on Lubuntu:
$ ffmpeg -i “concat:
ls -l | egrep -i "apr\ \ 2" | awk 'BEGIN {ORS="|"} { print $9 }'
” -c copy output.AVI
ffmpeg version 0.8.6-6:0.8.6-0ubuntu0.12.10.1, Copyright (c) 2000-2013 the Libav developers
built on Apr 2 2013 17:07:34 with gcc 4.7.2
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
[avi @ 0x8a8cf80] non-interleaved AVI
Input #0, avi, from ‘concat:PICT0001.AVI|PICT0002.AVI|PICT0003.AVI|PICT0004.AVI|PICT0005.AVI|PICT0006.AVI|PICT0007.AVI|PICT0008.AVI|PICT0009.AVI|PICT0010.AVI|':
Duration: 00:14:59.96, start: 0.000000, bitrate: 88466 kb/s
Stream #0.0: Video: mjpeg, yuvj422p, 1280x720, 30 tbr, 30 tbn, 30 tbc
Stream #0.1: Audio: adpcm_ima_wav, 16000 Hz, 1 channels, s16, 64 kb/s
Unrecognized option ‘c’
Failed to set value ‘copy’ for option ‘c’
Not to worry, I can always explicitly say what I want to do with the streams:
$ ffmpeg -i “concat:
ls -l | egrep -i "apr\ \ 2" | awk 'BEGIN {ORS="|"} { print $9 }'
” -vcodec copy -acodec copy output.AVI
ffmpeg version 0.8.6-6:0.8.6-0ubuntu0.12.10.1, Copyright (c) 2000-2013 the Libav developers
built on Apr 2 2013 17:07:34 with gcc 4.7.2
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
[avi @ 0x9561f80] non-interleaved AVI
Input #0, avi, from ‘concat:PICT0001.AVI|PICT0002.AVI|PICT0003.AVI|PICT0004.AVI|PICT0005.AVI|PICT0006.AVI|PICT0007.AVI|PICT0008.AVI|PICT0009.AVI|PICT0010.AVI|':
Duration: 00:14:59.96, start: 0.000000, bitrate: 88466 kb/s
Stream #0.0: Video: mjpeg, yuvj422p, 1280x720, 30 tbr, 30 tbn, 30 tbc
Stream #0.1: Audio: adpcm_ima_wav, 16000 Hz, 1 channels, s16, 64 kb/s
Output #0, avi, to ‘output.AVI’:
Metadata:
ISFT : Lavf53.21.1
Stream #0.0: Video: mjpeg, yuvj422p, 1280x720, q=2-31, 30 tbn, 30 tbc
Stream #0.1: Audio: adpcm_ima_wav, 16000 Hz, 1 channels, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Press ctrl-c to stop encoding
[avi @ 0x9579d40] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 4551 >= 4551
av_interleaved_write_frame(): Invalid argument
Oh, I guess that didn’t work either. Okay, if ffmpeg isn’t an option, then mencoder
is the next option:
$ mencoder -oac copy -ovc copy -idx -o output.AVI
ls -l | egrep -i "apr\ \ 2" | awk 'BEGIN {ORS=" "} { print $9 }'
MEncoder svn r34540 (Ubuntu), built with gcc-4.7 (C) 2000-2012 MPlayer Team
success: format: 0 data: 0x0 - 0x3f4a3440
libavformat version 53.21.1 (external)
Mismatching header version 53.19.0
AVI file format detected.
[aviheader] Video stream found, -vid 0
[aviheader] Audio stream found, -aid 1
Detected NON-INTERLEAVED AVI file format.
VIDEO: [MJPG] 1280x720 24bpp 30.000 fps 12399.9 kbps (1513.7 kbyte/s)
[V] filefmt:3 fourcc:0x47504A4D size:1280x720 fps:30.000 ftime:=0.0333
videocodec: framecopy (1280x720 24bpp fourcc=47504a4d)
audiocodec: framecopy (format=11 chans=1 rate=16000 bits=4 B/s=8110 sample-256)
Writing header…
ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
Writing header…
ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
^CPos: 692.7s 20782f (72%) 298.78fps Trem: 0min 1343mb A-V:0.000 [11759:64]
Writing index…
Writing header…
ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
I cancelled the run, but it seems to work. Strange that ffmpeg is so far behind on Ubuntu. So far behind, in fact, that the -c command fails. But on the plus side, at least mencoder works