若函数 $\int_{-\pi}^\pi\left(x-a_1 \cos x-b_1 \sin x\right)^2 \mathrm{~d} x$
$$
=\min _{a, b \in \mathrm{R}}\left\{\int_{-\pi}^\pi(x-a \cos x-b \sin x)^2 \mathrm{~d} x\right\} \text {, }
$$
则 $a_1 \cos x+b_1 \sin x=$
A. $2 \sin x$
B. $2 \cos x$
C. $2 \pi \sin x$
D. $2 \pi \cos x$