Firstly, I found it hard to get the audio from an .avi file but finally I used the -mmread- function from Micah Richert and manage to read both audio and video data. Now can't find a way to get the new data together to a new .avi file.Of course there is -mmwrite-, but because I change the format of the video and audio structs that -mmread- returns is difficult to use.
One way is to try and create the two structs required by -mmwrite- but since I encountered some problems this way I just want to ask if there is another way to "merge" separated video and audio data in an .avi file. The -avifile- function doesn't say anything about sound data, at least in Matlab R2009a which I use which is funny for an AudioVideoInterleaved creating function. Also found some posts about using Simulink but I don't think it can happen because I need matlab source code.
If anyone has any idea it, or encountered the same problem would help a lot.
Thanx and sorry for any language mistakes.
The functionality that you seek became available in 10a release of MATLAB under Video and Image
Processing Blockset. This functionality is available for MATLAB (not just Simulink):
http://www.mathworks.com/help/toolbox/vipblks/ref/video.multimediafilereaderclass.html
and
http://www.mathworks.com/help/toolbox/vipblks/ref/video.multimediafilewriterclass.html
Witek
Had some time to check the messages.
I did try the read and write but they give little control over the avi file.
The video.MultimediaFileReader class only reads an avi file in order to play it. There aren't much you can to do to alter the video file or get its frames for example.
And the video.MultimediaFileWriter class is useful for writing a file from the video.MultimediaFileReader class form.I couldn't see a way of creating an original avi file frame to frame using it.
If you know better I'll be happy to try i again.
The reader gives you a MATLAB matrix for every video frame. The writer takes a MATLAB matrix (frame) for
writing. Let's say that you called the reader and got a matrix called videoFrame. Now you can do:
videoFrame=videoFrame+0.2. You've just brightened your video. You can call any MATLAB operator on
videoFrame. Here is the example that we are talking about:
hvfr = video.MultimediaFileReader('viplanedeparture.avi');
hp = video.VideoPlayer;
while ~isDone(hvfr)
videoFrame = step(hvfr); % get next frame
videoFrame = videoFrame+0.2; % brighten the video; just an example
% do whatever else you like to videoFrame here before either displaying it or writing it
% to a file
step(hp, videoFrame); % display the video; you can replace it with the writer if you wish
end
release(hp); % free up the objects which were allocated at the top
release(hvfr);
Here is an example of video stabilization using the MultimediaFileReader:
So I'm really curious, what made you think that "class only reads an avi file in order to play it" ?
Witek
Thanks to lots of people wanting to rip audio from uploaded music
videos, there are lots of solutions:
http://www.bing.com/search?q=audio+from+video&form=QBLH&qs=AS&sk=AS2&pq=audio+from&sp=3&sc=8-10
> The reader gives you a MATLAB matrix for every video frame. The writer takes a MATLAB matrix (frame) for
> writing. Let's say that you called the reader and got a matrix called videoFrame. Now you can do:
> videoFrame=videoFrame+0.2. You've just brightened your video. You can call any MATLAB operator on
> videoFrame. Here is the example that we are talking about:
>
> hvfr = video.MultimediaFileReader('viplanedeparture.avi');
> hp = video.VideoPlayer;
> while ~isDone(hvfr)
> videoFrame = step(hvfr); % get next frame
> videoFrame = videoFrame+0.2; % brighten the video; just an example
>
> % do whatever else you like to videoFrame here before either displaying it or writing it
> % to a file
>
> step(hp, videoFrame); % display the video; you can replace it with the writer if you wish
> end
> release(hp); % free up the objects which were allocated at the top
> release(hvfr);
>
> Here is an example of video stabilization using the MultimediaFileReader:
>
> http://www.mathworks.com/products/viprocessing/demos.html?file=/products/demos/shipping/vipblks/videostabilize_pm.html
>
> So I'm really curious, what made you think that "class only reads an avi file in order to play it" ?
>
>
> Witek
I mean that I can't read frames [400:500] for example. I have to read all frames one by one which doesn't help me a lot and the struct doesn't contain information such as the number of frames, dimensions of the video or frame rate. Must admit though that if you need to read all frames successively is fine.
I encountered some problems with mmreader and mmread in video files tha contain pairs of identical frames when I read chunks of frames ( http://www.mathworks.com/matlabcentral/newsreader/view_thread/301374 ) so I finally used video.MultimediaFileReader for these videos combined with mmreader to get my initial information I want.
Thnx
Yes, ability to read a range of frames is very useful. The current workaround would be to grab
particular set of frames into a new (shorter file) and use it instead. We'll eventually eliminate this
limitation.
As far as getting the information about the video, it's available:
>> x = video.MultimediaFileReader('vipmen.avi');
>> x.info
ans =
Audio: 0
Video: 1
VideoFrameRate: 30.0000
VideoSize: [160 120]
VideoFormat: 'RGB '
>>
Witek
But I am getting error in step function and in writer fuction. Please help me out. I am new to matlab and i cannot resolve the error.
??? Error using ==> step
Reported by video.MultimediaFileWriter: Not enough input
arguments; expected 2 (in addition to the object handle), got
1.
Error in ==> videowriter at 6
step(hmfw,videoFrame);
I know it is tough but can u help me in how to do video steganography in MATLAB
??? Error using ==> step
Reported by video.MultimediaFileWriter: Not enough input
arguments; expected 2 (in addition to the object handle), got
1.
Error in ==> videowriter at 6
step(hmfw,videoFrame);
I know it is tough but can u help me in how to do video steganography in MATLAB. I am developing a project on it and I am in very need for a code regarding this.
"Govind Chowdhari" <govin...@gmail.com> wrote in message
news:ij0oro$aki$1...@fred.mathworks.com...
Look at the documentation for the STEP method:
http://www.mathworks.com/help/toolbox/vipblks/ref/video.multimediafilewriter.step.html
When you specify that the file has both audio and video, as you've done when
you constructed hmfw, you need to specify _both_ an audio input _and_ a
video input. You have not done so; you've just provided it the video.
"step(H,I,AUDIO) writes one frame of video, I, and one frame of audio
samples, AUDIO , to the output file when you set both the AudioInputPort and
VideoInputPort properties to true."
If you don't intend for your AVI file to have audio associated with it,
don't set the AudioInputPort property to true. If you do, specify the
appropriate audio in your STEP call.
> I know it is tough but can u help me in how to do video steganography in
> MATLAB
I'm guessing you're working on video steganography for a school project or
for work. In the former case, you should ask the professor for whom you're
doing the project for help; in the latter case, talk to your coworkers
and/or your boss. They would be better able to sit down with you and work
through whatever problems you're experiencing better than someone
potentially halfway around the world from you.
--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
Thanks a lot for your help. SO you mean I have a read audio from the video file and then supply the information in step() along with video frame. But how will I read audio from the avi file in the same code.
And about help from professors, It is different in India atleast where I study. SO it is better for me to trust on guys like you who is expert in MATLAB. Please do guide me on this audio issue,
Hi, I think Steve provided you a very clear answer. If you set both the 'VideoOutputPort' and 'AudioOutputPort' properties to true when you construct your video.MultimediaFileReader object, then when you call the step() method, you have the ability to get two output arguments. The documentation states:
[I,AUDIO] = step(H) outputs one frame of multidimensional video signal, I , and one frame of audio samples, AUDIO . This behavior requires an input file which contains audio and video data and that you set the AudioOutputPort and VideoOutputPort properties to true.
Now because you set the 'AudioInputPort' and 'VideoInputPort' properties to true in your video.MultimediaFileWriter object, when you invoke the step method of that object, it expects two input arguments (the audio and the video frame) in addition to the video.MultimediaFileWriter object handle.
That's why you get the error message:
Not enough input arguments; expected 2 (in addition to the object handle), got
1.
The relevant line from the step method help page is:
step(H,I,AUDIO) writes one frame of video, I, and one frame of audio samples, AUDIO , to the output file when you set both the AudioInputPort and VideoInputPort properties to true
Wayne
hmfr = video.MultimediaFileReader('D:\Wildlife.wmv','AudioOutputPort',true,'VideoOutputPort',true);
hmfw = video.MultimediaFileWriter('D:\123.wmv','AudioInputPort',true,'VideoInputPort',true);
while ~isDone(hmfr)
[v,a] = step(hmfr);
step(hmfw,v,a);
end
msgbox('Completed');
release(hmfw);
release(hmfr);
??? Undefined function or method 'release' for input arguments of
type 'video.MultimediaFileWriter'.
Error in ==> videowriter at 8
release(hmfw);
Hi Govind,
I assume you are using the R2010a version of MATLAB. In R2010a, use close() instead of release() .
Replace your lines:
release(hmfw);
release(hmfr);
with
close(hmfw);
close(hmfr);
Wayne
Thanks again Wayne. My problem is solved. But i found that the audio synchronization with frames is not much same as in original file. They audio glitches and frames are sometimes not smooth as in original one. Please suggest something on this
That's kind of hard for me to guess at without being able to play with the file. Can you try increasing the value of the SamplesPerAudioFrame property. It defaults to 1024. Try doubling it and see if that makes things better.
Wayne
Thanks Wayne. The problem is bit solved. The problem occurred when i was playing that file in windows media player. But when i played it in vlc it ran smoothly.
I want your help on encryption mechanisms. I want ti hide encrypted text behind images. So can u tell me if there is any encryption mechanisms in MATLAB as in java( built in functions) or I have to write the whole program in matlab
Everything is working fine for me now. But the only problem is that the video size that I am getting after saving the video is far much greater than the original one. My 7.92 MB file is now 977 MB. I found that the original file is compressed using xvid or 'Indeo5'. Please tell me how to reduce the file size
Hi, You should see that when you construct your video.MultimediaFileWriter System object (I recall you're using R2010a) that the VideoCompressor and AudioCompressor (available if the AudioInputPort property is true) properties are set to 'none'. This means the file you write is uncompressed.
You have the ability to specify those properties and write a compressed file.
% For example
hmfw = video.MultimediaFileWriter('test.avi','AudioInputPort',true,'VideoInputPort',true)
hmfw =
Description: 'Multimedia File Writer'
Filename: 'test.avi'
FileFormat: 'AVI'
AudioInputPort: true
VideoInputPort: true
AudioCompressor: 'None (uncompressed)'
VideoCompressor: 'None (uncompressed)'
SampleRate: 44100
FrameRate: 30
FileColorSpace: 'RGB'
Now, if you type the following at the command line (don't hit enter!)
hmfw.VideoCompressor = '
and hit the tab key (keep your cursor just on the other side of the single quote when you hit TAB), you will see the very nice autocomplete feature of MATLAB. You will see the options you have available for video compression.
Similarly with audio:
% type the following and hit the TAB key--do not hit enter
hmfw.AudioCompressor = '
You can select the audio and video compression algorithm you want among the supported types. If you know which algorithm you want, you can specify that in your System object constructor:
hmfw = video.MultimediaFileWriter('test.avi','AudioInputPort',true,...
'VideoInputPort',true,'AudioInputPort',true,'VideoInputPort',true,...
'AudioCompressor','PCM','VideoCompressor','MJPEG Compressor')
Wayne
Thanks Wayne. I understood the concept. I am able to use compression but the results are not good. I want to use xvid codec in matlab. I downloaded and installed xvid codec but it is not getting listed. Please help me out in this matter.