필터 지우기
필터 지우기

Write video in wide screen format

조회 수: 14 (최근 30일)
Seven Eden
Seven Eden 2019년 3월 20일
답변: Seven Eden 2019년 3월 23일
I'm creating a video using MATLAB's video writer function but the video always shows in a different visual format. I'm creating the video from frames of another (videoIn.mp4) with resolution of 720 x 576.
When I reproduce videoIn.mp4 in a video reproducer, it shows correctly. But when I reproduce the one generated by MATLAB, it shows "compressed" on the sides (not wide enough).
Does anyone know how to fix it?
This is my code:
myVideo = VideoWriter('videoOut.mp4','MPEG-4');
myVideo.FrameRate = 25;
myVideo.Quality = 100;
open(myVideo);
videoObject = VideoReader('videoIn.mp4');
framesToCopy = 1:50;
for nFrame = 1:length(framesToCopy)
mov(nFrame).cdata = readFrame(videoObject);
writeVideo(myVideo,mov(nFrame).cdata);
end
close(myVideo);
This is a screenshot of both videos open with VLC
video2.jpg
  댓글 수: 6
Guillaume
Guillaume 2019년 3월 20일
편집: Guillaume 2019년 3월 20일
It looks to me that VideoOut has got the correct aspect ratio for a 720x576 image. On the other hand, VideoIn looks like it is around twice as wide as tall, so does not match a 720x576 aspect ratio.
If you play the input video in matlab (with implay) what aspect ratio does it have?
Seven Eden
Seven Eden 2019년 3월 20일
It also looks constrained.
You are right, the original video doesn't seem to be display in a player with the actual aspect ratio the file has, my guess is that there is something in the file header that tells the player that it should play the video wider. But when I'm writing the new file I'm not putting this on it. The thing is that I don't know how to do it.

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2019년 3월 20일
Matlab assumes and always display the video with a pixel aspect ratio of 1:1.
My guess is that your original video specify a different aspect ratio, that VLC respects (hence it stretches the video horizontally). Unfortunaly, that property is not accessible within matlab. The MP4 format is sufficiently complex that extracting that information within matlab without the help of a library would be substantial work.
So, if you want to process that video in matlab, you'll be stuck with a final video with a 1:1 pixel aspect ratio. It must be noted that the video is not constrained. It's more that the original is artificially stretched from its actual 720 pixels width by VLC.
A quick search shows that a command line program mp4box would allow you to change the pixel aspect ratio (without recoding the video). See this page where it's discuss. Never having used it (or heard of it before today) I can't vouch for it.

추가 답변 (1개)

Seven Eden
Seven Eden 2019년 3월 23일
I ended up resizing the images before putting them inside the movie:
myVideo = VideoWriter('videoOut.mp4','MPEG-4');
myVideo.FrameRate = 25;
myVideo.Quality = 100;
vidHeight = 576; %this is the value in which it should reproduce
vidWidth = 1024; %this is the value in which it should reproduce
open(myVideo);
videoObject = VideoReader('videoIn.mp4');
framesToCopy = 1:50;
for nFrame = 1:length(framesToCopy)
I = readFrame(videoObject);
J = imresize(I,[vidHeight vidWidth]);
mov(nFrame).cdata = J;
writeVideo(myVideo,mov(nFrame).cdata);
end
close(myVideo);

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by