Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Video Stabilization Output Length Change

I'm performing video stabilization using code from the videostab sample reduced down to simply perform one pass stabilization using OnePassStabilizer with a GaussianMotionFilter, and copy the source codec to the output writer. However, after copying the audio track from the original video to the stabilized video with FFmpeg I noticed that the audio wasn't correctly aligned. Further inspection revealed that the stabilized video (3:49.03) is slightly longer than the input video (3:47.05). The OpenCV code copies the source FPS to the output FPS, however, when comparing the frame rate in VLC the original video appears as 30.303030 while the stabilized video appears as 30.

Why is the stabilized video slightly longer than the original? Why is the stabilized video frame rate rounded down?

FFmpeg information for input video:

$ ffmpeg -i original.mp4 ... Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'original.mp4':   Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: isom3gp4
    creation_time   : 2016-02-25T14:09:56.000000Z   Duration: 00:03:47.05, start:
0.000000, bitrate: 4593 kb/s
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, 4498 kb/s, SAR 1:1 DAR 16:9, 30.30 fps, 30 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2016-02-25T14:09:56.000000Z
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
    Metadata:
      creation_time   : 2016-02-25T14:09:56.000000Z
      handler_name    : SoundHandle At least one output file must be specified

FFmpeg information for stabilized video:

$ ffmpeg -i videostab.mp4
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'videostab.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.1.0
  Duration: 00:03:49.03, start: 0.000000, bitrate: 2449 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 2446 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
At least one output file must be specified

Video Stabilization Output Length Change

I'm performing video stabilization using code from the videostab sample reduced down to simply perform one pass stabilization using OnePassStabilizer with a GaussianMotionFilter, and copy the source codec to the output writer. However, after copying the audio track from the original video to the stabilized video with FFmpeg I noticed that the audio wasn't correctly aligned. Further inspection revealed that the stabilized video (3:49.03) is slightly longer than the input video (3:47.05). The OpenCV code copies the source FPS to the output FPS, however, when comparing the frame rate in VLC the original video appears as 30.303030 while the stabilized video appears as 30.

Why is the stabilized video slightly longer than the original? Why is the stabilized video frame rate rounded down?

FFmpeg information for input video:

$ ffmpeg -i original.mp4 ... original.mp4
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'original.mp4':   Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: isom3gp4
    creation_time   : 2016-02-25T14:09:56.000000Z   Duration: 00:03:47.05, start:
0.000000, bitrate: 4593 kb/s
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, 4498 kb/s, SAR 1:1 DAR 16:9, 30.30 fps, 30 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2016-02-25T14:09:56.000000Z
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
    Metadata:
      creation_time   : 2016-02-25T14:09:56.000000Z
      handler_name    : SoundHandle At least one output file must be specified

FFmpeg information for stabilized video:

$ ffmpeg -i videostab.mp4
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'videostab.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.1.0
  Duration: 00:03:49.03, start: 0.000000, bitrate: 2449 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 2446 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
At least one output file must be specified

Video Stabilization Output Length Change

I'm performing video stabilization using code from the videostab sample reduced down to simply perform one pass stabilization using OnePassStabilizer with a GaussianMotionFilter, and copy the source codec to the output writer. However, after copying the audio track from the original video to the stabilized video with FFmpeg I noticed that the audio wasn't correctly aligned. Further inspection revealed that the stabilized video (3:49.03) is slightly longer than the input video (3:47.05). The OpenCV code copies the source FPS to the output FPS, however, when comparing the frame rate in VLC the original video appears as 30.303030 while the stabilized video appears as 30.

Why is the stabilized video slightly longer than the original? Why is the stabilized video frame rate rounded down?

FFmpeg information for input video:

$ ffmpeg -i original.mp4
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'original.mp4': 'original.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: isom3gp4
    creation_time   : 2016-02-25T14:09:56.000000Z   Duration: 00:03:47.05, start:
0.000000, bitrate: 4593 kb/s
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, 4498 kb/s, SAR 1:1 DAR 16:9, 30.30 fps, 30 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2016-02-25T14:09:56.000000Z
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
    Metadata:
      creation_time   : 2016-02-25T14:09:56.000000Z
      handler_name    : SoundHandle At least one output file must be specified

FFmpeg information for stabilized video:

$ ffmpeg -i videostab.mp4
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'videostab.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.1.0
  Duration: 00:03:49.03, start: 0.000000, bitrate: 2449 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 2446 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
At least one output file must be specified

Video Stabilization Output Length Change

I'm performing video stabilization in OpenCV 3.2.0 using code from the videostab sample reduced down to simply perform one pass stabilization using OnePassStabilizer with a GaussianMotionFilter, and GaussianMotionFilter. The code was also enhanced to copy the source codec to the output writer. However, after copying the audio track from the original video to the stabilized video with FFmpeg I noticed that the audio wasn't correctly aligned. Further inspection revealed that the stabilized video (3:49.03) is slightly longer than the input video (3:47.05). The OpenCV code copies the source FPS to the output FPS, however, when comparing the frame rate in VLC the original video appears as 30.303030 while the stabilized video appears as 30.

Why is the stabilized video slightly longer than the original? Why is the stabilized video frame rate rounded down?

FFmpeg information for input video:

$ ffmpeg -i original.mp4
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'original.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: isom3gp4
    creation_time   : 2016-02-25T14:09:56.000000Z   Duration: 00:03:47.05, start:
0.000000, bitrate: 4593 kb/s
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, 4498 kb/s, SAR 1:1 DAR 16:9, 30.30 fps, 30 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2016-02-25T14:09:56.000000Z
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
    Metadata:
      creation_time   : 2016-02-25T14:09:56.000000Z
      handler_name    : SoundHandle At least one output file must be specified

FFmpeg information for stabilized video:

$ ffmpeg -i videostab.mp4
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'videostab.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.1.0
  Duration: 00:03:49.03, start: 0.000000, bitrate: 2449 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 2446 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
At least one output file must be specified