오디오 또는 비디오 파일에서 메타 데이터를 가져 와서 데이터베이스 레코드에 저장하는 것이 지금까지 유일한 방법입니다 이 AVCONV subprocess.Open 호출을 누른 다음 해당 파일을 읽는 파일을 사용하여 저장하려면 일부 단계를 저장하려면이 일을 할 수있는 라이브러리 무엇입니까? 나는 Pydub 또는 PySox로 그것을 할 수있는 방법을 찾지 못했습니다. 여기에 내가 사용하는 단순한 hamfisted 초보자 코드가 있는데, 비트 레이트, 지속 시간 등의 정보를 변수 audio_info에 넣고 메타 데이터를 메타 데이터에 넣습니다. OGG 출력은 내가 테스트 한 다른 형식과 다르게 작동했습니다 (비디오 및 오디오 톤이었습니다!).어떻게 파이썬의 오디오/비디오 파일에서 메타 데이터와 비트 전송률 정보를 추출 할 수 있습니까?
try:
p = subprocess.Popen(["avconv" , "-i" , music_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
retcode = p.wait()
except IOError,e:
pass
extension = uploaded_music_file[-3:]
if "ogg" not in [err , extension]:
if "Metadata:" in err:
list = err.split("Metadata:")
holder = list[1].split("Duration:")
metadata = holder[0]
audio_info = holder[1].replace("At least one output file must be specified","")
print metadata
print audio_info
else:
list = err.split("Duration:")
audio_info = list[1].replace("At least one output file must be specified","")
print "No Metadata"
print audio_info
else:
list = err.split("Duration:")
if "Metadata:" in list[1]:
data = list[1].split("Metadata:")
metadata = data[1].replace("At least one output file must be specified","")
audio_info = data[0]
print metadata
print audio_info
else:
audio_info = list[1].replace("At least one output file must be specified","")
print "No Metadata"
print audio_info
if (audio_info):
print "AUDIO INFO:"
cursor.execute("UPDATE songDB SET audio_info = %s WHERE id = %s" ,[ audio_info , song_id ])
if (metadata):
print "METADATA:"
cursor.execute("songDB pack_song SET metadata = %s WHERE id = %s" ,[ metadata , song_id ])
@ Oz123은 실제로 함께 작동하는 코드를 추가했습니다. - 출력이 꽤 janky –