I'm not sure why ffmpeg does that to the output file when using -metadata. I have tried -y to overwrite, not using regex or in a variable... its strange. because if you write to a new file, it will work. I had to make songs display correctly on a car stereo awhile back, and had to fix certain tracks and made this:
#!/bin/bash
ICO="applications-multimedia"
f=$(yad --window-icon="$ICO" --center --title "Select MP3 File" --file)
function fthelp () {
yad --window-icon="gtk-help" --title="Help?" --borders=10 --center --skip-taskbar --image-on-top --image="gtk-help" --text-align=center --text="None so far..." --button=gtk-close:0
}
export -f fthelp
# SCAN FOR EXISTING TAGS
scan_art=$(ffprobe -loglevel error -show_entries format_tags=artist -of default=noprint_wrappers=1:nokey=1 "$f")
scan_alb=$(ffprobe -loglevel error -show_entries format_tags=album -of default=noprint_wrappers=1:nokey=1 "$f")
scan_tit=$(ffprobe -loglevel error -show_entries format_tags=title -of default=noprint_wrappers=1:nokey=1 "$f")
scan_year=$(ffprobe -loglevel error -show_entries format_tags=year -of default=noprint_wrappers=1:nokey=1 "$f")
scan_len=$(ffmpeg -i "$f" 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,//)
scan_gen=$(ffprobe -loglevel error -show_entries format_tags=genre -of default=noprint_wrappers=1:nokey=1 "$f")
scan_lyr=$(ffprobe -loglevel error -show_entries format_tags=lyrics -of default=noprint_wrappers=1:nokey=1 "$f")
# MAIN DIALOG
MD=$(yad --window-icon="$ICO" --geometry="275x475" --center --borders="20" --justify="center" --title="2J ID3 Editor 1.0" --buttons-layout="center" --text-align="center" --text "ID3 Tag Editor" --form \
--field="Artist:" "$scan_art" \
--field="Title:" "$scan_tit" \
--field="Album:" "$scan_alb" \
--field="Year:" "$scan_year" \
--field="Length:":RO "$scan_len" \
--field="Genre:" "$scan_gen" \
--field="Lyrics:":TXT "$scan_lyr" \
--field="Create Backup?":CHK "FALSE" > /tmp/entries \
--button=gtk-help:"bash -c fthelp" \
--button=gtk-apply:0 \
--button=gtk-quit:1)
fld1=$(cut -d'|' -f1 < /tmp/entries)
fld2=$(cut -d'|' -f2 < /tmp/entries)
fld3=$(cut -d'|' -f3 < /tmp/entries)
fld4=$(cut -d'|' -f4 < /tmp/entries)
fld5=$(cut -d'|' -f5 < /tmp/entries)
fld6=$(cut -d'|' -f6 < /tmp/entries)
fld7=$(cut -d'|' -f7 < /tmp/entries)
fld8=$(cut -d'|' -f8 < /tmp/entries)
if [[ $MD == 1 ]]
then rm /tmp/entries
exit 1
else [[ $MD == 0 ]]
if [[ $fld8 == TRUE ]]
then cp "$f" "$f.bak"
ffmpeg -y -i "$f" -c copy -metadata artist="$fld1" -metadata title="$fld2" -metadata album="$fld3" -metadata year="$fld4" -metadata genre="$fld6" -metadata lyrics="$fld7" "${f#./}.new.mp3" && mv "${f#./}.new.mp3" "$f"
rm /tmp/entries
fi
fi
exit 0
If you remove the .out.mp3 and move at the end of that ffmpeg command, it will break that file. It overwrites your song to some file that's only kbytes in size, just like you speak of. Don't know why. I just tried using an out file instead of overwriting and it worked out.