<p>Use</p>

<pre><code>for %%a in ("*.avi") do (
    ffmpeg.exe -i "%%a" -vf "drawtext=fontfile=C\\:/Windows/Fonts/arial.ttf:timecode='00\:00\:00\:00':rate=5:text='Real \time\:':fontsize=46:fontcolor=white:x=30:y=30:box=1:boxcolor=0x00000000@1:boxborderw=5,setpts=0.25*PTS" -c:v libx264 -f avi "%%~na_with-time.avi"
)
</code></pre>

<p>Added <code>boxborderw=5</code> for border width.</p>

<p>Added setpts after the drawtext.</p>

<p>Added encoder explicitly <code>-c:v libx264</code> - its default settings should produce good images. You can also stick with the default encoder (mpeg4) and just add <code>-q:v 5</code> for decent quality - the default of 200 kbps is too low.</p>

<hr>

<p>For a custom timecode string, remove <code>timecode='00\:00\:00\:00':rate=5</code></p>

<p>and change <code>text</code> to </p>

<p><code>text='Real \time\: %{eif\:trunc(t/3600)\:d\:2}h %{eif\:trunc(mod(t/60\,60))\:d\:2}m %{eif\:trunc(mod(t\,60))\:d\:2}s'</code></p>

CC BY-SA 3.0
2018-04-03T16:57:53.940Z
Thank you!
Is there a way to replace the 
Real time:00:06:31:04 
with
Real time: 00h 06m 31s
(so there is a space after time:, no more : and frames (latests digits) are removed)?
m30l
CC BY-SA 3.0
2018-04-03T17:01:47.827Z
Also, is possible to center the timecode (horizontally) without checking how wide is the video (so I don't use 1920/2 = 960). Maybe something like 50% (similar to HTML/CSS 50%)?
m30l
CC BY-SA 3.0
2018-04-03T17:09:23.277Z
For horizontally centering, add `x='(W-tw)/2'`. A custom string can be done but it's a bit involved so I'll add it tomorrow.
Gyan
CC BY-SA 3.0
2018-04-03T17:48:10.633Z
Thanks! I've tested the code and there's an issue with the text size of the timecode, if the video is very big (2K/4K), the timecode is very small.
Is there a way to make the timecode 20% of the width of the video?
m30l
CC BY-SA 3.0
2018-04-03T18:06:55.213Z
Not directly. Add `fontsize=H/10` where H is video height. Test and see what expression results in the required footprint.
Gyan
CC BY-SA 3.0
2018-04-03T19:49:23.040Z
Thank you! Is there a way to fix this problem: Sometimes the rendered/converted video is longer than the actual time (so in this screenshot it says that it's 51 minutes long but actually it's 7:59 minutes, it can't got past 7:59 mins in this player): https://i.imgur.com/MozuyV4.png
m30l
CC BY-SA 3.0
2018-04-05T06:57:41.593Z
That sounds like a corrupt AVI. Can C4D save to a different format?
Gyan
CC BY-SA 3.0
2018-04-05T06:59:56.813Z
I'm not recording with/saving from Cinema 4D. I'm recording using Bandicam.
m30l
CC BY-SA 3.0
2018-04-03T16:28:30.817Z
2018-04-05T06:55:04.293Z
2018-04-05T06:55:04.293Z
Gyan
<p>I'm trying to create a .bat file for ffmpeg that:</p>

<ul>
<li>Applies a timecode overlay (e.g. 00:17:23:02)</li>
<li>Speeds up the video x4 (but AFTER the timecode is applied)</li>
<li>Doesn't "touch" the quality of the original video</li>
</ul>

<hr>

<p>This is what I got:</p>

<p><code>for %%a in ("*.avi") do (
    ffmpeg.exe -i "%%a" -vf "drawtext=fontfile=C\\:/Windows/Fonts/arial.ttf:timecode='00\:00\:00\:00':rate=5:text='Real \time\:':fontsize=46:fontcolor=white:x=30:y=30: box=1: boxcolor=0x00000000@1" -f avi "%%~na_with-time.avi"
)</code></p>

<hr>

<p>It works but I can't speed up x4 the video and it also losses a lot of the quality (very pixelated when moving around in the video)</p>

<p>This is what code I could use to speed up x4 the video but I can't get it in the code above (to work):
<code>"setpts=0.25*PTS"</code></p>

<p>Also this is the quality:</p>

<p>How the video looks before:
<img src="https://i.sstatic.net/VHFR4.png" alt=""></p>

<p>After conversion with the ffmpeg .bat code above:
<img src="https://i.sstatic.net/zmS6e.png" alt=""></p>

<p>Is there a way to speed-up the video x4 (but with the normal time timecode) and also don't change the quality of the exported video)? </p>

<p>Also is there a way to make the black box behind the timecode a bit bigger (5 pixels in all directions: left, up, right, down)? Or maybe a stroke effect to the text instead of the black box?</p>

<ffmpeg><video-quality><timecode>
How do I apply a timecode and then I speed up x4 a video with ffmpeg without losing quality?
m30l
# How do I apply a timecode and then I speed up x4 a video with ffmpeg without losing quality?

(Asked by: username_0 on 2018-04-03)

I'm trying to create a .bat file for ffmpeg that:

* Applies a timecode overlay (e.g. 00:17:23:02)
* Speeds up the video x4 (but AFTER the timecode is applied)
* Doesn't "touch" the quality of the original video

---

This is what I got:

`for %%a in ("*.avi") do (
ffmpeg.exe -i "%%a" -vf "drawtext=fontfile=C\\:/Windows/Fonts/arial.ttf:timecode='00\:00\:00\:00':rate=5:text='Real \time\:':fontsize=46:fontcolor=white:x=30:y=30: box=1: boxcolor=0x00000000@1" -f avi "%%~na_with-time.avi"
)`

---

It works but I can't speed up x4 the video and it also losses a lot of the quality (very pixelated when moving around in the video)

This is what code I could use to speed up x4 the video but I can't get it in the code above (to work):
`"setpts=0.25*PTS"`

Also this is the quality:

How the video looks before:
![](https://i.sstatic.net/VHFR4.png)

After conversion with the ffmpeg .bat code above:
![](https://i.sstatic.net/zmS6e.png)

Is there a way to speed-up the video x4 (but with the normal time timecode) and also don't change the quality of the exported video)?

Also is there a way to make the black box behind the timecode a bit bigger (5 pixels in all directions: left, up, right, down)? Or maybe a stroke effect to the text instead of the black box?

**Tags:** ffmpeg, video-quality, timecode


---

## 1 answers

### Answer by username_1 on 2018-04-03. Score: 0 | Accepted answer

Use
for %%a in ("*.avi") do (
    ffmpeg.exe -i "%%a" -vf "drawtext=fontfile=C\\:/Windows/Fonts/arial.ttf:timecode='00\:00\:00\:00':rate=5:text='Real \time\:':fontsize=46:fontcolor=white:x=30:y=30:box=1:boxcolor=0x00000000@1:boxborderw=5,setpts=0.25*PTS" -c:v libx264 -f avi "%%~na_with-time.avi"
)

Added boxborderw=5 for border width.
Added setpts after the drawtext.
Added encoder explicitly -c:v libx264 - its default settings should produce good images. You can also stick with the default encoder (mpeg4) and just add -q:v 5 for decent quality - the default of 200 kbps is too low.

For a custom timecode string, remove timecode='00\:00\:00\:00':rate=5
and change text to 
text='Real \time\: %{eif\:trunc(t/3600)\:d\:2}h %{eif\:trunc(mod(t/60\,60))\:d\:2}m %{eif\:trunc(mod(t\,60))\:d\:2}s'

> **Comments:**
> **username_0**: Thank you! Is there a way to replace the  Real time:00:06:31:04  with Real time: 00h 06m 31s (so there is a space after time:, no more : and frames (latests digits) are removed)?  
> **username_0**: Also, is possible to center the timecode (horizontally) without checking how wide is the video (so I don't use 1920/2 = 960). Maybe something like 50% (similar to HTML/CSS 50%)?  
> **username_1**: For horizontally centering, add `x='(W-tw)/2'`. A custom string can be done but it's a bit involved so I'll add it tomorrow.  
> **username_0**: Thanks! I've tested the code and there's an issue with the text size of the timecode, if the video is very big (2K/4K), the timecode is very small. Is there a way to make the timecode 20% of the width of the video?  
> **username_1**: Not directly. Add `fontsize=H/10` where H is video height. Test and see what expression results in the required footprint.  
> **username_0**: Thank you! Is there a way to fix this problem: Sometimes the rendered/converted video is longer than the actual time (so in this screenshot it says that it's 51 minutes long but actually it's 7:59 minutes, it can't got past 7:59 mins in this player): https://i.imgur.com/MozuyV4.png  
> **username_1**: That sounds like a corrupt AVI. Can C4D save to a different format?  
> **username_0**: I'm not recording with/saving from Cinema 4D. I'm recording using Bandicam.  

---

