if you just do ffmpeg -i inputfile
it will give you informational output including the length of the stream (there is also a ffprobe
command that you may or may not have that does the same thing, and may have more output control).
% ffmpeg -i foo.mkv
ffmpeg version 1.0.git-79133fd Copyright (c) 2000-2012 the FFmpeg developers
[...]
Input #0, matroska,webm, from 'foo.mkv':
Metadata:
creation_time : 2009-11-08 16:11:10
Duration: 00:43:16.71, start: 0.000000, bitrate: 2435 kb/s
Stream #0:0(eng): Video: h264 (High), yuv420p, 720x480 [SAR 32:27 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0:1(eng): Audio: ac3, 48000 Hz, stereo, s16, 192 kb/s (default)
Stream #0:2(eng): Subtitle: subrip
At least one output file must be specified
So you'll need to parse this output to get the length of each original file, and then use the -itsoffset
option with what you learn.
-itsoffset offset (input)
Set the input time offset in seconds. "[-]hh:mm:ss[.xxx]" syntax
is also supported. The offset is added to the timestamps of the
input files. Specifying a positive offset means that the
corresponding streams are delayed by offset seconds.
so you'll end up with something like (untested):
ffmpeg -i foo.mp3 -itsoffset 60 -i blah.mpeg -acodec copy -vcodec copy -copyts out.mkv
Best Answer
Something like this:
You'll need to adjust both thresholds (
start_threshold
) and durations (start_duration
) to your specific case.