Reputation: 874
Is there a way to extract ID3 tags using ffmpeg-libav? I have already tried the code below but it does not extract anything:
fun extractMetadata(mp3FilePath: String) {
avformat.av_register_all()
val formatContext = AVFormatContext(null)
if (avformat.avformat_open_input(formatContext, mp3FilePath, null, null) < 0) {
println("Failed to open input file")
return
}
if (avformat.avformat_find_stream_info(formatContext, null) < 0) {
println("Failed to retrieve stream information")
avformat.avformat_close_input(formatContext)
return
}
var metadataEntry: AVDictionaryEntry? = null
while (true) {
metadataEntry = avformat.av_dict_get(formatContext.metadata, "", metadataEntry, avformat.AV_DICT_IGNORE_SUFFIX)
if (metadataEntry == null) {
break
}
val key = metadataEntry.key().getString()
val value = metadataEntry.value().getString()
println("Key: $key, Value: $value")
}
avformat.avformat_close_input(formatContext)
}
By the way this code is written in Kotlin and using org.bytedecoe.ffmpeg-platform
lib which is a wrapper for libav. You can give me C++ code and i will be able convert it to kotlin code with ease.
Upvotes: 0
Views: 141