Answers.Body: <p>You need to use state e.g.</p>
  
  <pre><code>ffmpeg -i src.png
   -vf zoompan=d=300:z='if(gte(zoom,2)+eq(ld(1),1)*gt(zoom,1),zoom-0.04*st(1,1),zoom+0.04+0*st(1,0))'
  o.mp4
  </code></pre>
  
  <p>This expression zooms from <code>zoom=1</code> to <code>zoom=2</code> in steps of <code>0.04</code>. Remember, zoom is initialized to <code>1</code>. The above will create 6 loops.</p>
  
  <p>In <code>st</code>(store) and <code>ld</code>(load) functions, the first argument is variable id (0 to 9), and the second is the value.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-27T13:32:11.813Z
Answers.Text: good, it works, but I don't understand very well  what does it do! What if I'd like to start with zoom out and then zoom in? Thanks!
Answers.UserDisplayName: GFCoder977
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-28T09:21:32.353Z
Answers.Text: Actually, I use  pzoom for z evaluazion `min(pzoom+0.0015,1.5)`, and before zoompan I scale the image with `scale=iw*10:ih*10`. I'm trying to apply your formula, but it does not work. How should I change to use pzoom?
Answers.UserDisplayName: GFCoder977
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-28T11:24:22.673Z
Answers.Text: Sorry, it works well; I have updated my ffmpeg version with 3.4.2. Thanks!!!
Answers.UserDisplayName: GFCoder977
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-14T22:41:09.273Z
Answers.Text: @Gyan How can this effect be done in videos, with it zooming into the center?
Answers.UserDisplayName: pigeonburger
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-15T04:55:00.160Z
Answers.Text: `d=1` and use `pzoom` in place of `zoom`
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-23T21:30:09.573Z
Answers.Text: @pigeonburger check this you may adapt it for a video : https://superuser.com/questions/1087685/ffmpeg-zoompan-image-to-center-position
Answers.UserDisplayName: Dorian Grv
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-26T12:06:41.967Z
Answers.LastActivityDate: 2018-03-26T12:06:41.967Z
Answers.UserDisplayName: Gyan
Answers.Body: <p>Based on Gyan's answer, here are more details.</p>
  <p>The following creates a video from an image and an mp3 with an infinite zoom-in-out on the image:</p>
  <pre><code>ffmpeg -loop 1 -i img.png  -i adio.mp3 -vf &quot;[0:v]scale=7680x4320,zoompan=z='if(gte(zoom,1.5)+eq(ld(1),1)*gt(zoom,1),zoom-0.00005*st(1,1),zoom+0.00005+st(1,0))':d=20000&quot; -c:a copy -c:v libx264 -shortest out3.mp4
  </code></pre>
  <p><code>[0:v]scale=7680x4320</code> upscales 4 times the original 1920x1080 image for a smooth transition.</p>
  <p><code>d=20000</code> specifies the duration of the zoom-in-out. In this case, I perform a zoom from 1 to 1.5 with increments or decrements of 0.00005. That's (1.5-1) / 0.00005 steps for the zoom, which means I need two times this for the zoom + dezoom, which is 10'000*2 = 20'000.</p>
  <p><code>if(gte(zoom,1.5)+eq(ld(1),1)*gt(zoom,1),zoom-0.00005*st(1,1),zoom+0.00005+st(1,0))</code> can be translated to the following pseudo-code:</p>
  <pre><code>// '||' corresponds to a `+` and '&amp;&amp;' to a '*' 
  if zoom &gt;= 1.5 || (isDezooming &amp;&amp; zoom &gt; 1) {
    zoom-0.00005
    isDezooming = true // corresponds to '*st(1,1)'
  } else {
    zoom+0.00005
    isDezooming = false // corresponds to '+st(1,0)'
  }
  </code></pre>
  <p>where <code>isDezooming</code> corresponds to the variable <code>1</code> handled with the <code>ld(1)</code> and <code>st(1,0)</code> instructions. Here is the full <a href="https://ffmpeg.org/ffmpeg-utils.html#Expression-Evaluation" rel="nofollow noreferrer">list of instruction</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-21T20:52:27.357Z
Answers.LastActivityDate: 2020-09-21T20:52:27.357Z
Answers.UserDisplayName: Noémien Kocher
Body: <p>I'd like to apply a Zoompan effect but instead of zoom in or zoom out, I'd like to mix both of them: the zoom will start with zoom in, and, after some period of time, the zoom continue with zoom out, and so on, alternatively.</p>
  
  <p>While I'm thinking how to archieve this, has someone some tips?</p>
  
  <p>Thanks !</p>
  
Tags: <ffmpeg>
Title: ffmpeg - Zoompan IN and Out alternately
UserDisplayName: GFCoder977
ThreadText: # ffmpeg - Zoompan IN and Out alternately
  
  (Asked by: username_0 on 2018-03-26)
  
  I'd like to apply a Zoompan effect but instead of zoom in or zoom out, I'd like to mix both of them: the zoom will start with zoom in, and, after some period of time, the zoom continue with zoom out, and so on, alternatively.
  
  While I'm thinking how to archieve this, has someone some tips?
  
  Thanks !
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-03-26. Score: 4
  
  You need to use state e.g.
  
  ```
  ffmpeg -i src.png
   -vf zoompan=d=300:z='if(gte(zoom,2)+eq(ld(1),1)*gt(zoom,1),zoom-0.04*st(1,1),zoom+0.04+0*st(1,0))'
  o.mp4
  
  ```
  
  This expression zooms from `zoom=1` to `zoom=2` in steps of `0.04`. Remember, zoom is initialized to `1`. The above will create 6 loops.
  
  In `st`(store) and `ld`(load) functions, the first argument is variable id (0 to 9), and the second is the value.
  
  > **Comments:**
  > **username_0**: good, it works, but I don't understand very well  what does it do! What if I'd like to start with zoom out and then zoom in? Thanks!  
  > **username_0**: Actually, I use  pzoom for z evaluazion `min(pzoom+0.0015,1.5)`, and before zoompan I scale the image with `scale=iw*10:ih*10`. I'm trying to apply your formula, but it does not work. How should I change to use pzoom?  
  > **username_0**: Sorry, it works well; I have updated my ffmpeg version with 3.4.2. Thanks!!!  
  > **username_2**: @username_1 How can this effect be done in videos, with it zooming into the center?  
  > **username_1**: `d=1` and use `pzoom` in place of `zoom`  
  > **username_3**: @username_2 check this you may adapt it for a video : https://superuser.com/questions/1087685/ffmpeg-zoompan-image-to-center-position  
  
  ---
  
  ### Answer by username_4 on 2020-09-21. Score: 1
  
  Based on username_1's answer, here are more details.
  
  The following creates a video from an image and an mp3 with an infinite zoom-in-out on the image:
  
  ```
  ffmpeg -loop 1 -i img.png  -i adio.mp3 -vf "[0:v]scale=7680x4320,zoompan=z='if(gte(zoom,1.5)+eq(ld(1),1)*gt(zoom,1),zoom-0.00005*st(1,1),zoom+0.00005+st(1,0))':d=20000" -c:a copy -c:v libx264 -shortest out3.mp4
  
  ```
  
  `[0:v]scale=7680x4320` upscales 4 times the original 1920x1080 image for a smooth transition.
  
  `d=20000` specifies the duration of the zoom-in-out. In this case, I perform a zoom from 1 to 1.5 with increments or decrements of 0.00005. That's (1.5-1) / 0.00005 steps for the zoom, which means I need two times this for the zoom + dezoom, which is 10'000\*2 = 20'000.
  
  `if(gte(zoom,1.5)+eq(ld(1),1)*gt(zoom,1),zoom-0.00005*st(1,1),zoom+0.00005+st(1,0))` can be translated to the following pseudo-code:
  
  ```
  // '||' corresponds to a `+` and '&&' to a '*' 
  if zoom >= 1.5 || (isDezooming && zoom > 1) {
    zoom-0.00005
    isDezooming = true // corresponds to '*st(1,1)'
  } else {
    zoom+0.00005
    isDezooming = false // corresponds to '+st(1,0)'
  }
  
  ```
  
  where `isDezooming` corresponds to the variable `1` handled with the `ld(1)` and `st(1,0)` instructions. Here is the full [list of instruction](https://ffmpeg.org/ffmpeg-utils.html#Expression-Evaluation).
  
  
  ---
  
  