[FFmpeg-user] trim silent mp4 to rounded second?

Erik Blankinship erikb at mediamods.com
Mon Nov 28 21:22:28 EET 2016


I have a silent mp4. I want to trim it to an exact rounded second. I am
having trouble.

For example, I want to trim a video to exactly 12 seconds (from 00:00:00.00
to 12 seconds).

I want to do this so I can concat multiple silent videos and have them all
start on a rounded second.

% ffprobe input.mp4
ffprobe version 3.2 Copyright (c) 2007-2016 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2 --enable-shared
--enable-pthreads --enable-gpl --enable-version3
--enable-hardcoded-tables --enable-avresample --cc=clang
--host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264
--enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.100 / 57. 64.100
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.56.100
  Duration: 00:02:12.56, start: 0.000000, bitrate: 410 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
640x360 [SAR 1:1 DAR 16:9], 407 kb/s, 29.86 fps, 29.97 tbr, 90k tbn,
59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler

and then...

% ffmpeg -i input.mp4 -t 12 -c copy output.mp4
[...]
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.56.100
  Duration: 00:02:12.56, start: 0.000000, bitrate: 410 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
640x360 [SAR 1:1 DAR 16:9], 407 kb/s, 29.86 fps, 29.97 tbr, 90k tbn,
59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.56.100
    Stream #0:0(und): Video: h264 (High) ([33][0][0][0] / 0x0021),
yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=2-31, 407 kb/s, 29.86 fps,
29.97 tbr, 90k tbn, 90k tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=  362 fps=0.0 q=-1.0 Lsize=     529kB time=00:00:11.97 bitrate=
361.8kbits/s speed=2.81e+03x
video:524kB audio:0kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 0.929963%

and then...

% ffprobe output.mp4
[...]
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.56.100
  Duration: 00:00:12.08, start: 0.000000, bitrate: 358 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
640x360 [SAR 1:1 DAR 16:9], 355 kb/s, 29.97 fps, 29.97 tbr, 90k tbn,
59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler

But the duration is just over 12 seconds. *These runovers can add up!* By
finessing the -tparameter I am able to get it right... but that -t alteration
is different for trimming to 9 seconds, or 3 seconds, etc.

How to get it right without re-encoding? (And hopefully without repeated
iterations of clipping and probing).


More information about the ffmpeg-user mailing list