A packet processing method, applied to a network device comprising a processor and a target hardware engine, wherein the method comprises: generating, by the processor, a first encoding task based on M original packets in a to-be-processed first data stream, wherein M is a positive integer, and the first encoding task is used to indicate to encode the M original packets; and performing, by the target hardware engine, forward error correction, FEC, encoding on the M original packets based on the first encoding task to obtain R redundant packets, wherein R is a positive integer, wherein after the generating, by the processor, a first encoding task based on M original packets in a to-be-processed first data stream, the method further comprises: storing, by the processor, the first encoding task in a first target sending queue, wherein the first target sending queue is used to store encoding tasks of to-be-processed data streams of the network device, and the to-be-processed data streams of the network device comprise the first data stream; and reading, by the target hardware engine, the first encoding task from the first target sending queue, wherein the storing, by the processor, the first encoding task in a first target sending queue comprises: adding, by the processor, the first encoding task to the first target sending queue based on a priority of the first data stream, wherein a priority of the first target sending queue is equal to the priority of the first data stream. generating, by the processor, a first encoding task based on M original packets in a to-be-processed first data stream, wherein M is a positive integer, and the first encoding task is used to indicate to encode the M original packets; and performing, by the target hardware engine, forward error correction, FEC, encoding on the M original packets based on the first encoding task to obtain R redundant packets, wherein R is a positive integer, wherein after the generating, by the processor, a first encoding task based on M original packets in a to-be-processed first data stream, the method further comprises: storing, by the processor, the first encoding task in a first target sending queue, wherein the first target sending queue is used to store encoding tasks of to-be-processed data streams of the network device, and the to-be-processed data streams of the network device comprise the first data stream; and reading, by the target hardware engine, the first encoding task from the first target sending queue, wherein the storing, by the processor, the first encoding task in a first target sending queue comprises: adding, by the processor, the first encoding task to the first target sending queue based on a priority of the first data stream, wherein a priority of the first target sending queue is equal to the priority of the first data stream. storing, by the processor, the first encoding task in a first target sending queue, wherein the first target sending queue is used to store encoding tasks of to-be-processed data streams of the network device, and the to-be-processed data streams of the network device comprise the first data stream; and reading, by the target hardware engine, the first encoding task from the first target sending queue, wherein the storing, by the processor, the first encoding task in a first target sending queue comprises: adding, by the processor, the first encoding task to the first target sending queue based on a priority of the first data stream, wherein a priority of the first target sending queue is equal to the priority of the first data stream.