从 M4A

问题描述

我编写了一个 Python 脚本,用于收集 .m4a 文件(艺术家、标题等)的元数据,将 .m4a 转换为 .mp3,然后将元数据保存到新的 .mp3。>

当我在 iTunes 中播放新 MP3 时,显示的曲目长度是 M4A 版本的两倍。 (正常轨道长度为 3:37)。见下图:

iTunes Track Length Crop

有趣的是,当 7:14 长的曲目到达 3:37 时,歌曲会像往常一样结束,跳过剩余的显示时间,转到下一首歌曲。但是,当我使用下图所示的小部件单击曲目中的各个位置(包括超过 3:37 的时间戳)时,它似乎在歌曲中的相对点播放而不是什么都不播放。 (例如,拖动到 7:00 并点击“播放”会播放歌曲的正常结尾,与原始 M4A 的 ~3:23 时间戳播放的内容相同)。很难描述...希望这是有道理的。

我的代码在这里:

from pydub import AudioSegment
from tinytag import TinyTag
from mutagen.easyid3 import EasyID3
from mutagen.mp3 import MP3
import mutagen

song_directory = "/Users/mgermaine93/Desktop/Test-Music/"
song_name = "03 Dylan Thomas.m4a"
song_name_minus_file_type = song_name[0:-4]
song_file_type = song_name[-4:]
song_full_name = f"{song_directory}{song_name}"

# This grabs the track information from the existing file before it is converted
mp3 = TinyTag.get(f"{song_full_name}")

album = mp3.album
# album_artist = mp3.albumartist
title = mp3.title
artist = mp3.artist
composer = mp3.composer
genre = mp3.genre
year = mp3.year
track_number = mp3.track
track_total = mp3.track_total
disc_number = mp3.disc
disc_total = mp3.disc_total
duration = mp3.duration
print(f"This is the duration of the m4a: {duration}")

# This part does the conversion from m4a to mp3
m4a_audio = AudioSegment.from_file(
    f"{song_full_name}",format="m4a")
m4a_audio.export(
    f"{song_directory}{song_name_minus_file_type}.mp3",format="mp3")

# This assigns the m4a track field values to the new mp3
mp3 = EasyID3(f"{song_directory}{song_name_minus_file_type}.mp3")

mp3['album'] = album
mp3['title'] = title
mp3['artist'] = artist
mp3['composer'] = composer
mp3['genre'] = genre
mp3['date'] = year
EasyID3.RegisterTextKey('track total','TRCK')
mp3['track total'] = f"{track_number}/{track_total}"
EasyID3.RegisterTextKey('disc total','TPOS')
mp3['disc total'] = f"{disc_number}/{disc_total}"
mp3.save(v2_version=3)

# Get the properties of the mp3
new_song = TinyTag.get(f"{song_directory}{song_name_minus_file_type}.mp3")

new_duration = new_song.duration
print(f"This is the duration of the mp3: {new_duration}")

脚本的当前输出为:

This is the duration of the m4a: 216.85115646258504
This is the duration of the mp3: 216.94245058379644

据我所知,这个问题似乎没有影响任何有意义的事情。而且我确信有更有效的方法来执行文件转换,但是我所写的可以完成我想要它做的所有事情。 (除了上面输出中的持续时间值略有不同之外,两个文件的元数据是相同的。)我只是不明白为什么显示长度会与元数据所说的持续时间不同。

在此先感谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...