Merge branch 'video'

* video:
  decode video files (ffmpeg)
  move code to decodeFile()
  Read tags from video files
This commit is contained in:
Vincent Riquer 2013-04-29 23:35:48 +02:00
commit 83997bcc57
5 changed files with 160 additions and 96 deletions

70
atom
View File

@ -420,75 +420,7 @@ do
rest=${rest#*|}
performer=${rest%%|*}
unset rest
case "$mimetype" in
'audio/mpeg')
if [[ ${destinationformat[$destination]} = mp3 ]] \
&& checkCopy
then
copied=1
else
decodeSox
fi
;;
'application/ogg opus')
if [[ ${destinationformat[$destination]} = opus ]] \
&& checkCopy
then
copied=1
else
decodeOpusdec
if (( ${destinationnormalize["$destination"]}))\
|| (
[ -n "${destinationfrequency["$destination"]}" ]\
&& (( ${rate:-0} != ${destinationfrequency["$destination"]}))\
) || (
[ -n "${destinationchannels["$destination"]}" ]\
&& (( ${channels:-0} != ${destinationchannels["$destination"]} ))
)
then
sox_needed=1
fi
fi
;;
'application/ogg'*)
if [[ ${destinationformat[$destination]} = vorbis ]] \
&& checkCopy
then
copied=1
else
decodeSox
fi
;;
'audio/x-flac')
decodeSox
;;
*)
extendedtype=$(file -b "$sourcepath/$filename")
case "$extendedtype" in
*'Musepack '*)
decodeMpcdec
if (( ${destinationnormalize["$destination"]}))\
|| (
[ -n "${destinationfrequency["$destination"]}" ]\
&& (( ${rate:-0} != ${destinationfrequency["$destination"]}))\
) || (
[ -n "${destinationchannels["$destination"]}" ]\
&& (( ${channels:-0} != ${destinationchannels["$destination"]} ))
)
then
sox_needed=1
fi
;;
*)
decodeSox
;;
esac
;;
esac
if ! (( copied ))
then
decodeFile
fi
decodeFile
getDestDir
getDestFile
if (( copied ))

View File

@ -1,33 +1,81 @@
#!/bin/bash
decodeFile() {
if ! decodetaskid=$(
Select tasks id <<<"key = $tmpfile"
)
then
decodetaskid=$(
Insert tasks <<-EOInsert
key $tmpfile
source_file $fileid
$(
for key in ${!commandline[@]}
do
echo "cmd_arg$key ${commandline[key]}"
done
case "$mimetype" in
'video/'*)
extractAudio
sox_needed=1
;;
'audio/mpeg')
if [[ ${destinationformat[$destination]} = mp3 ]] \
&& checkCopy
then
copied=1
else
decodeSox
fi
;;
'application/ogg opus')
if [[ ${destinationformat[$destination]} = opus ]] \
&& checkCopy
then
copied=1
else
decodeOpusdec
if (( ${destinationnormalize["$destination"]}))\
|| (
[ -n "${destinationfrequency["$destination"]}" ]\
&& (( ${rate:-0} != ${destinationfrequency["$destination"]}))\
) || (
[ -n "${destinationchannels["$destination"]}" ]\
&& (( ${channels:-0} != ${destinationchannels["$destination"]} ))
)
status 0
EOInsert
)
progressSpin
fi
if (( sox_needed ))
then
sox_needed=1
fi
fi
;;
'application/ogg'*)
if [[ ${destinationformat[$destination]} = vorbis ]] \
&& checkCopy
then
copied=1
else
decodeSox
fi
;;
'audio/x-flac')
decodeSox
;;
*)
extendedtype=$(file -b "$sourcepath/$filename")
case "$extendedtype" in
*'Musepack '*)
decodeMpcdec
if (( ${destinationnormalize["$destination"]}))\
|| (
[ -n "${destinationfrequency["$destination"]}" ]\
&& (( ${rate:-0} != ${destinationfrequency["$destination"]}))\
) || (
[ -n "${destinationchannels["$destination"]}" ]\
&& (( ${channels:-0} != ${destinationchannels["$destination"]} ))
)
then
sox_needed=1
fi
;;
*)
decodeSox
;;
esac
;;
esac
if ! (( copied ))
then
cleanup="$tempdir/$tmpfile"
decodeSox "$tempdir/$tmpfile.wav"
if ! soxtaskid=$(
if ! decodetaskid=$(
Select tasks id <<<"key = $tmpfile"
)
then
soxtaskid=$(
decodetaskid=$(
Insert tasks <<-EOInsert
key $tmpfile
source_file $fileid
@ -37,13 +85,37 @@ decodeFile() {
echo "cmd_arg$key ${commandline[key]}"
done
)
requires $decodetaskid
required $decodetaskid
status 0
cleanup $cleanup
EOInsert
)
progressSpin
fi
if (( sox_needed ))
then
cleanup="$tempdir/$tmpfile"
decodeSox "$tempdir/$tmpfile.wav"
if ! soxtaskid=$(
Select tasks id <<<"key = $tmpfile"
)
then
soxtaskid=$(
Insert tasks <<-EOInsert
key $tmpfile
source_file $fileid
$(
for key in ${!commandline[@]}
do
echo "cmd_arg$key ${commandline[key]}"
done
)
requires $decodetaskid
required $decodetaskid
status 0
cleanup $cleanup
EOInsert
)
progressSpin
fi
fi
fi
}

51
lib/tags/getInfos::ffmpeg Normal file
View File

@ -0,0 +1,51 @@
#!/bin/bash
getInfosffmpeg_version='ffmpeg-1'
tagreaders+=( "$getInfosffmpeg_version" )
getInfos::ffmpeg() {
tagreader="$getInfosffmpeg_version"
local allinfos=$(
ffprobe -show_streams \
-i "$sourcepath/$filename" 2>&1 \
|sed '
/^Input/,/.* Audio: /{s/ *: */=/}
s/^[[:space:]]*//'
)
local metadata=$(
echo -e "$allinfos" \
|sed -n '/Metadata=/,/\[STREAM\]/p'
)
local fmt_infos=$(
echo -e "$allinfos" \
|sed -n \
'/codec_type=audio/,/\[STREAM\]/{
/^\(sample_rate\|bit_rate\|channels\)=/{
p
}
}'
)
local infos="$metadata"
albumartist=$(gettag album_artist)
album=$(gettag album)
artist=$(gettag artist)
composer=$(gettag composer)
genre=$(gettag genre)
performer=$(gettag TOPE)
title=$(gettag title)
tracknum=$(gettag tracknumber)
year=$(gettag year)
expr='^[0-9]*$'
if [ -n "$genre" ] && [[ $genre =~ $expr ]]
then
genre="${id3genres[$genre]}"
fi
infos="$fmt_infos"
channels=$(gettag channels)
rate=$(gettag 'sample_rate')
bitrate=$(gettag 'bit_rate')
if [[ $bitrate == N/A ]]
then
unset bitrate
else
bitrate=$((bitrate / 1000))
fi
}

View File

@ -1,5 +1,5 @@
#!/bin/bash
getTags_version='unknown-2'
getTags_version='unknown-3'
tagreaders+=( "$getTags_version" )
getTags() {
unset type
@ -16,6 +16,9 @@ getTags() {
audio/x-flac)
type=FLAC
;;
video/*)
type=ffmpeg
;;
*)
extendedtype=$(file -b "$sourcepath/$filename")
case "$extendedtype" in

6
lib/video/extractaudio Normal file
View File

@ -0,0 +1,6 @@
#!/bin/bash
extractAudio() {
tmpfile="${fileid}ffmpeg"
commandline=(${ionice}ffmpeg -v 0 -vn -y)
commandline+=(-i "$sourcepath/$filename" "$tempdir/$tmpfile.wav")
}