Ultra low latency transmission, high bandwidth and ubiquitous access points have greatly alleviated the "last mile" problem of streaming media live service. However, the complex compression coding of high‐resolution video is still inevitable before transmission. We combine the YOLOv5 target detection algorithm with the video encoder, segment the foreground and background of the video to be encoded with the help of the improved YOLOv5, and then encode the foreground and background respectively. The foreground area of the video uses the normal motion search to find the motion vector, and the background area uses the global motion parameters to describe its overall motion. This scheme can get the target detection results and encode the video at the same time. The experimental results show that the proposed scheme greatly reduces the complexity of the encoder with less loss of video quality, up to 82%. At the same time, the target detection task is completed.