Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have written a little bash script to extract audio from video files in batch mode.

Sound is extracted from each mp4 file to flac format using avconv (and the flac codec).

#!/bin/sh
#
# Batch conversion of audio extraction from video

FOLDER_SRC="/home/Me/Music/TestBatchConv"

for myvid in $(find ${FOLDER_SRC} | grep mp4)
do
avconv -i $myvid -acodec flac "${myvid}.flac"
done

exit 0

It works fine, but I would like to improve it.

The script only detects mp4 format. Is it possible to recognize a video file with a command (instead of testing each video format) ?

Thank you for advices.

share|improve this question
    
1] If you only had videos in a folder, would you then need to grep for mp4? 2] Why are you going for flac? Aren't those files huge? –  user25656 Mar 7 '13 at 15:58
    
1) yes you are right. in fact the script was not working because i have the TestBatchConv.sh~ file in it (not the script file itself). I can suppress this file but the question still remains :) and 2) sure ogg or mp3 would be more suitable. –  riimzzai Mar 7 '13 at 16:07
add comment

1 Answer 1

up vote 1 down vote accepted

You are looking for file

e.g.

 $ file -b 01--Frank_Sinatra--Close_to_You_And_More--Close_to_You.m4a 
 Audio file with ID3 version 2.4.0, contains: ISO Media, MPEG v4 system, iTunes AAC-LC

It should cover all well-known media types. If something is missing, you can add it yourself (see man magic).

share|improve this answer
    
thx for your answer, I tried file -b with several video files and it returns Macromedia Flash Video but also ISO Media, MPEG v4 system, version 2 for eg. So I can grep for Video or Media, and it would be suitable for my usage, but I am not 100% it contains all videos format :) –  riimzzai Mar 7 '13 at 16:36
    
@riimzzai see update in answer –  H.-Dirk Schmitt Mar 7 '13 at 16:42
    
okay thx (file -i works too but strangely recognize mkv as application) –  riimzzai Mar 7 '13 at 16:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.