4. The equation $8 x\left(2 x^{2}-1\right)\left(8 x^{4}-8 x^{2}+1\right)=1$ has ( ) real roots.
(A) 1
(B) 3
(C) 5
(D) 7
4.D.

If $|x| \geqslant 1$, then $2 x^{2}-1 \geqslant 1, 8 x^{4}-8 x^{2}+1 \geqslant 1$.
Therefore, $\left|8 x\left(2 x^{2}-1\right)\left(8 x^{4}-2 x^{2}+1\right)\right| \geqslant 8$.
Hence $|x|<1$.
Let $x=\cos \theta, \theta \in(0, \pi)$.
Then $8 \cos \theta\left(2 \cos ^{2} \theta-1\right)\left(8 \cos ^{4} \theta-8 \cos ^{2} \theta+1\right)=1$.
Simplifying, we get $8 \cos \theta \cdot \cos 2 \theta \cdot \cos 4 \theta=1$.
Thus, $\sin 8 \theta=\sin \theta(\theta \neq k \pi, k \in \mathbf{Z})$.
Therefore, $8 \theta=2 n \pi+\theta$ or $8 \theta=2 n \pi+\pi-\theta(n \in \mathbf{Z})$, i.e., $\theta=\frac{2 n \pi}{7}$ or $\theta=\frac{(2 n+1) \pi}{9}(n \in \mathbf{Z})$.
Hence, the roots of the equation are $\cos \frac{2 \pi}{7}, \cos \frac{4 \pi}{7}, \cos \frac{6 \pi}{7}, \cos \frac{\pi}{9}, \cos \frac{3 \pi}{9}, \cos \frac{5 \pi}{9}, \cos \frac{7 \pi}{9}$.