1

I have list of video files (loaded from database), each with start and end time of requested interval:

  # file   begin  end
  v1.mp4   1:01   2:01
  v2.mp4   3:02   3:32
  v3.mp4   2:03   5:23

And I need to create single video file containing these intervals:

 [0:00]---v1---[2:00]---v2---[2:30]---v3---[5:50]

I preffer usig ffmpeg, since it is installed on server. Caller program is written in PHP.

It is easy to cut one input to one output (argument escaping removed for clarity):

  exec("ffmpeg -ss $begin -i $input_file -ss $begin -c copy $output_file");

I there any easier way than executing ffmpeg for each interval and then execute it once more to concatenate prepared clips together? I really do not like to have a lot of temporary files or dealing with complex process handling.

1
  • 1
    I'm voting to close this question as off-topic because it is about using some tool. Such questions are on topic only if they cover how the tool integrates into some development process – after all, this site is about Software Engineering. See our help center for details. Please read: Where does my tool question go? Usage of development tools is on topic on Stack Overflow. For general purpose tools go to Super User.
    – amon
    Commented Nov 13, 2017 at 10:11

1 Answer 1

-2

Solution #1:

ffmpeg -ss 1:01 -t 60 -i v1.mp4 -ss 3:02 -t 30 -i v2.mp4 -ss 2:03 -t 200 -i v3.mp4 \
-filter_complex "[0:v][0:a][1:v][1:a][2:v][2:a]concat=n=3:v=1:a=1" \
-y mixed.mp4

Solution #2:

ffmpeg -i v1.mp4 -i v2.mp4 -i v3.mp4 -filter_complex "\
[0:v]trim=61:121,setpts=PTS-STARTPTS[v1]; \
[0:a]atrim=61:121,asetpts=PTS-STARTPTS[a1]; \
[1:v]trim=182:212,setpts=PTS-STARTPTS[v2]; \
[1:a]atrim=182:212,asetpts=PTS-STARTPTS[a2]; \
[2:v]trim=123:323,setpts=PTS-STARTPTS[v3]; \
[2:a]atrim=123:323,asetpts=PTS-STARTPTS[a3]; \
[v1][a1][v2][a2][v3][a3]concat=n=3:v=1:a=1[v][a]" \
-map "[v]" -map "[a]" -y mixed.mp4
2
  • 3
    This site is about conceptual questions and answers are expected to explain things. Throwing code dumps instead of explanation is like copying code from IDE to whiteboard: it may look familiar and even sometimes be understandable, but it feels weird... just weird. Whiteboard doesn't have compiler
    – gnat
    Commented Nov 11, 2017 at 10:55
  • @gnat The code was very simple and did not need to be explained. Commented Nov 11, 2017 at 16:07

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