<p>Y4M has no timestamps, only framerate in its header. So, if your source has any variability in its framerate, you'll see a shift in apparent timestamp in the Y4M.</p>

<p>e.g.</p>

<pre><code>n     src     y4m
0       0       0
1    0.04    0.04 
2    0.07    0.08
3    0.12    0.12
4    0.21    0.16
5    0.24    0.20
6    0.27    0.24 
...
</code></pre>

<p>Over a long period, these perturbations can add up. Here frame #6 in src is at TS of src #5 in Y4M.</p>

<p><strong>Edit</strong>: the sample TS file has VFR timestamps.</p>

<p>Use <code>-c:v rawvideo -vsync 0 -vf setpts=N/FRAME_RATE/TB -an</code> and save to <code>.nut</code>.</p>

CC BY-SA 4.0
2018-06-07T12:15:21.030Z
I have tested your solution and executed `ffmpeg -i input.ts -c:v rawvideo -vsync 0 -enc_time_base 1/1000 output.nut` but unfortunately I am losing one frame every ~1000 frames and this is pretty consistent loss. I have tried to add `-an`, remove the `-enc-time-base`  but it is always dropping a frame every ~1000 frames. As a matter of fact ffmpeg 3.2.4 works better in this regard and not dropping frames with the same input.
Georgi Stoyanov
CC BY-SA 4.0
2018-06-07T12:28:09.950Z
Share the full log of your command.
Gyan
CC BY-SA 4.0
2018-06-07T13:04:31.617Z
I have uploaded the test.log file using a link from wetransfer. It is rather bulky: 19Mb and my original video sequence has ~37000 frames. The link and the command could be seen in my original post, in the EDIT section.
Georgi Stoyanov
CC BY-SA 4.0
2018-06-09T04:07:39.853Z
Can you share the source file?
Gyan
CC BY-SA 4.0
2018-06-11T08:32:53.907Z
you can download it from [here](https://we.tl/QJbiMY1Ts0) @Gyan
Georgi Stoyanov
CC BY-SA 4.0
2018-06-11T09:39:31.633Z
Can you upload it elswhere? Wetransfer is very slow. Drive or Dropbox..etc
Gyan
CC BY-SA 4.0
2018-06-11T10:20:57.603Z
[Google Drive Link](https://goo.gl/2Lg4qD)
Georgi Stoyanov
CC BY-SA 4.0
2018-06-13T09:36:39.160Z
Can't reproduce. I ran `ffmpeg -i input.ts -vsync 0 output.y4m` and then `ffmpeg -ss xxx -i output.y4m -vframes 1 xxx.png` and `ffmpeg -ss xxx -i input.ts -vframes 1 xxx-ts.png` to compare. I get the same frame for 5-6 values that I tried. Can you identify a few `ss` values that show the problem?
Gyan
CC BY-SA 4.0
2018-06-13T09:53:50.130Z
If you are using: `ffmpeg -i test.ts -c:v rawvideo -vsync 0 -enc_time_base 1/1000 output.nut` I am getting roughly one frame drop every 1000 frames. You can try to extract the frames every 3000 frames (60 sec). I believe the whole duration is 5 minutes so you can use -ss 0 - to get the first frame in the sequence and then -ss 60, -ss 120, -ss 180, -ss 240, -ss 300. With `ffmpeg -i input.ts -vsync 0 output.y4m` I am getting more random drops, sometimes it is only one frame for the whole duration, sometimes more. Please note that actually the file is looping and there is a skipped frame:14998.
Georgi Stoyanov
CC BY-SA 4.0
2018-06-13T09:56:09.357Z
You can confirm easily by comparing the burned-in frame number of the extracted frames and you should have exactly 3000 frames difference between the exported frames in case you use -ss 0, -ss 60, etc.
Georgi Stoyanov
CC BY-SA 4.0
2018-06-13T13:06:24.900Z
See edited cmd.
Gyan
CC BY-SA 4.0
2018-06-13T13:33:28.123Z
Thanks @Gyan, I will check later on the updated command, but the variable frame rate doesn't explain why the `ffmpeg -i input.ts -vsync 0 output.y4m` command was sometimes skipping a frame or two or sometimes it was working perfectly fine. How did you also checked the file for VFR and CFR? Is there a command in ffprobe to check for it?
Georgi Stoyanov
CC BY-SA 4.0
2018-06-13T13:45:30.493Z
There's a filter recently added: **vfrdet**. For the sample, it shows `VFR:0.400005 (15185/22777) min: 1801 max: 3604)`. 40% of frames have non-standard duration. All should have 1800 units in this file.
Gyan
CC BY-SA 4.0
2018-06-13T14:49:00.370Z
You are absolutely right, @Gyan, I have tried your command and it works very well, I have also tried the `detvfr` filter and it showed me the deviation. I am wondering why the TS file has VFR, since I have recorded it with ffmpeg and I am pretty sure the input has CFR. Do I need to use `-re` in the recording command in this case in order to preserve the input frame rate(duration)? Can you also suggest a recording command not cutting the null padding (stuffing) from the TS?
Georgi Stoyanov
CC BY-SA 4.0
2018-06-13T15:29:16.083Z
TS is a VFR container, so in output you need to add `-vsync cfr` and also `-r` if that value is different than nominal input fps.
Gyan
CC BY-SA 4.0
2018-06-13T16:25:30.023Z
and what about the preserving the null padding at the output? By default ffmpeg is erasing all null PIDs which is creating PCR errors on the recorded stream, is it possible to preserve them?
Georgi Stoyanov
CC BY-SA 4.0
2018-06-14T05:02:17.913Z
Do you mean when creating the TS or when transferring to NUT?
Gyan
CC BY-SA 4.0
2018-06-14T06:59:25.850Z
When I am making the TS recording? Is there a way to tell ffmpeg not to trim the null padding?
Georgi Stoyanov
CC BY-SA 4.0
2018-06-14T08:12:03.957Z
Have you added -muxrate?
Gyan
CC BY-SA 4.0
2018-06-14T08:35:19.817Z
assuming that I am making a TS recording from Internet, do I need first to probe for the MUX rate and then configure it in the recording command? And if yes, how can I probe the mux rate with ffmpeg? And what if the input stream is not CBR but VBR with variable bitrate but still some null pad stuffing?
Georgi Stoyanov
CC BY-SA 4.0
2018-06-07T10:52:40.180Z
2018-06-13T13:06:09.957Z
2018-06-13T13:06:09.957Z
Gyan
<p>I have noticed today that when I use ffmpeg 4.0 stable to decode some TS files into y4m or ffv1 it occasionally skips some frames. My input file has all the frames burned into the picture and I am extracting some frames at regular intervals. Sometimes it works just fine without any skipped frames but sometimes it skips one or two frames. I am using the following command to decode my input:</p>

<pre><code>ffmpeg -i input.ts -vsync 0 output.y4m
</code></pre>

<p>and I am extracting the frames using: </p>

<pre><code>ffmpeg -ss xxx -i output.y4m -vframes 1 xxx.png
</code></pre>

<p>I am substituting xxx with 0, 100, 200, etc and sometimes I see 1-2-3 frame dropped which is very annoying since I am trying to evaluate the PSNR afterwards and this is messing up the whole PSNR/SSIM evaluation. </p>

<p>[EDIT] I have executed the command which @Gyan suggested:</p>

<pre><code>ffmpeg -v 99 -loglevel 99 -i test.ts \
-c:v rawvideo -vsync 0 \
-enc_time_base 1/1000 output.nut &amp;&gt; test.log
</code></pre>

<p>And here is the log file <a href="https://we.tl/ePLv1JdfrT" rel="nofollow noreferrer">test.log</a></p>

<video><ffmpeg><raw><decoding>
FFMPEG 4.0 skipping frames
Georgi Stoyanov
# FFMPEG 4.0 skipping frames

(Asked by: username_0 on 2018-06-07)

I have noticed today that when I use ffmpeg 4.0 stable to decode some TS files into y4m or ffv1 it occasionally skips some frames. My input file has all the frames burned into the picture and I am extracting some frames at regular intervals. Sometimes it works just fine without any skipped frames but sometimes it skips one or two frames. I am using the following command to decode my input:
ffmpeg -i input.ts -vsync 0 output.y4m

and I am extracting the frames using: 
ffmpeg -ss xxx -i output.y4m -vframes 1 xxx.png

I am substituting xxx with 0, 100, 200, etc and sometimes I see 1-2-3 frame dropped which is very annoying since I am trying to evaluate the PSNR afterwards and this is messing up the whole PSNR/SSIM evaluation. 
[EDIT] I have executed the command which @username_1 suggested:
ffmpeg -v 99 -loglevel 99 -i test.ts \
-c:v rawvideo -vsync 0 \
-enc_time_base 1/1000 output.nut &> test.log

And here is the log file test.log

**Tags:** video, ffmpeg, raw, decoding


---

## 1 answers

### Answer by username_1 on 2018-06-07. Score: 2 | Accepted answer

Y4M has no timestamps, only framerate in its header. So, if your source has any variability in its framerate, you'll see a shift in apparent timestamp in the Y4M.
e.g.
n     src     y4m
0       0       0
1    0.04    0.04 
2    0.07    0.08
3    0.12    0.12
4    0.21    0.16
5    0.24    0.20
6    0.27    0.24 
...

Over a long period, these perturbations can add up. Here frame #6 in src is at TS of src #5 in Y4M.
Edit: the sample TS file has VFR timestamps.
Use -c:v rawvideo -vsync 0 -vf setpts=N/FRAME_RATE/TB -an and save to .nut.

> **Comments:**
> **username_0**: I have tested your solution and executed `ffmpeg -i input.ts -c:v rawvideo -vsync 0 -enc_time_base 1/1000 output.nut` but unfortunately I am losing one frame every ~1000 frames and this is pretty consistent loss. I have tried to add `-an`, remove the `-enc-time-base`  but it is always dropping a frame every ~1000 frames. As a matter of fact ffmpeg 3.2.4 works better in this regard and not dropping frames with the same input.  
> **username_1**: Share the full log of your command.  
> **username_0**: I have uploaded the test.log file using a link from wetransfer. It is rather bulky: 19Mb and my original video sequence has ~37000 frames. The link and the command could be seen in my original post, in the EDIT section.  
> **username_1**: Can you share the source file?  
> **username_0**: you can download it from [here](https://we.tl/QJbiMY1Ts0) @username_1  
> **username_1**: Can you upload it elswhere? Wetransfer is very slow. Drive or Dropbox..etc  
> **username_0**: [Google Drive Link](https://goo.gl/2Lg4qD)  
> **username_1**: Can't reproduce. I ran `ffmpeg -i input.ts -vsync 0 output.y4m` and then `ffmpeg -ss xxx -i output.y4m -vframes 1 xxx.png` and `ffmpeg -ss xxx -i input.ts -vframes 1 xxx-ts.png` to compare. I get the same frame for 5-6 values that I tried. Can you identify a few `ss` values that show the problem?  
> **username_0**: If you are using: `ffmpeg -i test.ts -c:v rawvideo -vsync 0 -enc_time_base 1/1000 output.nut` I am getting roughly one frame drop every 1000 frames. You can try to extract the frames every 3000 frames (60 sec). I believe the whole duration is 5 minutes so you can use -ss 0 - to get the first frame in the sequence and then -ss 60, -ss 120, -ss 180, -ss 240, -ss 300. With `ffmpeg -i input.ts -vsync 0 output.y4m` I am getting more random drops, sometimes it is only one frame for the whole duration, sometimes more. Please note that actually the file is looping and there is a skipped frame:14998.  
> **username_0**: You can confirm easily by comparing the burned-in frame number of the extracted frames and you should have exactly 3000 frames difference between the exported frames in case you use -ss 0, -ss 60, etc.  
> **username_1**: See edited cmd.  
> **username_0**: Thanks @username_1, I will check later on the updated command, but the variable frame rate doesn't explain why the `ffmpeg -i input.ts -vsync 0 output.y4m` command was sometimes skipping a frame or two or sometimes it was working perfectly fine. How did you also checked the file for VFR and CFR? Is there a command in ffprobe to check for it?  
> **username_1**: There's a filter recently added: **vfrdet**. For the sample, it shows `VFR:0.400005 (15185/22777) min: 1801 max: 3604)`. 40% of frames have non-standard duration. All should have 1800 units in this file.  
> **username_0**: You are absolutely right, @username_1, I have tried your command and it works very well, I have also tried the `detvfr` filter and it showed me the deviation. I am wondering why the TS file has VFR, since I have recorded it with ffmpeg and I am pretty sure the input has CFR. Do I need to use `-re` in the recording command in this case in order to preserve the input frame rate(duration)? Can you also suggest a recording command not cutting the null padding (stuffing) from the TS?  
> **username_1**: TS is a VFR container, so in output you need to add `-vsync cfr` and also `-r` if that value is different than nominal input fps.  
> **username_0**: and what about the preserving the null padding at the output? By default ffmpeg is erasing all null PIDs which is creating PCR errors on the recorded stream, is it possible to preserve them?  
> **username_1**: Do you mean when creating the TS or when transferring to NUT?  
> **username_0**: When I am making the TS recording? Is there a way to tell ffmpeg not to trim the null padding?  
> **username_1**: Have you added -muxrate?  
> **username_0**: assuming that I am making a TS recording from Internet, do I need first to probe for the MUX rate and then configure it in the recording command? And if yes, how can I probe the mux rate with ffmpeg? And what if the input stream is not CBR but VBR with variable bitrate but still some null pad stuffing?  

---

