MATLAB Answers

How to change video format from AVI to MP4

220 ビュー (過去 30 日間)
Joni Afria
Joni Afria 2019 年 7 月 12 日
コメント済み: Walter Roberson 2020 年 6 月 4 日
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

  0 件のコメント

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

回答 (1 件)

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 件のコメント

Walter Roberson
Walter Roberson 2020 年 4 月 27 日
it is better to loop with hasFrame. Using duration times framerate does not count frames properly, for multiple reasons.
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.

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

Community Treasure Hunt

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

Start Hunting!

Translated by