bash - Check if a audio file is a valid as MP3 in shell -


i writing bash shell script needs determine if provided mp3 audio file valid or invalid. how accomplish in bash?

eg fake: > file.mp3 or mv file.txt file.mp3

it depends on how want be.

just check extension: can check extension of provided file in bash with:

if [ ${file: -4} == ".mp3" ] 

which takes last 4 characters of string file , asserts equals .mp3

check file headers: more assured, check small portion of actual file data. can checking mime-type of file using file function in bash. give you, well, mime-type.

however, these can spoofed, , not know if actual data in file valid. need deep inspection of binary data, and, likely, decode it. not can in simple bash script.

check file data its-self: use ffmpeg , ffprobe @ command line test files contents. think best bet ffprobe, give lot of data file. if still have questions, please attempt , add script question receive more help.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -