[FFmpeg-trac] #6905(undetermined:new): When copying video from .avi to .mp4, frames have incorrect pts values

FFmpeg trac at avcodec.org
Sun Dec 10 10:43:56 EET 2017

#6905: When copying video from .avi to .mp4, frames have incorrect pts values
             Reporter:  Misaki       |                     Type:  defect
               Status:  new          |                 Priority:  normal
            Component:               |                  Version:  git-
  undetermined                       |  master
             Keywords:               |               Blocked By:
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
 Step 1, generate a video with numbered frames:

 {{{ffmpeg -filter_complex
 -preset veryslow -refs 8 -aq-strength 0.5 -threads 1 -crf 20 -frames:v 30
 -movflags faststart ordered-frames.mp4}}}

 Step 2, convert it to avi:

 {{{ffmpeg -i ordered-frames.mp4 -c copy ordered-frames.avi}}}

 Step 3, convert back to mp4:

 {{{ffmpeg -i ordered-frames.avi -c copy -movflags faststart ordered-

 Examine the frames using ffprobe:

 {{{ffprobe -hide_banner -show_entries
 frame=pkt_pts_time,pkt_dts_time,pkt_size,coded_picture_number ordered-
 frames.mp4 -select_streams v | less}}}

 In another terminal tab, compare the new mp4:

 {{{ffprobe -hide_banner -show_entries
 frame=pkt_pts_time,pkt_dts_time,pkt_size,coded_picture_number ordered-
 frames-avicopy.mp4 -select_streams v | less}}}

 The pkt_dts_time values are just two more than the original file, but the
 pts values are now completely different. They are the packet dts values,
 which are different from the frame's pkt_dts values. This can be seen by
 looking at the packets and looking for similar sizes:

 {{{ffprobe -hide_banner -show_entries packet=pts_time,dts_time,size
 ordered-frames-avicopy.mp4 -select_streams v | less}}}

 Could also make arrays and by doing so sort everything by size so you
 wouldn't have to search to compare packets to frames, but it's easy to
 look for two or three packets.

 Most programs seem to effectively ignore the pts for a frame shown by
 ffprobe, because they pay attention to the dts for a frame, which is
 different from the packet dts but usually the same as the frame pts and
 the packet pts.

 So the 'bugged' mp4 files, copied from avi, appear to have a delay of a
 couple frames at most at the start, but then play normally with maybe a
 slight audio-video sync mismatch.

 But it appears that the Chrome browser and Chrome OS's video player do
 care about the pts values, because they read the frames earlier than the
 dts values. This results in stuttering output:

 They stutter the same way with the original avi file. This is probably
 unrelated to any ffmpeg libraries, but it does seem possible to make the
 copied mp4 files have better timestamps and so play correctly in Chrome.

Ticket URL: <https://trac.ffmpeg.org/ticket/6905>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker

More information about the FFmpeg-trac mailing list