# mux audio into containers. file names in sound and current dirrectories must match. tmp usage for anime downloads. # usage: ffmpeg_mux_audio ffmpeg_mux_audio() { if [[ "$1" = "" ]]; then echo "usage: ffmpeg_mux_audio " return 2 fi for file in *; do ffmpeg -i "$file" -i "$1"/"$file" -c copy -map 0:v:0 -map 1:a:0 -shortest "$2"/"$file"; done } # Mux cover into music file. # Usage: ffmpeg_mux_cover ffmpeg_mux_cover() { if [[ "${1}" = "" ]]; then echo "Usage: ffmpeg_mux_cover " return 2 fi local format="${1}" local cover="${2}" mkdir out case "${format}" in "mka"|"mkv") for file in *.${format}; do ffmpeg -i "${file}" -attach "${cover}" -map 0 -c copy -metadata:s:t mimetype="image/${cover##*.}" -metadata:s:t:0 filename="cover.${cover##*.}" "./out/${file}" || return 1 done ;; *) for file in *.${format}; do ffmpeg -i "${file}" -i "${cover}" -map 0 -map 0:-v? -map 1 -codec copy -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -disposition:v attached_pic ./out/"${file}" || return 1 done ;; esac mv out/* . rm -d out/ && rm "${2}" } # Change music metadata. # Usage: ffmpeg_music_meta ffmpeg_music_meta() { if [[ "${1}" = "" ]]; then echo "Usage: ffmpeg_music_meta " return 2 fi local format="${1}" ls *.${format} &> /dev/null || return 1 local artist="${PWD%/*}"; artist="${artist##*/}"; artist="${artist//_/ }" local album="${PWD##*/}"; album="${album#*_}"; album="${album//_/ }" local year="${PWD##*/}"; year="${year%%_*}" # local total=$(ls *.${format} | wc -l) mkdir out for file in *.${format}; do local track="${file%%_*}"; track=$((10#${track})); [[ "${track}" = "" ]] && track=0 local title="${file#*_}"; title="${title%.*}"; title="${title//_/ }" # echo "${artist}; ${album}; ${year}; ${track}; ${title}" # TODO: make it format-specific. ffmpeg -i "${file}" -map 0 -c copy -metadata "artist=${artist}" -metadata "album_artist=${artist}" -metadata "album=${album}" -metadata "date=${year}" -metadata "year=${year}" -metadata "date_released=${year}" -metadata "track=${track}" -metadata "part_number=${track}" -metadata "title=${title}" ./out/"${file}" || return 1 done mv out/* . rm -d out/ } _ffprobe_fps() { local fps=$(ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate "${1}") fps="${fps%%/*}" echo "${fps}" } _ffprobe_keyint() { local fps=$(_ffprobe_fps "${1}") echo $((fps*5)) } _ffprobe_ba() { local ba=$(ffprobe -v error -select_streams a:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 "${1}") [[ "${ba}" != "N/A" ]] && echo $((ba/1024)) || echo 128 } export -f _ffprobe_keyint _ffprobe_ba _ffprobe_fps