Mailinglist Archive: opensuse (686 mails)

< Previous Next >
Re: [opensuse] bash: how to get file extension
Hello,

On Mon, 15 Jul 2013, lynn wrote:
Perfect. I want to get an mp3 from a movie. So here it is in all its
contextual glory:

#!/bin/bash
address=$1
echo YouTube $address
video_id=$(echo $1 | cut -d '=' -f2)
youtube-dl $1
echo Downoading: $video_id;
video_title="$(youtube-dl --get-title $address)"
if [ -z "$video_title" ]
then {
video_title="no title"
echo "cant get song title, using no title"
}
fi
full_name=$(ls "$video_title"*)

You might want to look at clive for this part.

ext="${full_name##*.}"
echo Found "$video_title": Converting to "$video_title.mp3"
echo Converting. . .
ffmpeg -i "/home/lynn/Desktop/$video_title"-"$video_id"."$ext"
"$video_title".wav
lame --scale 2 "$video_title".wav "$video_title".mp3

ffmpeg should be able to directly convert to mp3. Oh, and also, with
clive you can choose the qualitity, a lot of YT content is available
as VP8/webm or H264/webm with e.g. OGG Vorbis Audio that you probably
would want to extract without reencoding. E.g.:

ffmpeg -i "$video_title" -acodec copy -vn "${video_title}.${out_ext}"

for out_ext, you'd have to check the audio-codec/format e.g. with
mplayer (midentify) or mediainfo (e.g. mediainfo --Inform='Audio;%Format%')
and choose a suitable container for that Codec (WAV for RIFF, OGG for
Vorbis, etc...). Or you could just convert to mp3, i.e.

ffmpeg -i "$video_title" -vn "${video_title}.mp3"

That should use libmp3lame to encode to mp3, but you should adjust
bitrate settings, default seems to be 64kbit/s or so.

HTH,
-dnh

--
Those who use Word for technical write-ups should be shot. Those who
are forced to use it by mandate from $PHB should shoot the PHB.
-- Stuart Lamble in asr
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >