7

I have 2 video files that I want to concat using ffmpeg

initial.mp4 Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv), 720x720, 1077 kb/s, 15.98 fps, 16 tbr, 600 tbn, 1200 tbc (default)

ending.mp4 Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt470bg), 720x720 [SAR 1:1 DAR 1:1], 1287 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default

video_instructions_with_ending.txt

file initial.mp4
file initial.mp4
file initial.mp4
file ending.mp4

FFmpeg command

ffmpeg -f concat -i video_instructions_with_ending.txt -c copy output.mp4 -y

output.mp4 Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv), 720x720, 27 kb/s, 0.43 fps, 48 tbr, 19200 tbn, 38400 tbc (default)

The output file is supposed to be 6 seconds. But the output file is 3min and 32 seconds.

Any help will be appreciated

For the files that I used, you can get it from:HERE

Riandy
  • 372
  • 3
  • 10
  • Please refer to [this answer](https://stackoverflow.com/questions/5651654/ffmpeg-how-to-split-video-efficiently/38884327#38884327) , I think this will your solution. – Classsic Sep 08 '18 at 13:49

2 Answers2

3

Run this command on ending.mp4 and then concat with the new file:

ffmpeg -i ending.mp4 -c copy -video_track_timescale 600 newending.mp4

Long story short, timebases are different so the ending video is prolonged. See https://stackoverflow.com/a/43337235/5726027 for context on timestamps & bases.

Community
  • 1
  • 1
Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Hi, thanks for the help. I tried it and unfortunately the combined video doesn't have the newending.mp4 . Why is that? – Riandy Apr 24 '17 at 07:37
  • Your videos don't have the same encoding. One or both may need to be re-encoded. – Gyan Apr 24 '17 at 08:54
3

I tried the following command and it worked for me

ffmpeg -i initial.mp4 -i initial.mp4 -i initial.mp4 -i ending.mp4 -filter_complex concat=n=4:v=1:a=0 -f MOV output.mp4 -y

Explanation: FFmpeg has three concat methods

  1. concat protocol (ffmpeg -i 'concat:input1|input2' -codec copy output). - use it for binary concat compatible files like avi, mpeg-ts files
  2. concat demuxer (the method you have explained) - use when you want to avoid a re-encode and your format does not support file level concatenation.
  3. concat filter: (the above answer) - use if you need to re-encode such as when applying filters.

The 3rd options fits the scenario, as we need to re-encode the files.

arunk2
  • 2,246
  • 3
  • 23
  • 35
  • Hi Arun, thanks for the explanation. for the 3rd option, since it's reencoding, i will suffer quality loss right? – Riandy Apr 24 '17 at 07:46
  • Not necessarily. we can apply other parameters to have lossless encoding. There is a parameter crf (0-51). Where 0 for complete lossless and 51 for most lossy. When I tried crf with 18, I could have the source bitrate. Following is the command, I tried 'ffmpeg -i initial.mp4 -i initial.mp4 -i initial.mp4 -i ending.mp4 -filter_complex concat=n=4:v=1:a=0 -crf 18 output.mp4 -y' Ref: https://trac.ffmpeg.org/wiki/Encode/H.264 – arunk2 Apr 24 '17 at 09:14
  • This fixed my [issue](https://superuser.com/questions/1260156/adding-frame-to-video-with-same-fps-using-ffmpeg-concat-reduces-output-fps?noredirect=1#comment1853789_1260156) so thank you very much! I thought I was to avoid this method when using MP4 but clearly not! Thank you very much :) – J. Scull Oct 18 '17 at 13:44