Encoding method, electronic device, communication system, storage medium, and program product
An encoding method includes that a first device determines an I-frame position of a first image stream and an I-frame position of a second image stream based on a first resolution, a second resolution, an I-frame time interval, and a frame rate; the first device encodes the first image stream based on the I-frame position of the first image stream to obtain a first compressed stream; the first device encodes the second image stream based on the I-frame position of the second image stream to obtain a second compressed stream; and the first device sends the first compressed stream and the second compressed stream to the second device.
1. A method, implemented by a first device, wherein the method comprises:
receiving, from a second device, a first instruction;
configuring a first resolution and a second resolution according to the first instruction;
controlling a first camera and a second camera of the first device to capture images;
processing first images captured by the first camera to obtain a first image stream, wherein the first image stream comprises the first resolution;
processing second images captured by the second camera to obtain a second image stream, wherein the second image stream comprises the second resolution;
encoding the first image stream based on a first I-frame position of the first image stream to obtain a first compressed stream;
encoding the second image stream based on a second I-frame position of the second image stream to obtain a second compressed stream, wherein the first I-frame position of the first image stream and the second I-frame position of the second image stream is based on the first resolution, the second resolution, an I-frame time interval, and a frame rate, wherein the I-frame time interval is based on a current network bandwidth, a first bandwidth threshold, and a second bandwidth threshold, and wherein the first bandwidth threshold is greater than the second bandwidth threshold;
using, by the first device and when the current network bandwidth is greater than or equal to the first bandwidth threshold, a first preset interval as the I-frame time interval;
identifying, by the first device and when the current network bandwidth is greater than the second bandwidth threshold and less than the first bandwidth threshold, the I-frame time interval based on the current network bandwidth, the first bandwidth threshold, the second bandwidth threshold, the first preset interval, and a second preset interval, wherein the second preset interval is greater than the first preset interval; and
sending the first compressed stream and the second compressed stream to the second device.
2. The method of claim 1 , wherein an I-frame position is a frame sequence number of an I-frame, and wherein the method further comprises:
using a first frame sequence number of a first frame of image in the first image stream as a second frame sequence number of a first I-frame in the first image stream;
using a third frame sequence number of a second frame of image in the second image stream as a fourth frame sequence number of a second I-frame in the second image stream; and
identifying a fifth frame sequence number of a first n th I-frame in the first image stream and a sixth frame sequence number of a second n th I-frame in the second image stream based on a first I-frame position weight of the first image stream, a second I-frame position weight of the second image stream, the I-frame time interval, and the frame rate, wherein n is greater than or equal to 2, and wherein the first I-frame position weight and the second I-frame position weight are based on the first resolution and the second resolution.
3. The method of claim 2 , further comprising:
identifying a seventh frame sequence number of a third I-frame in the first image stream;
identifying an eighth frame sequence number of a fourth I-frame in the second image stream based on the first I-frame position weight, the second I-frame position weight, the seventh frame sequence number, the I-frame time interval, and the frame rate;
identifying a ninth frame sequence number of a first m th I-frame in the first image stream based on the seventh frame sequence number, the I-frame time interval, and the frame rate, wherein m is greater than or equal to 3; and
identifying a tenth frame sequence number of a second m th I-frame in the second image stream based on the eighth frame sequence number, the I-frame time interval, and the frame rate, wherein m is greater than or equal to 3.
4. The method of claim 2 , wherein the first I-frame position weight is based on a formula
W
1
=
S
1
S
1
+
S
2
,
wherein W 1 is the first I-frame position weight, S 1 is the first resolution, and S 2 is the second resolution, wherein the second I-frame position weight is based on a formula
W
2
=
S
2
S
1
+
S
2
,
and wherein W 2 is the second I-frame position weight, S 1 is the first resolution, and S 2 is the second resolution.
5. The method of claim 3 , wherein the eighth frame sequence number is based on a formula P 2 =P 1 +(W 1 +W 2 )*INR*Fps/2, and wherein P 2 is the eighth frame sequence number, P 1 is the seventh frame sequence number, W 1 is the first I-frame position weight, W 2 is the second I-frame position weight, INR is the I-frame time interval, and Fps is the frame rate.
6. The method of claim 3 , wherein the ninth frame sequence number is based on a formula P m =P m-1 +INR*Fps, wherein P m is the ninth frame sequence number, P m-1 is a frame sequence number of an (m−1) th I-frame in the first image stream, INR is the I-frame time interval, and Fps is the frame rate, wherein the tenth frame sequence number is based on a formula P′ m =P′ m-1 +INR*Fps, and wherein P′ m is the tenth frame sequence number, P′ m-1 is an eleventh frame sequence number of an (m−1) th I-frame in the second image stream, INR is the I-frame time interval, and Fps is the frame rate.
7. The method of claim 1 , wherein the I-frame time interval is based on a formula INR=INR normal +(INR max −INR normal )*(BW−TH 2 )/(TH 1 −TH 2 ), and wherein INR is the I-frame time interval, INR normal is the first preset interval, INR max the second preset interval, BW is the current network bandwidth, TH 1 is the first bandwidth threshold, and TH 2 is the second bandwidth threshold.
8. The method of claim 1 , wherein an I-frame position is a timestamp of an I-frame, and wherein the method further comprises:
identifying a first frame sequence number of a first I-frame in the first image stream and a second frame sequence number of a second I-frame in the second image stream based on the first resolution, the second resolution, the I-frame time interval, and the frame rate;
identifying a first timestamp of the first I-frame based on the first frame sequence number, a second timestamp of a first frame of image in the first image stream, and the frame rate; and
identifying a third timestamp of the second I-frame based on the second frame sequence number, a fourth timestamp of the first frame of image in the second image stream, and the frame rate.
9. The method of claim 1 , wherein the method further comprises:
receiving a second instruction;
configuring a third resolution according to the second instruction;
controlling a third camera of the first device to capture images;
processing third images captured by the third camera to obtain a third image stream, wherein the third image stream comprises the third resolution; and
identifying a third I-frame position of the first image stream, a fourth I-frame position of the second image stream, and a fifth I-frame position of the third image stream based on the first resolution, the second resolution, the third resolution, the I-frame time interval, and the frame rate.
10. The method of claim 9 , wherein the identifying the third I-frame position, the fourth I-frame position, and the fifth I-frame position comprises:
updating frame sequence numbers of images captured by the first camera and the second camera to a first frame sequence number of a first frame of image when the third camera captures the first frame of image;
using the first frame sequence number in the first image stream as a second frame sequence number of a first I-frame in the first image stream;
using a third frame sequence number of the first frame of image in the second image stream as a fourth frame sequence number of a second I-frame in the second image stream; and
using a fifth frame sequence number as a sixth frame sequence number of a third I-frame in the third image stream;
identifying a first I-frame position weight of the first image stream, a second I-frame position weight of the second image stream, and a third I-frame position weight of the third image stream based on the first resolution, the second resolution, and the third resolution; and
identifying a seventh frame sequence number of a first n th I-frame in the first image stream, an eighth frame sequence number of a second n th I-frame in the second image stream, and a ninth frame sequence number of a third n th I-frame in the third image stream based on the first I-frame position weight, the second I-frame position weight, the third I-frame position weight, the I-frame time interval, and the frame rate, wherein n is greater than or equal to 2.
11. The method of claim 1 , wherein the method further comprises:
receiving, from the second device, a third instruction;
configuring a fourth resolution according to the third instruction;
processing fourth images captured by the first camera to obtain a fourth image stream, wherein the fourth image stream comprises the fourth resolution; and
identifying the second I-frame position and a third I-frame position of the fourth image stream based on the second resolution, the fourth resolution, the I-frame time interval, and the frame rate.
12. The method of claim 11 , wherein the identifying the second I-frame position and the third I-frame position comprises:
updating frame sequence numbers of images captured by the first camera and the second camera to a first frame sequence number of a first frame of image when the third instruction is received;
using the first frame sequence number of a second frame of image in the second image stream as a second frame sequence number of a first I-frame in the second image stream;
using a third frame sequence number of a third frame of image in the fourth image stream as a fourth frame sequence number of a second I-frame in the fourth image stream;
identifying a first I-frame position weight of the second image stream and a second I-frame position weight of the fourth image stream based on the second resolution and the fourth resolution; and
identifying a fifth frame sequence number of a first n th I-frame in the second image stream and a sixth frame sequence number of a second n th I-frame in the fourth image stream based on the first I-frame position weight, the second I-frame position weight, the I-frame time interval, and the frame rate, wherein n is greater than or equal to 2.
13. An encoding method, implemented by a communication system, wherein the method comprises:
separately sending, by a third device of the communication system, a first instruction to a first device and a second device of the communication system;
configuring, by the first device, a first resolution according to the first instruction by:
controlling the first device to capture first images; and
processing the first images captured by the first device to obtain a first image stream, wherein the first resolution is of the first image stream;
configuring, by the second device, a second resolution according to the first instruction by:
controlling the second device to capture second images; and
processing the second images captured by the second device to obtain a second image stream, wherein the second resolution is of the second image stream;
identifying, by the third device, a first I-frame position of the first image stream and a second I-frame position of the second image stream based on the first resolution, the second resolution, an I-frame time interval, and a frame rate, wherein an I-frame position is a frame sequence number of an I-frame, and wherein the identifying, by the third device, the first I-frame position and the second I-frame position comprises:
using, by the third device, a first frame sequence number of a first frame of image in the first image stream as a second frame sequence number of a first I-frame in the first image stream;
using, by the third device, a third frame sequence number of a second frame of image in the second image stream as a fourth frame sequence number of a second I-frame in the second image stream;
identifying, by the third device, a first I-frame position weight of the first image stream and a second I-frame position weight of the second image stream based on the first resolution and the second resolution; and
identifying, by the third device, a fifth frame sequence number of a first n th I-frame in the first image stream and a sixth frame sequence number of a second n th I-frame in the second image stream based on the first I-frame position weight, the second I-frame position weight, the I-frame time interval, and the frame rate, wherein n is greater than or equal to 2;
sending the first I-frame position to the first device;
sending the second I-frame position to the second device;
encoding, by the first device, the first image stream based on the first I-frame position to obtain a first compressed stream;
sending the first compressed stream to the third device;
encoding, by the second device, the second image stream based on the second I-frame position to obtain a second compressed stream; and
sending the second compressed stream to the third device.
14. The method of claim 13 , wherein the identifying the fifth frame sequence number and the sixth frame sequence number comprises:
identifying, by the third device, a seventh frame sequence number of a third I-frame in the first image stream;
identifying, by the third device, an eighth frame sequence number of a fourth I-frame in the second image stream based on the first I-frame position weight, the second I-frame position weight, the seventh frame sequence number, the I-frame time interval, and the frame rate;
identifying, by the third device, a ninth frame sequence number of a first m th I-frame in the first image stream based on the seventh frame sequence number, the I-frame time interval, and the frame rate, wherein m is greater than or equal to 3; and
identifying, by the third device, a tenth frame sequence number of a second m th I-frame in the second image stream based on the eighth frame sequence number, the I-frame time interval, and the frame rate, wherein m is greater than or equal to 3.
15. The method of claim 13 , wherein the identifying the first I-frame position weight and the second I-frame position weight comprises:
identifying, by the third device, the first I-frame position weight using a formula:
W
1
=
S
1
S
1
+
S
2
,
wherein W 1 is the first I-frame position weight, S 1 is the first resolution, and S 2 is the second resolution; and
identifying, by the third device, the second I-frame position weight using a formula:
W
2
=
S
2
S
1
+
S
2
,
wherein W 2 is the second I-frame position weight, S 1 is the first resolution and S 2 is the second resolution.
16. The method of claim 14 , wherein the identifying the eighth frame sequence number comprises identifying, by the third device, the eighth frame sequence number using a formula: P 2 =P 1 +(W 1 +W 2 )*INR*Fps/2, and wherein P 2 is the eighth frame sequence number, P 1 is the seventh frame sequence number, W 1 is the first I-frame position weight, W 2 is the second I-frame position weight, INR is the I-frame time interval, and Fps is the frame rate.
17. A first device comprising:
a first camera and a second camera configured to capture images; and
a processor coupled to the first camera and the second camera and configured to:
control the first camera and the second camera to capture the images; and
process first images captured by the first camera to obtain a first image stream, wherein the first image stream comprises a first resolution;
process second images captured by the second camera to obtain a second image stream, wherein the second image stream comprises a second resolution;
identify a first I-frame position of the first image stream and a second I-frame position of the second image stream based on the first resolution, the second resolution, an I-frame time interval, and a frame rate, wherein the I-frame time interval is based on a current network bandwidth, a first bandwidth threshold, and a second bandwidth threshold, and wherein the first bandwidth threshold is greater than the second bandwidth threshold;
use, when the current network bandwidth is greater than or equal to the first bandwidth threshold, a first preset interval as the I-frame time interval;
identify when the current network bandwidth is greater than the second bandwidth threshold and less than the first bandwidth threshold, the I-frame time interval based on the current network bandwidth, the first bandwidth threshold, the second bandwidth threshold, the first preset interval, and a second preset interval, wherein the second preset interval is greater than the first preset interval;
encode the first image stream based on the first I-frame position to obtain a first compressed stream;
encode the second image stream based on the second I-frame position to obtain a second compressed stream; and
send the first compressed stream and the second compressed stream to a second device.
18. The first device of claim 17 , wherein an I-frame position is a frame sequence number of an I-frame, and wherein the processor is further configured to:
use a first frame sequence number of a first frame of image in the first image stream as a second frame sequence number of a first I-frame in the first image stream;
use a third frame sequence number of a second frame of image in the second image stream as a fourth frame sequence number of a second I-frame in the second image stream; and
identify a fifth frame sequence number of a first n th I-frame in the first image stream and a sixth frame sequence number of a second n th I-frame in the second image stream based on a first I-frame position weight of the first image stream, a second I-frame position weight of the second image stream, the I-frame time interval, and the frame rate, wherein n is greater than or equal to 2, and wherein the first I-frame position weight and the second I-frame position weight are based on the first resolution and the second resolution.
19. The first device of claim 18 , wherein the processor is further configured to:
identify a seventh frame sequence number of a third I-frame in the first image stream;
identify an eighth frame sequence number of a fourth I-frame in the second image stream based on the first I-frame position weight, the second I-frame position weight, the seventh frame sequence number, the I-frame time interval, and the frame rate;
identify a ninth frame sequence number of a first m th I-frame in the first image stream based on the seventh frame sequence number, the I-frame time interval, and the frame rate, wherein m is greater than or equal to 3; and
identify a tenth frame sequence number of a second m th I-frame in the second image stream based on the eighth frame sequence number, the I-frame time interval, and the frame rate, wherein m is greater than or equal to 3.
20. The first device of claim 17 , wherein an I-frame position is a timestamp of an I-frame, and wherein the processor is further configured to:
identify a first frame sequence number of a first I-frame in the first image stream and a second frame sequence number of a second I-frame in the second image stream based on the first resolution, the second resolution, the I-frame time interval, and the frame rate;
identify a first timestamp of the first I-frame based on the first frame sequence number, a second timestamp of a first frame of image in the first image stream, and the frame rate; and
identify a third timestamp of the second I-frame based on the second frame sequence number, a fourth timestamp of the first frame of image in the second image stream, and the frame rate.