動画をmp4で保存
Linuxでは対応していない模様…
table:table
profile の値 説明
'Archival' 可逆圧縮による Motion JPEG 2000 ファイル
'Motion JPEG AVI' (デフォルト)Motion JPEG エンコードを使用する AVI ファイル
'Motion JPEG 2000' Motion JPEG 2000 ファイル
'MPEG-4' H.264 エンコードを使用する MPEG-4 ファイル (Windows 7 以降または macOS 10.7 以降のシステム)
'Uncompressed AVI' RGB24 ビデオを使用した非圧縮 AVI ファイル
'Indexed AVI' インデックス付きビデオを使用した非圧縮 AVI ファイル
'Grayscale AVI' グレースケール ビデオを使用した非圧縮 AVI ファイル
ffmpegをinstallし、パスを通しておく必要がある
code:matlab
function mp4Path = avi2mp4(aviPath, deleteOriginal)
% Convert AVI to MP4 using ffmpeg
%
% Input:
% aviPath - string, path to the input AVI file
% deleteOriginal - boolean, whether to delete the original AVI file (default: false)
%
% Output:
% mp4Path - string, path to the output MP4 file
% Set default value for deleteOriginal if not provided
if nargin < 2
deleteOriginal = false;
end
% Generate output MP4 filename
mp4Path = regexprep(aviPath, '\.avi', '.mp4');
% Construct ffmpeg command based on the operating system
if isunix % for linux
cmd = sprintf('ffmpeg -i %s -y -movflags faststart -pix_fmt yuv420p -crf 9 -preset slow %s', aviPath, mp4Path);
elseif ispc % for windows
cmd = sprintf('ffmpeg.exe -i %s -y -movflags faststart -pix_fmt yuv420p -crf 9 -preset slow %s', aviPath, mp4Path);
else
error('Unsupported operating system');
end
% Execute ffmpeg command
% Check if the conversion was successful
if status ~= 0
error('FFmpeg conversion failed with error: %s', cmdout);
end
% Delete the original AVI file if requested
if deleteOriginal
delete(aviPath);
end
end