playback and recording at the same time

Hi there,
I need assistance playingback and recording simultaneously without actually preserving the stream as a recording on the disk. I am looking for playback from a remote machine, which is a target device, and screen capture playback streaming data is analysed in the backend system, where I pick up the video stream, convert to a frame, and histogram the defect sequence if I discover a defect.
Could you please provide me with a sample code and an idea? How can I complete such a task?
Thank you very much.

 Respuesta aceptada

Vishnu
Vishnu el 12 de Jul. de 2023
You can utilize the VideoReader, implay and VideoWriter functions of MATLAB.
Here is some sample code on how to use these functions:
videoReader = VideoReader('path/to/video/file.mp4');
videoPlayer = implay('path/to/video/file.mp4');
videoWriter = VideoWriter('path/to/save/output.mp4', 'MPEG-4');
Setting equal framerates for VideoWriter instance and implay instance.
videoWriter.FrameRate = videoReader.FrameRate;
open(videoWriter);
Then run a while loop over the video which is to be read using the implay instance and use the writeVideo function to write the file data into the VideoWriter instance.
while hasFrame(videoReader)
% Read the frame
frame = readFrame(videoReader);
% Perform some operations on the read frame
% Write the frame to the video writer
writeVideo(videoWriter, frame);
end
Close the instances you opened using the functions in the first step.
close(videoReader);
close(videoPlayer);
close(videoWriter);
You can check out the MATLAB documentation for these functions to have a better idea about the operations which you could perform on the video you read and the file you write in.

3 comentarios

Life is Wonderful
Life is Wonderful el 12 de Jul. de 2023
The VideoReader function is looking for a file.mp4. I'm not suggesting to have mp4 recording, but rather a live stream video playback capture that I'm expected to analyse. In this scenario, I convert a live video into a frame and then utilise while loop code.Is it reasonable to make a code adjustable, and is my understanding correct?
Vishnu
Vishnu el 13 de Jul. de 2023
Editada: Vishnu el 13 de Jul. de 2023
I believe your approach is correct, I have a code snipped which can help.
function startRec
disp('recording')
Recorder = VideoWriter('result.mp4','MPEG-4');
open(Recorder);
videoObj = VideoReader('xylophone.mp4');
frame = read(videoObj,1);
RecTimer = timer("ExecutionMode", "fixedDelay", 'Period', 1/10, 'TimerFcn', @(~,~)writeVideo(Recorder,frame));
start(RecTimer);
pause(10);
disp('stopped')
stop(RecTimer);
pause(0.5);
delete(RecTimer);
close(Recorder);
delete(Recorder);
end
In this function i am reading an example video and then writing one of its frame. you can modify the timer callback function to read the latest frame of you live video and then write it to a file. here the timer function works like a while loop calling the callback after a certain time.
Hope this helps,Thank You.
Life is Wonderful
Life is Wonderful el 14 de Jul. de 2023
Thank you!! Your suggestion looks good to me.I make the implementation out of your suggestion.
In case I need your support , I will come back here.
Thanks a lot

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2022b

Preguntada:

el 12 de Jul. de 2023

Comentada:

el 14 de Jul. de 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by