[FFmpeg-user] Problem of PTS for video segmentation

Guillaume Chanel Guillaume.Chanel at unige.ch
Fri Apr 12 17:09:03 CEST 2013

Dear FFMPEG users,

I am struggling with an issue using ffmpeg timestamps, especially -vsynch and -copyts. My goal is to cut a video according to a given time and number of frames (i.e. from time T up to F frames after) but keeping the same times stamps or at least the same non constant frame rate. This means that I would like to:
- cut my video;
- change the codec (since Camtasia cannot be encoded and codec copy does not work);
- keep the same time between the PTS of two given frames.

So far I am using the following FFMPEG command:
ffmpeg -y -i inputVideo.asf -ss 353.035 -vcodec mpeg4 -vframes 100 -vsync 0 -copyts -vf showinfo outputVideob.avi 2> videoinfo.txt

I tried without the -vsync and and -copyts which gave the same results. I also added the showinfo filter to try to understand the problem.

Here is a reduced output of the command:

ffmpeg version 0.10.6-6:0.10.6-0ubuntu0jon1~oneiric1 Copyright (c) 2000-2012 the FFmpeg developers
  built on Nov 12 2012 13:11:34 with gcc 4.6.1
  configuration: --arch=amd64 --enable-pthreads --enable-runtime-cpudetect --extra-version='6:0.10.6-0ubuntu0jon1~oneiric1' --libdir=/usr/lib/x86_64-linux-gnu --disable-stripping --prefix=/usr --enable-bzlib --enable-libdc1394 --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-libcdio --enable-x11grab --enable-libx264 --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
  libavutil      51. 35.100 / 51. 35.100
  libavcodec     53. 61.100 / 53. 61.100
  libavformat    53. 32.100 / 53. 32.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 61.100 /  2. 61.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0.  6.100 /  0.  6.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, asf, from '/user/mmi/emotion/data/EATMINT/ClientP02/TobiiExport/D02P02/ScreenRecordings_EATMI_Expe_D02P02_D02P02_2012-06-19_15-13-31.3831205_5725692445_8077573997.asf':
    WMFSDKVersion   : 12.0.7601.17514
    WMFSDKNeeded    :
    IsVBR           : 0
  Duration: 00:39:11.98, start: 0.000000, bitrate: 1581 kb/s
    Stream #0:0(fre): Video: camtasia (tscc / 0x63637374), bgra, 1280x1024, 1000000 kb/s, 59.67 tbr, 1k tbn, 1k tbc
Incompatible pixel format 'bgra' for codec 'mpeg4', auto-selecting format 'yuv420p'
[buffer @ 0xc9da80] w:1280 h:1024 pixfmt:bgra tb:1/1000000 sar:0/1 sws_param:
[showinfo @ 0xc9f3c0] auto-inserting filter 'auto-inserted scale 0' between the filter 'src' and the filter 'Parsed_showinfo_0'
[scale @ 0xca1580] w:1280 h:1024 fmt:bgra -> w:1280 h:1024 fmt:yuv420p flags:0x4
Output #0, avi, to '/home/chanel/D02P02_Screen_Collab.avi':
    WMFSDKVersion   : 12.0.7601.17514
    WMFSDKNeeded    :
    IsVBR           : 0
    ISFT            : Lavf53.32.100
    Stream #0:0(fre): Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 1280x1024, q=2-31, 200 kb/s, 59.67 tbn, 59.67 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (camtasia -> mpeg4)
Press [q] to stop, [?] for help

n:0 pts:353035000 pts_time:353.035000 pos:156948836 fmt:yuv420p sar:0/1 s:1280x1024 i:P iskey:1 type:? checksum:13764275 plane_checksum:[F47E3FFC 6811D07D 1EC431ED 00000000]
[showinfo @ 0xc9f3c0] n:1 pts:353161000 pts_time:353.161000 pos:156948836 fmt:yuv420p sar:0/1 s:1280x1024 i:P iskey:1 type:? checksum:0F8DFF59 plane_checksum:[484FE07F E077B316 DA056BB5 00000000]
[showinfo @ 0xc9f3c0] n:2 pts:353236000 pts_time:353.236000 pos:157052836 fmt:yuv420p sar:0/1 s:1280x1024 i:P iskey:1 type:? checksum:E83B38CB plane_checksum:[23802B1D AAA6C229 F0374B76 00000000]
[showinfo @ 0xc9f3c0] n:3 pts:353317000 pts_time:353.317000 pos:157068836 fmt:yuv420p sar:0/1 s:1280x1024 i:P iskey:1 type:? checksum:2C92157F plane_checksum:[5D2C0CB0 5CB2C00B BC8C48B5 00000000]
frame=  100 fps= 26 q=31.0 Lsize=     575kB time=00:00:09.88 bitrate= 476.2kbits/s    
video:555kB audio:0kB global headers:0kB muxing overhead 3.497475%

As you can be seen from the output the video is cutted at the correct PTS: 353.035 and records 100 frames as requested. So far so good.

Now I would like to see the output. For this I employ the ffprobe command:
ffprobe -show_frames outputVideob.avi | more

I will only list the values of the field pkt_pts_time for frame 0 to 3:
Frame 0 : 0.000000
Frame 1 : 0.134078
Frame 2 : 0.201117
Frame 3 : 0.284916

As you can see the PTS time difference between frames has changed. This could be seen by comparing the showinfo filter output from the ffprobe output:
Frame1 - Frame0 for the showinfo filter: 353.161000 − 353.035000 = 0.126
Frame1 - Frame0 for the ffprobe output: 0.134078 − 0.000000 = 0.134078

Is there a way to keep the same time difference as in the input ? Notice that the frame rate of my files are not constant I would not be satisfied with a constant frame rate. 

Also the absolute value are not the same despite of the -copyts. But this I do not care that much, I only need to keep the same non constant rate between frames from the input file to the output file.

What am I doing wrong ?

Thanks in advance for your help,

Guillaume Chanel

More information about the ffmpeg-user mailing list