'ffmpeg Stream copy outputs wrong frame rate

When running the following command, out.mp4 has a framerate of 30.10, even though video.mp4's framerate is 30.00. One thing that I noticed is that the duration of out.mp4 should be 00:00:06.39, instead of 00:00:06.38. I also see that in the ffprobe output for out.mp4, the 'start' parameter is 0.020000 when it should (perhaps) be 0.000000, how can I resolve this? I think this discrepancy might be due to the fact that the frame I am cutting at is not a keyframe, but I am really not sure what is going on :\

ffmpeg -i video.mp4 -ss 22 -c copy out.mp4

ffprobe for video.mp4

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf59.20.100
  Duration: 00:00:28.39, start: 0.000000, bitrate: 2231 kb/s
  Stream #0:0[0x1](und): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 2100 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]

ffprobe for out.mp4

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf59.20.100
  Duration: 00:00:06.38, start: 0.020000, bitrate: 2307 kb/s
  Stream #0:0[0x1](und): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 2254 kb/s, 30.10 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]


Solution 1:[1]

I don't have a definitive answer, but if you want to adjust your start time to be on a keyframe, you can run the following ffprobe command to determine where the nearest keyframe is:

ffprobe -show_frames -show_entries frame=key_frame,pkt_pts_time -read_intervals 21%22 video.mp4

I've specified an interval between 21s and 22s as a starter but set it to your liking. If a frame is a keyframe, its key_frame entry is 1. Use that timestamp and see if the problem goes away.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kesh