[FFmpeg-user] Zoompan filter, frame counts seem to start from 2 and 1, not 0 -- expected behaviour?

Jim DeLaHunt from.ffmpeg-user at jdlh.com
Sat Jun 2 11:03:04 EEST 2018


Hello, all:

I was doing some work with the *zoompan 
<https://ffmpeg.org/ffmpeg-filters.html#zoompan>* video filter for 
ffmpeg, attempting to zoom and pan across the frames of an input video 
to create an output video that looked like a camera operator was 
tracking the action. So I was using the *d*=1 option, and assigning the 
*x*, *y*, and *zoom* options to expressions which gave different values 
based on the frame count.

I see something very curious. While filters like *crop* and *drawtext* 
populate variable *n* with a frame number starting at 0 for the first 
frame of the input video, *zoompan* seems to populate variable *in* (the 
"input frame count") with a number starting at 2 for the first frame of 
the input video, and variable *on* (the "output frame count") with a 
number starting at 1 for the first frame of the output video.

See the command line invocation and the complete output below.  I use 
the *print()* expression to print "123400" followed by *n* from *crop*, 
and "271800" with *in,* and "314200" with *on*, from *zoompan*.

The results seem to be:

First frame of input video, and first frame of output video: crop:n 0, 
zoompan:in 2, zoompan:on 1
Second frame of input video, and first frame of output video: crop:n 1, 
zoompan:in 3, zoompan:on 2
Third frame of input video, and first frame of output video: crop:n 2, 
zoompan:in 4, zoompan:on 3
etc.

Is this the expected behaviour? Is there a rationale for the input frame 
count not to start with 0 (or 1)?  Is there a rationale for the output 
frame count not to equal the input frame count, when zoompan=d=1 sets up 
a 1:1 correspondence between input frame and output frame for the 
filter? Is there a rationale for input frame count in *zoompan* to 
differ from "the number of the input frame" in *crop*?

As I read the source, the values seem to get set up in 
libavfilter/vf_zoompan.c:277-278, which read:

         s->var_values[VAR_IN]    = inlink->frame_count_out + 1;
         s->var_values[VAR_ON]    = outlink->frame_count_in + 1;

As I read the history, this +1 increment has been present since the 
first draft of vf_zoompan.c at commit 
4b6cb1cc69010cd11b2370d81ef11fd454bc5d98 back in June of 2014.

Here is the output I get, testing *ffmpeg* built from the current *master*:

% ./ffmpeg -to 0.3 -i fate-suite/h264/interlaced_crop.mp4 -an -vf "crop=x=print(1234000+n)*0,zoompan=d=1:s=qhd:zoom=print(2718000+in)*0+print(3142000+on)*0+1" -f mp4 -y /dev/null
ffmpeg version N-91206-g9827bb88e7 Copyright (c) 2000-2018 the FFmpeg developers
   built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
   configuration: --samples=fate-suite
   libavutil      56. 18.102 / 56. 18.102
   libavcodec     58. 19.105 / 58. 19.105
   libavformat    58. 17.100 / 58. 17.100
   libavdevice    58.  4.100 / 58.  4.100
   libavfilter     7. 24.100 /  7. 24.100
   libswscale      5.  2.100 /  5.  2.100
   libswresample   3.  2.100 /  3.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'fate-suite/h264/interlaced_crop.mp4':
   Metadata:
     major_brand     : avc1
     minor_version   : 0
     compatible_brands: isomavc1
     creation_time   : 2010-10-07T15:03:51.000000Z
   Duration: 00:00:05.04, start: 0.000000, bitrate: 551 kb/s
     Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 547 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc (default)
     Metadata:
       creation_time   : 2010-10-07T15:03:51.000000Z
       handler_name    : GPAC ISO Video Handler
Stream mapping:
   Stream #0:0 -> #0:0 (h264 (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
1234000.000000
     Last message repeated 1 times
2718002.000000
3142001.000000
Output #0, mp4, to '/dev/null':
   Metadata:
     major_brand     : avc1
     minor_version   : 0
     compatible_brands: isomavc1
     encoder         : Lavf58.17.100
     Stream #0:0(und): Video: mpeg4 (mp4v / 0x7634706D), yuv420p, 960x540 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 12800 tbn, 25 tbc (default)
     Metadata:
       creation_time   : 2010-10-07T15:03:51.000000Z
       handler_name    : GPAC ISO Video Handler
       encoder         : Lavc58.19.105 mpeg4
     Side data:
       cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
1234001.000000
     Last message repeated 1 times
2718003.000000
3142002.000000
1234002.000000
     Last message repeated 1 times
2718004.000000
3142003.000000
1234003.000000
     Last message repeated 1 times
2718005.000000
3142004.000000
1234004.000000
     Last message repeated 1 times
2718006.000000
3142005.000000
1234005.000000
     Last message repeated 1 times
2718007.000000
3142006.000000
1234006.000000
     Last message repeated 1 times
2718008.000000
3142007.000000
1234007.000000
     Last message repeated 1 times
2718009.000000
3142008.000000
frame=    8 fps=0.0 q=12.1 Lsize=     107kB time=00:00:00.28 bitrate=3127.5kbits/s speed=7.95x
video:106kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.837148%

Thank you for any insight you can provide.

-- 
     --Jim DeLaHunt, jdlh at jdlh.com     http://blog.jdlh.com/ (http://jdlh.com/)
       multilingual websites consultant

       355-1027 Davie St, Vancouver BC V6E 4L2, Canada
          Canada mobile +1-604-376-8953



More information about the ffmpeg-user mailing list