之前用matlab单独读取视频或者音频,这次使用插件下载了视频,想提取其中的音频,不想下载其他软件,现记录所用方法。
matlab 版本
Introduced in R2012b
audioread 和 audiowrite
read支持格式
Platform Support File Format
All platforms AIFC (.aifc)
AIFF (.aiff, .aif)
AU (.au)
FLAC (.flac)
OGG (.ogg)
OPUS (.opus)
WAVE (.wav)
Windows® 7 (or later), Macintosh, and Linux® MP3 (.mp3)
MPEG-4 AAC (.m4a, .mp4)
write支持格式
audiowrite supports the following file formats.
Platform Support File Format
All platforms FLAC (.flac)
OGG (.ogg)
OPUS (.opus)
WAVE (.wav)
Windows® and Mac MPEG-4 AAC (.m4a, .mp4)
demo
%% 读取
filepath = 'C:\Users\t\Downloads\[白叔]_少年行(《天宝伏妖录》插曲)\[白叔]_少年行(《天宝伏妖录》插曲).mp4';
[y,Fs] = audioread(filepath );
whos y
%% 保存 wav
filename = 'test.wav';
audiowrite(filename,y,Fs);
%% 播放
sound(y,Fs);
%%
不支持写入mp3
reference
- https://ww2.mathworks.cn/help/matlab/ref/audioread.html
- https://www.mathworks.com/matlabcentral/answers/667348-how-to-extract-audio-from-mp4-video-file-with-matlab