How to change video format from AVI to MP4

125 次查看(过去 30 天)
Hi.
I have a project about video compression (video processing).
How to change video format from AVI to MP4 or YUV to MP4?
Thank's

回答(3 个)

Yash Totla
Yash Totla 2019-7-12
Convert any video format to .mp4 video format. It does not support the MKV format.
% clc;
% clear all;
% close all;
% Browse Video File :
[ video_file_name,video_file_path ] = uigetfile({'*.mov'});
if(video_file_path==0)
return;
end
% Output path
output_image_path = fullfile(video_file_path,[video_file_name(1:strfind(video_file_name,'.')-1),'.mp4']);
% mkdir(output_image_path);
input_video_file = [video_file_path,video_file_name];
% Read Video
videoFReader = VideoReader(input_video_file);
% Write Video
videoFWrite = VideoWriter(output_image_path,'MPEG-4');
open(videoFWrite);
for count = 1:abs(videoFReader.Duration*videoFReader.FrameRate)
disp(count);
key_frame = read(videoFReader,count);
writeVideo(videoFWrite,key_frame);
end
% Release video object
close(videoFReader);
close(videoFWrite);
disp('COMPLETED');
  3 个评论
Rachel Hafner
Rachel Hafner 2020-6-4
Hi @Walter (or anyone who may be able to help me out with this question!),
I'm wondering how using hasFrame rather than the duration would change the code. Would you replace the videoFReader.FrameRate with hasFrame instead, and still multiply it by the duration? I'm a bit of a newbie to Matlab and coding in general, but I'd love a better explanation on why this is the case if possible.
Thank you!
Walter Roberson
Walter Roberson 2020-6-4
  • variable frame-rate video has a single nominal frame rate. The actual frame rate encoded in the file could be lower or higher depending how much change there is in the scene. No one frame rate in the header will be sufficient to be able to multiple the frame rate by duration to give an exact frame count
  • Depending on the encoder, NTSC frame rates are typically indicated in the header as either 30.0 fps or 29.97 frames per second, but neither of those are completely correct, and over long enough films the difference between the recorded frame rate and actual frame rate will add up
  • hardware decoders do not use double precision arithmetic: they use integer ratio approximations or at most they use single precision, so there will be different round-off in the counts and frame-rates, so numbers are not likely to exactly match what you get with double precision calculations.
The safe way is to loop over the frames.

请先登录,再进行评论。


Karan Mahe
Karan Mahe 2021-11-22
HI THere,
Would you know how I can convert from .mp4 to .AVI?
Thank you,
Karan

Image Analyst
Image Analyst 2021-11-22
See my attached demo.
Adapt the input and output formats as needed.
  2 个评论
Karan Mahe
Karan Mahe 2021-11-22
This is amazing. Thank you so much. I have actually been using this:
filename = '/Users/...../';
v = VideoReader(filename);
w = VideoWriter('.....');
open(w);
while hasFrame(v)
frame = readFrame(v);
writeVideo(w,frame);
end
close(w)
But for some reason, i am getting the following errors:
Error using VideoReader/initReader (line 734)
Could not open the file for reading. Permission denied.
Error in audiovideo.internal.IVideoReader (line 136)
initReader(obj, fileName, currentTime);
Error in VideoReader (line 104)
obj@audiovideo.internal.IVideoReader(varargin{:});
Error in ThrowMeInTrash (line 2)
v = VideoReader(filename);
I am very new to matlab and was wondering why I am getting these errors? Could it be because I updated my software to r2021b and I need to install some packages?
Thank you so much,
Karan
Image Analyst
Image Analyst 2021-11-22
What is filename? Do you have permission to write to that folder? The output file is also not already existing and open/playing is it?

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by