I understand the proof of this first formula.

I am confused about where he got the first E[min(X, k)] formula. It seems to have just come out of nowhere. And also, can someone explain why the two formulas are correct please?
On
Alternative proof:
$$\int_{0}^{\infty}[1-F_X(x)]dx$$
(by parts)
$$\int_{0}^{\infty}[1-F_X(x)]dx=[1-F_X(x)]x\Bigg|_{0}^{\infty}-\int_{0}^{\infty}-xf_X(x)dx=\int_{0}^{\infty}xf_X(x)dx=\mathbb{E}[X]$$
as the first addend is 0.
In fact:
$$x[1-F_X(x)]\Bigg|_{0}^{\infty}=0\cdot\infty$$
but
$$lim_{x \rightarrow +\infty}x[1-F_X(x)]=lim \frac{x}{\frac{1}{1-F}}\xrightarrow{H} lim\frac{1}{\frac{f}{(1-F)^2}}=lim\frac{(1-F_X(x))^2}{f_X(x)}=0$$
With similar arguments you can prove that, for a continuous rv, with $x \in \mathbb{R}$, you get
$$\mathbb{E}[X]=\int_{0}^{\infty}[1-F_X(x)]dx-\int_{-\infty}^{0}F_X(x)dx$$
$$\begin{align}\mathsf E(\min(X,k))&=\int_0^\infty \min(x,k)\,f(x)\,\mathrm d x\\[1ex]&=\int_0^\infty (x\mathbf 1_{x<k}+k\mathbf 1_{k\leqslant x})\,f(x)\,\mathrm d x\\[1ex]&=\int_0^k x~f(x)\,\mathrm d x + \int_k^\infty k~f(x)\mathrm d x\\[1ex]&=\int_0^k x~f(x)\,\mathrm d x + k \int_k^\infty f(x)\mathrm d x\\[1ex]&=\int_0^k x~f(x)\,\mathrm d x + k (1-F(k))\end{align}$$