The invention discloses an encryption method based on H.264 video streaming. During the H.264 coding, a frame of images is divided into m slices (m is more than or equal to 1), each slice contains n macro blocks (n is more than or equal to 1), each macro block is divided into 16 sub-blocks based on 4*4 as a basic unit: that is, Zm,n,0, Zm,n,1, Zm,n,15, and each sub-block contains 16 DCT coefficients, that is, Zm,n,i ={Cm,n,i, 0, Cm,n,i, 1, Cm,n,i,15} (m is more than or equal to 1, n is more than or equal to 1, i is more than or equal to 0 but less than or equal to 15); a DCT coefficient hierarchical model is established in correspondence to the macro block and then divided into a DC coefficient layer and other 15 AC coefficient layers; sequentially, each frame of image data is distributed with a key, that is, each layer is distributed with a key, if necessary, a plurality of layers share one key; each frame of image data is encrypted and the key sequence pointer resets to scramble layer after layer until the frame is completed. The invention has good safety and high compression ratio.