0

Can FFmpeg cut to a hundredth of a second?

When I try to cut a video using :

ffmpeg -i input.mov -ss 0.989 -t 0.238 -r 30 -y output.mov

The video duration of output.mov is 0.27 seconds and not 0.238 seconds.

Is this something that is limited by the video frame rate?

This is the input video data:

  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf58.29.100
  Duration: 00:00:04.43, start: 0.000000, bitrate: 12070 kb/s
    Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1920x1080 [SAR 1:1 DAR 16:9], 11995 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, 133 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio

This is the output video data:

 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

2 Answers 2

2

I believe you cannot cut less than a frame dealing with video streams.

With 30 fps a single frame is 0.033(3) seconds. The closest value for your requested 0.238 is 0.233(3). But it is less than needed and to not miss any data ffmpeg takes one more frame which results in 0.266(6). When rounded it is exactly 0.27.

1

Is this something that is limited by the video frame rate?

Indirectly — if the input video stream has a fixed frame rate. The true reason is system of PTS.

Every frame has its so-called presentation time stamp (PTS), expressed as an integer number.

Your input video stream has probably these PTS: enter image description here What is the meaning of these integer numbers?

They are multiples of the unit time (a tick) for the stream.

  • In your case, the unit time is as small as 1/15360 of second, because it is a reciprocal value of the so-called time base, and the time base for your input stream is 15360
    (see ..., 15360 tbn, ... in your listing).

Here are the same PTS values and calculated corresponding times:

PTS 0 512 1024 1536 2048
Presen-tation time in seconds 0*(1/15360)=0 1*(1/15360)=1/30 2*(1/15360)=2/30 3*(1/15360)=3/30 1*(1/15360)=4/30

Similar — but inverse — calculation is performed for your time values -ss 0.989 -t 0.238:

Required starting PTS 0.989 * 15360 = 15191
Required ending PTS (0.989 + 0.238) * 15360 = 18847

But frames with such PTS values in your input video don't exist, so FFmpeg will select frames with PTS 15360 (=30 * 512) and 18944 (=37 * 512), i.e. frame № 30 as a start frame and frame № 37 as an end frame.

There are 8 frames between frames 30 and 37 (inclusive), so the duration will be 8 * (1/30) = 8/30 seconds. It is the exact value. Your 0.27 seconds is the rounded one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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