In our previous lesson we were able to receive the data from the drone.
We also set the system to pass the data to the FFL MPEG process.
In this lesson we will be receiving the decoded data from the FFR MPEG Let's scroll down and start first
defined video binary generator function.
Let's create a generator using a while loop while True the loop will go on and receive the data set
frame to self proc SD out read the frame size if there is an exception will log what is going on logger
error with action video binary generator with the message E X
even if there is an exception we continue the loop.
Also if there is no frame we will still continue the loop.
If a frame exists we won't receive the frame in 2D.
But in 3D use num B from string And set frame and num be Unit 8 we reshape this using frame y and frame
X into 3D.
This code is for the F of MPEG process and how we pass the data onto the open CV.
So you don't have to fully understand this code.
We converted the frame into a data that the open CV can receive now said Hield and frame to return the
frame data next.
Let's go on and create a video JPEG generator.
Here we want to process the frame in self video binary generator.
Received this with a yield and convert this into JPEG.
We can use CV image encode and add the j peg extension to process the frame.
Next we need to set the J big file using two bytes so it can be compatible with the webcam
let's set this as the JPEG binary return JPEG binary.
Using yield now we've completed the part to show the image on the webcam.
Let's go back quickly through the process again in our previous lesson.
We created the part where we received the video data from the drone and process it with f f MPEG.
Then we reshape the data and set to read it from ECD out once we read the data.
We reshaped it so we can use it with open CV.
Next we encode the image to JPEG.
Lastly we set the J big into byte strings so it can be shown on the webcam.
Now let's go to the server API
scroll all the way to the top so we can import.
Here I want you to import from flask response once you imported the response go back to the bottom of
the script set a decorator to at Mark app route to video streaming defined video feed function and return
the j pick binary string.
Here we will be using the response method and this parenthesis.
We want to set the eel binary string later on.
For now let's set it to none.
MIME type will be set to multipart slash X mixed replace boundary will be frame.
Let's check what X mixed replays on weeki we will go to the mind page and search for C mixed replays.
Here you can see that it will emulate server push and stream over HDTV.
So by setting this mime we enabled the video to be streamed on HDTV earlier we set the first argument
as none for the response.
Now we need to define the video generator function to set the content type First we set drone to get
drone for J.
Big and drone video J.
Big generator.
Here we get the J big binary string to return we set yield with B
double hyphen frame then set return carriage and new line in the next row.
We set binary content type with image as J Peg again we need to set to go to the next row.
Then we add the JP binary string and finish the row with return carriage and New Line.
Now we've created the video generator so we can replace the none.
Add a parentheses so we can run this function.
The mime type will be set to stream on H TTP which will enable the image to stream on the front end
side.
Let's go back quickly through the codes.
We use the response method and set the mime type to stream.
The boundary is set to frame.
So we used hyphen hyphen frame to get the data.
Once the system gets a frame it determines the content type as image JPEG.
Then in the next line we receive the binary string which will be followed with a new line.
This will create an image that will be sent to the front end the for loop will go on and send the image
which will be created with video to stream on the webcam.
OK let's stop explaining and start running the system.
Wait before we start.
Go onto the controller HDMI I'll set a brake tag here and set the image source to video streaming which
is the U R L we created earlier.
Now let's run the script.
You already know the routine.
So go to the controller page.
Let's hit takeoff once we hit the button.
You can see that a video started on the bottom of the controller page.
Once you start the video streaming press some buttons to move the drone around.
If you set the server to public you can remotely control your drone from outside.
You just made yourself a home security system.
Let's hit land to finish our flight.