0

Python novice, looking to change that.

I am trying to convert a song from wma to mp3 while keeping the metadata on the song. Here is my code.

#musicproject.py
import os
import glob
from pydub import AudioSegment

music_dir ='/mnt/c/renameproject'
extension_list = ('*.wma')

os.chdir(music_dir)
for extension in extension_list:
    for song in glob.glob(extension):
        mp3_filename = os.path.splitext(os.path.basename(song))[0] + '.mp3'
        AudioSegment.from_file(song).export(mp3_filename, format='mp3')

The program finishes and the song is written as an mp3 in the same folder and plays just fine. Unfortunately all of the metadata has been stripped from the song. I get the following warning at the command line when I run the program. My theory on the problem is that there is a mismatch between pydub and ffmpeg as far as the metadata library goes so pydub is feeding in something that ffmpeg doesn't understand so it pukes. I have absolutely no idea what steps to take to fix it from here. Any breadcrumbs would be appreciated. Thanks.

File "./musicproject.py", line 12, in <module>
    AudioSegment.from_file(song).export(mp3_filename, format='mp3')
  File "/home/tom/.local/lib/python2.7/site-packages/pydub/audio_segment.py", line 725, in from_file
    p.returncode, p_err.decode(errors='ignore') ))
pydub.exceptions.CouldntDecodeError: Decoding failed. ffmpeg returned error code: 1

Output from ffmpeg/avlib:

ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy 
--enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
musicproject.py: Invalid data found when processing input
Rich
  • 1
  • Get a plain, non-scripted `ffmpeg` command-line working before you attempt to script it. When you do that you'll notice the `library configuration mismatch` will still show up and can be ignored. It's a result of how Ubuntu packaged this particular build of `ffmpeg`. As for the metadata run `ffmpeg -i input.wma output.mp3` and provide the complete log. – llogan Jul 21 '20 at 17:42
  • Thank you for the response. Here is the output. https://pastebin.com/LAmn6UzR Edit: I just realized that the metadata was cloned over. does this mean the problem is with pydub? – Rich Jul 21 '20 at 18:03
  • Did pydub even output any MP3 files? `musicproject.py: Invalid data found when processing input` indicates that the script itself is possibly being used as an input, like `ffmpeg -i musicproject.py` which will result in that error. – llogan Jul 21 '20 at 18:29
  • Yes, pydub did spit out a working mp3 file with the proper name, just no metadata associated with the file. – Rich Jul 21 '20 at 18:53
  • If it is just a wrapper to the `ffmpeg` command line tool then if you can find the actual command it executes it may provide the reason for this behavior. – llogan Jul 21 '20 at 18:55
  • Thank you. I'll fiddle with this and see if I can discover the answer on my own although I'll come back if not. – Rich Jul 22 '20 at 13:08

0 Answers0