How to rotate a video 180 degrees?

19 ビュー (過去 30 日間)
Gulce Lale
Gulce Lale 2020 年 12 月 2 日
コメント済み: Stephan 2020 年 12 月 3 日
I have videos in .mp4 format and I need to rotate them vertically so that they will rotate 180 degrees.
I wrote the code and it rotates 180 degrees, however, it only takes one frame, so the video duration is 0 and the video is grayscale, which is a thing that I don't want since the video includes a red fixation point.
vidName = 'SID12.mp4';
vidPath = strcat(videosPathToBeEdited, vidName);
V= VideoReader(vidPath);
for k=1:video_duration*FrameRate
RGB= readFrame(V);
clear temp
image_rot = flipud( RGB );
rotated_vid = image_rot;
end
rotated_vid = rotated_vid(:,:,end:-1:1);
%calling save video function in another .m file
savemy_video(rotated_vid,[vidName(1:end-4), '_rev_rotated' video_duration_inname]);
Are there any easier and quicker ways to rotate a video? or if you could help me with this code would really appreciate it.

採用された回答

Stephan
Stephan 2020 年 12 月 3 日
vidName = 'xylophone.mp4';
vidPath = strcat(videosPathToBeEdited, vidName);
V = VideoReader(vidName);
% read the complete video and flip it without loop
RGB = read(V);
RGB_flip = flipud(RGB);
% save the new file
V_flip = VideoWriter('C:\YOUR_PATH_NAME_HERE\xylophone_flip','MPEG-4');
open(V_flip)
writeVideo(V_flip,RGB_flip)
close(V_flip)
% read the flipped video
V_flip = VideoReader('C:\YOUR_PATH_NAME_HERE\xylophone_flip.mp4');
% play the flipped video
while hasFrame(V_flip)
frame = readFrame(V_flip);
imshow(frame)
pause(1/V_flip.FrameRate);
end
  4 件のコメント
Gulce Lale
Gulce Lale 2020 年 12 月 3 日
Thank you! I solved the problem, and your solution also works!
Stephan
Stephan 2020 年 12 月 3 日
Did you notice that you can accept and/or vote for useful answers?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by