how to write a MP4 video using vision toolbox ?

2 Ansichten (letzte 30 Tage)
Liran
Liran am 23 Jul. 2014
Kommentiert: Dinesh Iyer am 28 Jul. 2014
hello , I have been trying to use
vision.VideoFileWriter('output.mp4','FileFormat', '???' ); but the help cant really tell me the strings for format types.
tnx to Dima for the help so far.
i still have a problem ( still trying to output a MP4 to a file) i get a "On Windows, frame must be between 64 by 64 and 1920 by 1088 when writing MPEG4 files." error when my frame to write is 1920X1080
my code :
hVideoSrc_Color = vision.VideoFileReader('swipeCut.mp4'); hReffVideoOut = vision.VideoFileWriter('diff.mp4','FrameRate',hVideoSrc_Color.info.VideoFrameRate,'FileFormat','MPEG4'); counter=0; while ~isDone(hVideoSrc_Color) frame=step(hVideoSrc_Color); step(hReffVideoOut,frame); counter=counter+1; end
release(hVideoSrc_gray); release(hReffVideoOut);

Akzeptierte Antwort

Dinesh Iyer
Dinesh Iyer am 24 Jul. 2014
Bearbeitet: Dinesh Iyer am 24 Jul. 2014
Lirian,
I see the confusion. It is common to refer to image dimensions in terms of Width x Height. So a full HD video is said to have dimensions 1920x1080. But an array storing that frame has 1080 rows and 1920 columns.
However, the variable "frame" that you have contains 1920 rows and 1080 columns. If you look at the example code I posted earlier, the data array was 1080x1920.
I am surprised that step( vision.VideoFileReader('swipeCut.mp4') ) returns 1920x1080x3 frames. I tried reading HD video from an MP4 file at my end and it returned a 1080x1920x3 matrix.
Hope this helps. Try to transpose "frame" and write it. I agree that the error message issued is confusing.
Dinesh
  2 Kommentare
Liran
Liran am 27 Jul. 2014
thank you , the video was taken from a screen recording of a mobile phone and thats why the dimentions are transposed.
does this mean i cant output any change i made to the original video to a MP4 file ?
Dinesh Iyer
Dinesh Iyer am 28 Jul. 2014
Hi Lirian, You can try to write the transpose of the frame to an MP4 file.
if true
vfw = vision.VideoFileWriter('Filename', 'myfile.mp4', 'FileFormat', 'MPEG-4');
vfr = vision.VideoFileReader('swipeCut.mp4');
while ~isDone(vfr)
frame = step(vfr);
step(vfw, frame');
end
release(vfr);
release(vfw);
end
Hope this helps.
Dinesh

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Dima Lisin
Dima Lisin am 23 Jul. 2014
Bearbeitet: Dima Lisin am 23 Jul. 2014
If you do
>> help vision.VideoFileWriter
and then click on FileFormat you should see this:
FileFormat Format of created file
Specify the format of the video file.
On Windows (R) platforms, this may be one of:
[{'AVI'} | 'WMV' | 'MJ2000' | 'MPEG4'].
On Linux (R) platforms, this may be one of:
[{'AVI'} | 'MJ2000'].
On Mac OS X (R) platforms, this may be one of:
[{'AVI'} | 'MJ2000' | 'MPEG4']
These abbreviations
correspond to the following file formats:
WMV: Windows Media Video
AVI: Audio-Video Interleave
MJ2000: Motion JPEG 2000
MPEG4: MPEG-4/H.264 Video
  1 Kommentar
Liran
Liran am 23 Jul. 2014
thanks , for some reason it's not written in the F1 help . I also have a follow-up question ( i edited my original post)

Melden Sie sich an, um zu kommentieren.


Dinesh Iyer
Dinesh Iyer am 23 Jul. 2014
Liran, I tried the following code to write one frame of HD video on Windows 7 using R2014a:
if true
data = single(rand(1080, 1920, 3));
vfw = vision.VideoFileWriter('Filename', 'hdoutput.mp4', 'FileFormat', 'MPEG4')
step(vfw, data);
end
and it worked fine without any errors. Can you verify the dimensions of the video in swipeCut.mp4?

Community Treasure Hunt

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

Start Hunting!

Translated by