1
00:00:00,900 --> 00:00:04,830
In our previous lesson we were able to receive the data from the drone.

2
00:00:05,430 --> 00:00:10,470
We also set the system to pass the data to the FFL MPEG process.

3
00:00:10,560 --> 00:00:19,140
In this lesson we will be receiving the decoded data from the FFR MPEG Let's scroll down and start first

4
00:00:19,140 --> 00:00:23,190
defined video binary generator function.

5
00:00:23,190 --> 00:00:31,020
Let's create a generator using a while loop while True the loop will go on and receive the data set

6
00:00:31,020 --> 00:00:42,880
frame to self proc SD out read the frame size if there is an exception will log what is going on logger

7
00:00:42,880 --> 00:00:48,070
error with action video binary generator with the message E X

8
00:00:50,920 --> 00:00:54,430
even if there is an exception we continue the loop.

9
00:00:54,430 --> 00:00:58,430
Also if there is no frame we will still continue the loop.

10
00:00:58,600 --> 00:01:02,160
If a frame exists we won't receive the frame in 2D.

11
00:01:02,200 --> 00:01:14,130
But in 3D use num B from string And set frame and num be Unit 8 we reshape this using frame y and frame

12
00:01:14,190 --> 00:01:15,510
X into 3D.

13
00:01:16,740 --> 00:01:22,590
This code is for the F of MPEG process and how we pass the data onto the open CV.

14
00:01:22,710 --> 00:01:24,870
So you don't have to fully understand this code.

15
00:01:26,350 --> 00:01:34,240
We converted the frame into a data that the open CV can receive now said Hield and frame to return the

16
00:01:34,240 --> 00:01:38,040
frame data next.

17
00:01:38,050 --> 00:01:41,360
Let's go on and create a video JPEG generator.

18
00:01:41,410 --> 00:01:46,170
Here we want to process the frame in self video binary generator.

19
00:01:46,420 --> 00:01:50,480
Received this with a yield and convert this into JPEG.

20
00:01:50,680 --> 00:01:57,020
We can use CV image encode and add the j peg extension to process the frame.

21
00:01:57,040 --> 00:02:03,160
Next we need to set the J big file using two bytes so it can be compatible with the webcam

22
00:02:07,200 --> 00:02:11,340
let's set this as the JPEG binary return JPEG binary.

23
00:02:11,340 --> 00:02:16,670
Using yield now we've completed the part to show the image on the webcam.

24
00:02:16,710 --> 00:02:21,010
Let's go back quickly through the process again in our previous lesson.

25
00:02:21,030 --> 00:02:28,800
We created the part where we received the video data from the drone and process it with f f MPEG.

26
00:02:28,800 --> 00:02:35,130
Then we reshape the data and set to read it from ECD out once we read the data.

27
00:02:35,130 --> 00:02:39,720
We reshaped it so we can use it with open CV.

28
00:02:39,720 --> 00:02:42,870
Next we encode the image to JPEG.

29
00:02:42,870 --> 00:02:49,530
Lastly we set the J big into byte strings so it can be shown on the webcam.

30
00:02:49,540 --> 00:02:51,400
Now let's go to the server API

31
00:02:53,950 --> 00:02:57,440
scroll all the way to the top so we can import.

32
00:02:57,440 --> 00:03:05,050
Here I want you to import from flask response once you imported the response go back to the bottom of

33
00:03:05,050 --> 00:03:15,070
the script set a decorator to at Mark app route to video streaming defined video feed function and return

34
00:03:15,070 --> 00:03:17,910
the j pick binary string.

35
00:03:18,260 --> 00:03:22,270
Here we will be using the response method and this parenthesis.

36
00:03:22,280 --> 00:03:26,160
We want to set the eel binary string later on.

37
00:03:26,240 --> 00:03:27,650
For now let's set it to none.

38
00:03:28,580 --> 00:03:36,080
MIME type will be set to multipart slash X mixed replace boundary will be frame.

39
00:03:36,200 --> 00:03:46,010
Let's check what X mixed replays on weeki we will go to the mind page and search for C mixed replays.

40
00:03:46,030 --> 00:03:51,490
Here you can see that it will emulate server push and stream over HDTV.

41
00:03:52,300 --> 00:04:00,420
So by setting this mime we enabled the video to be streamed on HDTV earlier we set the first argument

42
00:04:00,480 --> 00:04:02,990
as none for the response.

43
00:04:03,000 --> 00:04:10,140
Now we need to define the video generator function to set the content type First we set drone to get

44
00:04:10,140 --> 00:04:12,890
drone for J.

45
00:04:12,890 --> 00:04:14,490
Big and drone video J.

46
00:04:14,500 --> 00:04:15,910
Big generator.

47
00:04:16,060 --> 00:04:22,420
Here we get the J big binary string to return we set yield with B

48
00:04:25,040 --> 00:04:31,310
double hyphen frame then set return carriage and new line in the next row.

49
00:04:31,310 --> 00:04:39,120
We set binary content type with image as J Peg again we need to set to go to the next row.

50
00:04:39,260 --> 00:04:45,640
Then we add the JP binary string and finish the row with return carriage and New Line.

51
00:04:45,660 --> 00:04:50,560
Now we've created the video generator so we can replace the none.

52
00:04:50,640 --> 00:04:53,880
Add a parentheses so we can run this function.

53
00:04:54,030 --> 00:05:00,660
The mime type will be set to stream on H TTP which will enable the image to stream on the front end

54
00:05:00,660 --> 00:05:01,410
side.

55
00:05:02,460 --> 00:05:05,370
Let's go back quickly through the codes.

56
00:05:05,370 --> 00:05:10,230
We use the response method and set the mime type to stream.

57
00:05:10,230 --> 00:05:12,000
The boundary is set to frame.

58
00:05:12,210 --> 00:05:16,200
So we used hyphen hyphen frame to get the data.

59
00:05:16,470 --> 00:05:23,590
Once the system gets a frame it determines the content type as image JPEG.

60
00:05:24,210 --> 00:05:30,540
Then in the next line we receive the binary string which will be followed with a new line.

61
00:05:30,540 --> 00:05:37,860
This will create an image that will be sent to the front end the for loop will go on and send the image

62
00:05:37,890 --> 00:05:40,750
which will be created with video to stream on the webcam.

63
00:05:41,880 --> 00:05:45,660
OK let's stop explaining and start running the system.

64
00:05:46,110 --> 00:05:47,340
Wait before we start.

65
00:05:47,340 --> 00:05:54,900
Go onto the controller HDMI I'll set a brake tag here and set the image source to video streaming which

66
00:05:54,900 --> 00:05:57,900
is the U R L we created earlier.

67
00:05:57,900 --> 00:06:00,360
Now let's run the script.

68
00:06:00,360 --> 00:06:01,590
You already know the routine.

69
00:06:01,800 --> 00:06:03,610
So go to the controller page.

70
00:06:03,960 --> 00:06:06,890
Let's hit takeoff once we hit the button.

71
00:06:06,900 --> 00:06:11,370
You can see that a video started on the bottom of the controller page.

72
00:06:11,370 --> 00:06:16,520
Once you start the video streaming press some buttons to move the drone around.

73
00:06:16,560 --> 00:06:22,050
If you set the server to public you can remotely control your drone from outside.

74
00:06:22,080 --> 00:06:25,910
You just made yourself a home security system.

75
00:06:26,070 --> 00:06:28,260
Let's hit land to finish our flight.
