0

I am trying to take some clips, edit their speed, trim them and then join them together. The clips need to be trimmed to a very short, specific length (0.238 seconds or 0.952 seconds). The intention is for the cuts to be timed to a music track.

The clips end up longer than expected and become out of time with the music track.

I think it is something to do with the trimming operation as the individual cut videos have the wrong duration as you can see in the data below.

Here is my FFmpeg code:

  1. Slow each video down using:
ffmpeg - input.mov -vf setpts=2*PTS -r 30 -y output1.mov
  1. Trim them to a specific length (very short: 0.238 seconds or 0.952 seconds) and force the aspect ratio. (Start time is some decimal in the centre of the video e.g. 0.45 seconds below)
ffmpeg -i output1.mov -ss 0.45 -t 0.238 -vf scale=w=1920:h=1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2 -r 30 -y output2.mov
  1. Concatenate the outputs using the concatenate complex filter:
ffmpeg -i 0.mov -i 1.mov -i 2.mov -i 3.mov -i 4.mov -i 5.mov -i 6.mov -filter_complex [0:v][0:a][1:v][1:a][2:v][2:a][3:v][3:a][4:v][4:a][5:v][5:a][6:v][6:a]concat=n=7:v=1:a=1[v][a] -map [v] -map [a] -y final_output.MOV

What am I doing wrong? Thanks for any help. Please see an example video data at each stage below for reference.

An example input file data:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 0
    compatible_brands: qt  
    creation_time   : 2021-10-25T13:04:19.000000Z
  Duration: 00:00:02.08, start: 0.000000, bitrate: 17770 kb/s
    Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 161 kb/s (default)
    Metadata:
      creation_time   : 2021-10-25T13:04:19.000000Z
      handler_name    : Core Media Audio
    Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 17508 kb/s, 60 fps, 60 tbr, 600 tbn, 1200 tbc (default)
    Metadata:
      creation_time   : 2021-10-25T13:04:19.000000Z
      handler_name    : Core Media Video
      encoder         : H.264
    Stream #0:2(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
    Metadata:
      creation_time   : 2021-10-25T13:04:19.000000Z
      handler_name    : Core Media Metadata
    Stream #0:3(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
    Metadata:
      creation_time   : 2021-10-25T13:04:19.000000Z
      handler_name    : Core Media Metadata
    Stream #0:4(und): Data: none (mebx / 0x7862656D), 69 kb/s (default)
    Metadata:
      creation_time   : 2021-10-25T13:04:19.000000Z
      handler_name    : Core Media Metadata
Stream mapping:
  Stream #0:1 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (aac (native) -> aac (native))

Example file data after slowing down:

Output #0, mov, to 'sloweddown.MOV':
  Metadata:
    major_brand     : qt  
    minor_version   : 0
    compatible_brands: qt  
    encoder         : Lavf58.29.100
    Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuvj420p(pc), 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
    Metadata:
      creation_time   : 2021-10-25T13:04:19.000000Z
      handler_name    : Core Media Video
      encoder         : Lavc58.54.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2021-10-25T13:04:19.000000Z
      handler_name    : Core Media Audio
      encoder         : Lavc58.54.100 aac
frame=  125 fps= 36 q=-1.0 Lsize=    2394kB time=00:00:04.06 bitrate=4822.0kbits/s speed=1.17x    
video:2355kB audio:34kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.185639%

Example data after trimming:

Output #0, mov, to 'middlefolder/71.MOV':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf58.29.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuvj420p(pc), 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
    Metadata:
      handler_name    : Core Media Video
      encoder         : Lavc58.54.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
      encoder         : Lavc58.54.100 aac
frame=    8 fps=0.0 q=-1.0 Lsize=     275kB time=00:00:00.25 bitrate=8816.0kbits/s speed=0.66x    
video:269kB audio:4kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.632812%

And here is some of the concatenation data before:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'middlefolder/0.MOV':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf58.29.100
  Duration: 00:00:00.27, start: 0.000000, bitrate: 15299 kb/s
    Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1920x1080 [SAR 1:1 DAR 16:9], 15144 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : Core Media Video
      encoder         : Lavc58.54.100 libx264
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 123 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'middlefolder/1.MOV':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf58.29.100
  Duration: 00:00:00.27, start: 0.000000, bitrate: 18134 kb/s
    Stream #1:0: Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1920x1080 [SAR 1:1 DAR 16:9], 17988 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : Core Media Video
      encoder         : Lavc58.54.100 libx264
    Stream #1:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 117 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'middlefolder/2.MOV':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf58.29.100
  Duration: 00:00:00.27, start: 0.000000, bitrate: 15967 kb/s
    Stream #2:0: Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1920x1080 [SAR 1:1 DAR 16:9], 15811 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : Core Media Video
      encoder         : Lavc58.54.100 libx264
    Stream #2:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from 'middlefolder/3.MOV':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf58.29.100
  Duration: 00:00:00.27, start: 0.000000, bitrate: 13229 kb/s
    Stream #3:0: Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1920x1080 [SAR 1:1 DAR 16:9], 13081 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : Core Media Video
      encoder         : Lavc58.54.100 libx264
    Stream #3:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 113 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
Input #4, mov,mp4,m4a,3gp,3g2,mj2, from 'middlefolder/4.MOV':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf58.29.100
  Duration: 00:00:00.98, start: 0.000000, bitrate: 7577 kb/s
    Stream #4:0: Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1920x1080 [SAR 1:1 DAR 16:9], 7503 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : Core Media Video
      encoder         : Lavc58.54.100 libx264
    Stream #4:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 124 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
Input #5, mov,mp4,m4a,3gp,3g2,mj2, from 'middlefolder/5.MOV':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf58.29.100
  Duration: 00:00:00.98, start: 0.000000, bitrate: 8719 kb/s
    Stream #5:0: Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1920x1080 [SAR 1:1 DAR 16:9], 8656 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : Core Media Video
      encoder         : Lavc58.54.100 libx264
    Stream #5:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio

And after concatenation:

Output #0, mov, to 'middlefolder/output.MOV':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf58.29.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuvj420p(pc, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
    Metadata:
      encoder         : Lavc58.54.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      encoder         : Lavc58.54.100 aac
frame=  209 fps= 31 q=-1.0 Lsize=    7421kB time=00:00:06.96 bitrate=8726.9kbits/s speed=1.04x    
video:7310kB audio:102kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.118551%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.