ffmpeg : music_meta use auto-detection.

This commit is contained in:
Dmitry Voronin 2023-11-30 03:52:05 +03:00
parent 6239070c6a
commit abe6f6cf5f
2 changed files with 20 additions and 12 deletions

View file

@ -483,7 +483,7 @@ Command|Description
---|--- ---|---
`ffmpeg_mux_audio <SOUND> <RESULT>`|Mux external audio into one container with video (replaces original audio). Run inside dir with original video. <SOUND> names should be the same for each video. `ffmpeg_mux_audio <SOUND> <RESULT>`|Mux external audio into one container with video (replaces original audio). Run inside dir with original video. <SOUND> names should be the same for each video.
`ffmpeg_mux_cover <FORMAT> <COVER>`|Mux image into files of specified format. `ffmpeg_mux_cover <FORMAT> <COVER>`|Mux image into files of specified format.
`ffmpeg_music_artist <FORMAT> <ARTIST>`|Change audio artist metadata. `ffmpeg_music_meta <FORMAT>`|Detect and update music metadata.
## File. ## File.

View file

@ -4,7 +4,7 @@ ffmpeg_mux_audio()
{ {
if [[ "$1" = "" ]]; then if [[ "$1" = "" ]]; then
echo "usage: ffmpeg_mux_audio <SOUND> <OUTPUT DIR>" echo "usage: ffmpeg_mux_audio <SOUND> <OUTPUT DIR>"
return return 2
fi 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 for file in *; do ffmpeg -i "$file" -i "$1"/"$file" -c copy -map 0:v:0 -map 1:a:0 -shortest "$2"/"$file"; done
@ -16,7 +16,7 @@ ffmpeg_mux_cover()
{ {
if [[ "${1}" = "" ]]; then if [[ "${1}" = "" ]]; then
echo "Usage: ffmpeg_mux_cover <FORMAT> <COVER>" echo "Usage: ffmpeg_mux_cover <FORMAT> <COVER>"
return return 2
fi fi
local format="${1}" local format="${1}"
@ -28,28 +28,36 @@ ffmpeg_mux_cover()
ffmpeg -i "${file}" -i "${cover}" -map 0:a -map 1 -codec copy -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -disposition:v attached_pic ./out/"${file}" || return 1 ffmpeg -i "${file}" -i "${cover}" -map 0:a -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 done
mv out/* . && rm -d out/ && rm "${2}" mv out/* .
rm -d out/ && rm "${2}"
} }
# Change audio artist metadata. # Change music metadata.
# Usage: ffmpeg_music_artist <FORMAT> <ARTIST> # Usage: ffmpeg_music_meta <FORMAT>
ffmpeg_music_artist() ffmpeg_music_meta()
{ {
if [[ "${1}" = "" ]]; then if [[ "${1}" = "" ]]; then
echo "Usage: ffmpeg_music_artist <FORMAT> <ARTIST>" echo "Usage: ffmpeg_mux_cover <FORMAT> <COVER>"
return return 2
fi fi
local format="${1}" local format="${1}"
local artist="${2}"
local artist="${PWD%/*}"; artist="${artist##*/}"
local album="${PWD##*/}"; album="${album#*_}"
local year="${PWD##*/}"; year="${year%%_*}"
mkdir out mkdir out
for file in *.${format}; do for file in *.${format}; do
ffmpeg -i "${file}" -c copy -metadata "ARTIST=${artist}" -metadata "album_artist=${artist}" ./out/"${file}" || return 1 local track="${file%%_*}"
local title="${file#*_}"; title="${title%.*}"
ffmpeg -i "${file}" -c copy -metadata "artist=${artist}" -metadata "album_artist=${artist}" -metadata "album=${album}" -metadata "date=${year}" -metadata "track=${track}" -metadata "title=${title}" ./out/"${file}" || return 1
done done
mv out/* . && rm -d out/ mv out/* .
rm -d out/
} }
_ffprobe_fps() _ffprobe_fps()