1

like the title I want to add/change metadata to ogg(opus) files in one folder(one album/one artist).When i encode from wav/flac to opus i usually use

for f in *.*; do ffmpeg -i "$f" -c:a libopus -b:a 510000 "${f%.*}.ogg"; done

Then when i test one file with

for f in *.*; do ffmpeg -i "$f" -c copy -metadata artist="artist name" -metadata album="album name" "${f%.*}.ogg"; done

The result is the file reduced to just like 47kb(so i assumed that input and output name can't be same).

So any efficient way to add/change metadata while retaining same name? And how to embed image to the ogg(opus) files?I want to have cover art/image displayed when playing the files.

Rajesh Pandya
  • 1,540
  • 4
  • 18
  • 31
Calendar
  • 51
  • 1
  • 8

2 Answers2

4

I'm sorry I forgot this post of mine since there're no answer for more than a month. So actually after some testing back then, my problem is simply because for reasons I don't know(I'm not tech savy)ffmpeg and other tagger refuse to tag files when opus codec with .ogg extention being use. I searched a bit and the native and recommended extention for opus codec is .opus extention so I used that and with ffmpeg -map function the metadata from flac copied to the new opus files I created correctly.

The image also can embedded easily using ffmpeg or any tagger after that.

As for the overwrite problem, actually with a bit of logic it is really impossible to do what I want, simply the files must have different full names(.flac and .opus works) or just output the files to other directory.

Calendar
  • 51
  • 1
  • 8
  • Could it just be a question of encoding? Like base64... – Sandburg Sep 05 '20 at 10:12
  • 1
    Thank you for your answer, I thought I was going crazy. I am having the same issue with opus in .ogg container. Output metadata is unchanged (identical to input metadata) when attempting to change it using `-metadata`. Is it a bug? – Derkades Oct 06 '22 at 08:07
2

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.

J. Cravens
  • 131
  • 1
  • 7