Closed asmedrano closed 12 years ago
Do you have ffmpeg installed, it's required for all formats except for wav.
one good way to check is to see if you're able to import an mp3 file.
Sometimes if you have ffmpeg installed but pydub is unable to find it, you have to manually tell pydub where to find ffmpeg like so:
from pydub import AudioSegment
AudioSegment.converter = "/path/to/ffmpeg"
this should be just below the import
No Dice. I do have ffmpeg installed. /usr/bin/ffmpeg
from pydub import AudioSegment
AudioSegment.ffmpeg = "/usr/bin/ffmpeg"
# ^^^^^^^^^^^^^^^^^
# edit by maintainer: Starting in 0.9.0 this should now be AudioSegment.converter = …
def main():
s = AudioSegment.from_mp3("mysound.mp3")
out = s.reverse()
out.export("out.mp3", format="mp3")
if __name__ == '__main__':
main()
$ ffmpeg -version
ffmpeg version 0.8.3-4:0.8.3-0ubuntu0.12.04.1, Copyright (c) 2000-2012 the Libav developers
built on Jun 12 2012 16:37:58 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
ffmpeg 0.8.3-4:0.8.3-0ubuntu0.12.04.1
libavutil 51. 22. 1 / 51. 22. 1
libavcodec 53. 35. 0 / 53. 35. 0
libavformat 53. 21. 0 / 53. 21. 0
libavdevice 53. 2. 0 / 53. 2. 0
libavfilter 2. 15. 0 / 2. 15. 0
libswscale 2. 1. 0 / 2. 1. 0
libpostproc 52. 0. 0 / 52. 0. 0
I can import from mp3 just not export.
would you mind posting mysound.mp3
(you can upload to esploded.com if you don't have another way) as well as the output of out.export(…)
?
Give this a whirl http://ubuntuone.com/5aamm9opLmf6UqJsX1VN6H
Since the output file is 0 bytes I'm going to assume there is an error happening when calling ffmpeg.
The export function creates a temp file to save the output (where this isn't necessary to produce wav files)...
would you mind running this ffmpeg command on the wav file directly?
$ ffmpeg -y -f wav -i ./voice_2.wav -f mp3 ./out.mp3
for me, the output was:
FFmpeg version CVS, Copyright (c) 2000-2004 Fabrice Bellard
Mac OSX universal build for ffmpegX
configuration: --enable-memalign-hack --enable-mp3lame --enable-gpl --disable-vhook --disable-ffplay --disable-ffserver --enable-a52 --enable-xvid --enable-faac --enable-faad --enable-amr_nb --enable-amr_wb --enable-pthreads --enable-x264
libavutil version: 49.0.0
libavcodec version: 51.9.0
libavformat version: 50.4.0
built on Apr 15 2006 04:58:19, gcc: 4.0.1 (Apple Computer, Inc. build 5250)
Input #0, wav, from './voice_2.wav':
Duration: 00:00:07.2, start: 0.000000, bitrate: 705 kb/s
Stream #0.0: Audio: pcm_s32le, 22050 Hz, mono, 705 kb/s
Output #0, mp3, to './out.mp3':
Stream #0.0: Audio: mp3, 22050 Hz, mono, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding
size= 57kB time=7.3 bitrate= 64.0kbits/s
video:0kB audio:57kB global headers:0kB muxing overhead 0.000000%
producing a 58 KB mp3 file (which played fine)
Maybe you only have a decode codec but not encode?
what does this give you?
ffmpeg -formats
ffmpeg -formats
ffmpeg version 0.8.3-4:0.8.3-0ubuntu0.12.04.1, Copyright (c) 2000-2012 the Libav developers
built on Jun 12 2012 16:37:58 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
File formats:
D. = Demuxing supported
.E = Muxing supported
--
E 3g2 3GP2 format
E 3gp 3GP format
D 4xm 4X Technologies format
D IFF IFF format
D ISS Funcom ISS format
D MTV MTV format
DE RoQ raw id RoQ format
E a64 a64 - video for Commodore 64
D aac raw ADTS AAC
DE ac3 raw AC-3
E adts ADTS AAC
DE adx CRI ADX
D aea MD STUDIO audio
DE aiff Audio IFF
DE alaw PCM A-law format
DE alsa ALSA audio output
DE amr 3GPP AMR file format
D anm Deluxe Paint Animation
D apc CRYO APC format
D ape Monkey's Audio
D applehttp Apple HTTP Live Streaming format
DE asf ASF format
E asf_stream ASF format
DE ass Advanced SubStation Alpha subtitle format
DE au SUN AU format
DE avi AVI format
E avm2 Flash 9 (AVM2) format
D avs AVS format
D bethsoftvid Bethesda Softworks VID format
D bfi Brute Force & Ignorance
D bink Bink
D bmv Discworld II BMV
D c93 Interplay C93
D caf Apple Core Audio Format
DE cavsvideo raw Chinese AVS video
D cdg CD Graphics Format
E crc CRC testing format
DE daud D-Cinema audio format
D dfa Chronomaster DFA
DE dirac raw Dirac
DE dnxhd raw DNxHD (SMPTE VC-3)
D dsicin Delphine Software International CIN format
DE dts raw DTS
DE dv DV video format
D dv1394 DV1394 A/V grab
E dvd MPEG-2 PS format (DVD VOB)
D dxa DXA
D ea Electronic Arts Multimedia Format
D ea_cdata Electronic Arts cdata
DE eac3 raw E-AC-3
DE f32be PCM 32 bit floating-point big-endian format
DE f32le PCM 32 bit floating-point little-endian format
DE f64be PCM 64 bit floating-point big-endian format
DE f64le PCM 64 bit floating-point little-endian format
D fbdev Linux framebuffer
DE ffm FFM (AVserver live feed) format
DE ffmetadata FFmpeg metadata in text format
D film_cpk Sega FILM/CPK format
DE filmstrip Adobe Filmstrip
DE flac raw FLAC
D flic FLI/FLC/FLX animation format
DE flv FLV format
E framecrc framecrc testing format
E framemd5 Per-frame MD5 testing format
DE g722 raw G.722
E gif GIF Animation
D gsm raw GSM
DE gxf GXF format
DE h261 raw H.261
DE h263 raw H.263
DE h264 raw H.264 video format
D idcin id Cinematic format
DE image2 image2 sequence
DE image2pipe piped image2 sequence
D ingenient raw Ingenient MJPEG
D ipmovie Interplay MVE format
E ipod iPod H.264 MP4 format
D iv8 A format generated by IndigoVision 8000 video server
DE ivf On2 IVF
D jack JACK Audio Connection Kit
D jv Bitmap Brothers JV
DE latm LOAS/LATM
D libdc1394 dc1394 v.2 A/V grab
D lmlm4 lmlm4 raw format
D lxf VR native stream format (LXF)
DE m4v raw MPEG-4 video format
E matroska Matroska file format
D matroska,webm Matroska/WebM file format
E md5 MD5 testing format
DE mjpeg raw MJPEG video
DE mlp raw MLP
D mm American Laser Games MM format
DE mmf Yamaha SMAF
E mov MOV format
D mov,mp4,m4a,3gp,3g2,mj2 QuickTime/MPEG-4/Motion JPEG 2000 format
E mp2 MPEG audio layer 2
DE mp3 MPEG audio layer 3
E mp4 MP4 format
D mpc Musepack
D mpc8 Musepack SV8
DE mpeg MPEG-1 System format
E mpeg1video raw MPEG-1 video
E mpeg2video raw MPEG-2 video
DE mpegts MPEG-2 transport stream format
D mpegtsraw MPEG-2 raw transport stream format
D mpegvideo raw MPEG video
E mpjpeg MIME multipart JPEG format
D msnwctcp MSN TCP Webcam stream
DE mulaw PCM mu-law format
D mvi Motion Pixels MVI format
DE mxf Material eXchange Format
E mxf_d10 Material eXchange Format, D-10 Mapping
D mxg MxPEG clip file format
D nc NC camera feed format
D nsv Nullsoft Streaming Video
E null raw null video format
DE nut NUT format
D nuv NuppelVideo format
DE ogg Ogg
DE oma Sony OpenMG audio
DE oss Open Sound System playback
D pmp Playstation Portable PMP format
E psp PSP MP4 format
D psxstr Sony Playstation STR format
D pva TechnoTrend PVA file and stream format
D qcp QCP format
D r3d REDCODE R3D format
DE rawvideo raw video format
E rcv VC-1 test bitstream
D rl2 RL2 format
DE rm RealMedia format
D rpl RPL/ARMovie format
DE rso Lego Mindstorms RSO format
DE rtp RTP output format
DE rtsp RTSP output format
DE s16be PCM signed 16 bit big-endian format
DE s16le PCM signed 16 bit little-endian format
DE s24be PCM signed 24 bit big-endian format
DE s24le PCM signed 24 bit little-endian format
DE s32be PCM signed 32 bit big-endian format
DE s32le PCM signed 32 bit little-endian format
DE s8 PCM signed 8 bit format
DE sap SAP output format
D sdp SDP
E segment segment muxer
D shn raw Shorten
D siff Beam Software SIFF
DE smjpeg Loki SDL MJPEG
D smk Smacker video
D sol Sierra SOL format
DE sox SoX native format
DE spdif IEC 61937 (used on S/PDIF - IEC958)
DE srt SubRip subtitle format
E svcd MPEG-2 PS format (VOB)
DE swf Flash format
D thp THP
D tiertexseq Tiertex Limited SEQ format
D tmv 8088flex TMV
DE truehd raw TrueHD
D tta True Audio
D tty Tele-typewriter
D txd Renderware TeXture Dictionary
DE u16be PCM unsigned 16 bit big-endian format
DE u16le PCM unsigned 16 bit little-endian format
DE u24be PCM unsigned 24 bit big-endian format
DE u24le PCM unsigned 24 bit little-endian format
DE u32be PCM unsigned 32 bit big-endian format
DE u32le PCM unsigned 32 bit little-endian format
DE u8 PCM unsigned 8 bit format
D vc1 raw VC-1
D vc1test VC-1 test bitstream format
E vcd MPEG-1 System format (VCD)
D video4linux2 Video4Linux2 device grab
D vmd Sierra VMD format
E vob MPEG-2 PS format (VOB)
DE voc Creative Voice file format
D vqf Nippon Telegraph and Telephone Corporation (NTT) TwinVQ
D w64 Sony Wave64 format
DE wav WAV format
D wc3movie Wing Commander III movie format
E webm WebM file format
D wsaud Westwood Studios audio format
D wsvqa Westwood Studios VQA format
D wtv Windows Television (WTV)
D wv WavPack
D x11grab X11grab
D xa Maxis XA File Format
D xmv Microsoft XMV
D xwma Microsoft xWMA
D yop Psygnosis YOP Format
DE yuv4mpegpipe YUV4MPEG pipe format
mp3 is listed with DE (decode, encode) so it should be fine... maybe it's because it can't write to the temp file. is your temp folder full?
$ df -h
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 144G 60G 78G 44% /
udev 1.5G 4.0K 1.5G 1% /dev
tmpfs 585M 908K 584M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1.5G 1.8M 1.5G 1% /run/shm
BTW... I appreciate your hasty responses, I don't mean to keep you from anything else. I just happen not to be able to export to mp3. Its no real bother!
Could it be my OS?
Also here is the output of:
$ ffmpeg -y -f wav -i ./voice_2.wav -f mp3 ./out.mp3
ffmpeg version 0.8.3-4:0.8.3-0ubuntu0.12.04.1, Copyright (c) 2000-2012 the Libav developers
built on Jun 12 2012 16:37:58 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
[wav @ 0x9be5a80] max_analyze_duration reached
Input #0, wav, from './voice_2.wav':
Duration: 06:45:47.14, bitrate: 0 kb/s
Stream #0.0: Audio: pcm_s32le, 22050 Hz, 1 channels, s32, 705 kb/s
Output #0, mp3, to './out.mp3':
Stream #0.0: Audio: [0][0][0][0] / 0x0000, 22050 Hz, 1 channels, s32, 200 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Encoder (codec id 86017) not found for output stream #0.0
I missed that part of your comment.
hmmm.... looks like it's your ffmpeg install...
I don't think it's your OS, I run pydub in production on CentOS as well as Ubuntu server
Coolz. Maybe I picked up a weird version somehow. I'll do some more trouble shooting on it later on. Thanks!
Hi there,
I have had the very same issue. All the key points (like 0 bytes output file and 'DE' for mp3 format) were the same. The problem is that by default ffmpeg installs without mp3 support (libmp3lame, to be precise).
The solution is to remove the ffmpeg installation, and manually build it from sources with libmp3lame support. For more details check out these links: http://superuser.com/questions/196857/how-to-install-libmp3lame-for-ffmpeg https://trac.ffmpeg.org/wiki/UbuntuCompilationGuide
UPD.: This solution only fixes the ffmpeg encoder behaviour, not the avconv.
@bashuk Hey, you'll also want to install libavcodec-extra-53
as shown in the ffmpeg setup notes from the readme
:)
@bashuk Any luck?
Hey, @jiaaro! Sorry, I missed that you are waiting for the response.
As I wrote previously, I came up with the solution. Since I've built ffmpeg with libmp3lame
support, everything works like a charm. Obviously, ffmpeg was missing that part.
Not sure about libavcodec-extra-53
, to be honest - I didn't try that since the libmp3lame
fixed everything. I can't recall installing libavcodec-extra-53
explicitly along with the ffmpeg, but who knows - maybe I had installed it some long time ago as a dependency for some other package. Hope this fully describes the situation I have.
Anyways, thanks a lot for keeping an eye on my issue, really appreciate that! :)
@bashuk Glad you got it working, thanks for the reply
FWIW I'm also seeing the same issues on Ubuntu 12.04. I have installed libav-tools, libavcodec-extra-53, ffmpeg, libmp3lame0, and ubuntu-restricted-extras.
$ ffmpeg -formats
ffmpeg version 0.8.16-4:0.8.16-0ubuntu0.12.04.1, Copyright (c) 2000-2014 the Libav developers
built on Sep 16 2014 18:33:49 with gcc 4.6.3
The ffmpeg program is only provided for script compatibility and will be removed
in a future release. It has been deprecated in the Libav project to allow for
incompatible command line syntax improvements in its replacement called avconv
(see Changelog for details). Please use avconv instead.
File formats:
D. = Demuxing supported
.E = Muxing supported
--
E 3g2 3GP2 format
E 3gp 3GP format
D 4xm 4X Technologies format
D IFF IFF format
D ISS Funcom ISS format
D MTV MTV format
DE RoQ raw id RoQ format
E a64 a64 - video for Commodore 64
D aac raw ADTS AAC
DE ac3 raw AC-3
E adts ADTS AAC
DE adx CRI ADX
D aea MD STUDIO audio
DE aiff Audio IFF
DE alaw PCM A-law format
DE alsa ALSA audio output
DE amr 3GPP AMR file format
D anm Deluxe Paint Animation
D apc CRYO APC format
D ape Monkey's Audio
D applehttp Apple HTTP Live Streaming format
DE asf ASF format
E asf_stream ASF format
DE ass Advanced SubStation Alpha subtitle format
DE au SUN AU format
DE avi AVI format
E avm2 Flash 9 (AVM2) format
D avs AVS format
D bethsoftvid Bethesda Softworks VID format
D bfi Brute Force & Ignorance
D bink Bink
D bmv Discworld II BMV
D c93 Interplay C93
D caf Apple Core Audio Format
DE cavsvideo raw Chinese AVS video
D cdg CD Graphics Format
E crc CRC testing format
DE daud D-Cinema audio format
D dfa Chronomaster DFA
DE dirac raw Dirac
DE dnxhd raw DNxHD (SMPTE VC-3)
D dsicin Delphine Software International CIN format
DE dts raw DTS
DE dv DV video format
D dv1394 DV1394 A/V grab
E dvd MPEG-2 PS format (DVD VOB)
D dxa DXA
D ea Electronic Arts Multimedia Format
D ea_cdata Electronic Arts cdata
DE eac3 raw E-AC-3
DE f32be PCM 32 bit floating-point big-endian format
DE f32le PCM 32 bit floating-point little-endian format
DE f64be PCM 64 bit floating-point big-endian format
DE f64le PCM 64 bit floating-point little-endian format
D fbdev Linux framebuffer
DE ffm FFM (AVserver live feed) format
DE ffmetadata FFmpeg metadata in text format
D film_cpk Sega FILM/CPK format
DE filmstrip Adobe Filmstrip
DE flac raw FLAC
D flic FLI/FLC/FLX animation format
DE flv FLV format
E framecrc framecrc testing format
E framemd5 Per-frame MD5 testing format
DE g722 raw G.722
E gif GIF Animation
D gsm raw GSM
DE gxf GXF format
DE h261 raw H.261
DE h263 raw H.263
DE h264 raw H.264 video format
D idcin id Cinematic format
DE image2 image2 sequence
DE image2pipe piped image2 sequence
D ingenient raw Ingenient MJPEG
D ipmovie Interplay MVE format
E ipod iPod H.264 MP4 format
D iv8 A format generated by IndigoVision 8000 video server
DE ivf On2 IVF
D jack JACK Audio Connection Kit
D jv Bitmap Brothers JV
DE latm LOAS/LATM
D libdc1394 dc1394 v.2 A/V grab
D lmlm4 lmlm4 raw format
D lxf VR native stream format (LXF)
DE m4v raw MPEG-4 video format
E matroska Matroska file format
D matroska,webm Matroska/WebM file format
E md5 MD5 testing format
DE mjpeg raw MJPEG video
DE mlp raw MLP
D mm American Laser Games MM format
DE mmf Yamaha SMAF
E mov MOV format
D mov,mp4,m4a,3gp,3g2,mj2 QuickTime/MPEG-4/Motion JPEG 2000 format
E mp2 MPEG audio layer 2
DE mp3 MPEG audio layer 3
E mp4 MP4 format
D mpc Musepack
D mpc8 Musepack SV8
DE mpeg MPEG-1 System format
E mpeg1video raw MPEG-1 video
E mpeg2video raw MPEG-2 video
DE mpegts MPEG-2 transport stream format
D mpegtsraw MPEG-2 raw transport stream format
D mpegvideo raw MPEG video
E mpjpeg MIME multipart JPEG format
D msnwctcp MSN TCP Webcam stream
DE mulaw PCM mu-law format
D mvi Motion Pixels MVI format
DE mxf Material eXchange Format
E mxf_d10 Material eXchange Format, D-10 Mapping
D mxg MxPEG clip file format
D nc NC camera feed format
D nsv Nullsoft Streaming Video
E null raw null video format
DE nut NUT format
D nuv NuppelVideo format
DE ogg Ogg
DE oma Sony OpenMG audio
DE oss Open Sound System playback
D pmp Playstation Portable PMP format
E psp PSP MP4 format
D psxstr Sony Playstation STR format
D pva TechnoTrend PVA file and stream format
D qcp QCP format
D r3d REDCODE R3D format
DE rawvideo raw video format
E rcv VC-1 test bitstream
D rl2 RL2 format
DE rm RealMedia format
D rpl RPL/ARMovie format
DE rso Lego Mindstorms RSO format
DE rtp RTP output format
DE rtsp RTSP output format
DE s16be PCM signed 16 bit big-endian format
DE s16le PCM signed 16 bit little-endian format
DE s24be PCM signed 24 bit big-endian format
DE s24le PCM signed 24 bit little-endian format
DE s32be PCM signed 32 bit big-endian format
DE s32le PCM signed 32 bit little-endian format
DE s8 PCM signed 8 bit format
DE sap SAP output format
D sdp SDP
E segment segment muxer
D shn raw Shorten
D siff Beam Software SIFF
DE smjpeg Loki SDL MJPEG
D smk Smacker video
D sol Sierra SOL format
DE sox SoX native format
DE spdif IEC 61937 (used on S/PDIF - IEC958)
DE srt SubRip subtitle format
E svcd MPEG-2 PS format (VOB)
DE swf Flash format
D thp THP
D tiertexseq Tiertex Limited SEQ format
D tmv 8088flex TMV
DE truehd raw TrueHD
D tta True Audio
D tty Tele-typewriter
D txd Renderware TeXture Dictionary
DE u16be PCM unsigned 16 bit big-endian format
DE u16le PCM unsigned 16 bit little-endian format
DE u24be PCM unsigned 24 bit big-endian format
DE u24le PCM unsigned 24 bit little-endian format
DE u32be PCM unsigned 32 bit big-endian format
DE u32le PCM unsigned 32 bit little-endian format
DE u8 PCM unsigned 8 bit format
D vc1 raw VC-1
D vc1test VC-1 test bitstream format
E vcd MPEG-1 System format (VCD)
D video4linux2 Video4Linux2 device grab
D vmd Sierra VMD format
E vob MPEG-2 PS format (VOB)
DE voc Creative Voice file format
D vqf Nippon Telegraph and Telephone Corporation (NTT) TwinVQ
D w64 Sony Wave64 format
DE wav WAV format
D wc3movie Wing Commander III movie format
E webm WebM file format
D wsaud Westwood Studios audio format
D wsvqa Westwood Studios VQA format
D wtv Windows Television (WTV)
D wv WavPack
D x11grab X11grab
D xa Maxis XA File Format
D xmv Microsoft XMV
D xwma Microsoft xWMA
D yop Psygnosis YOP Format
DE yuv4mpegpipe YUV4MPEG pipe format
The file produced when I use:
sound.export("mashup.mp3", format="mp3)"
is unplayable. Here is the output from
$ avplay
Exporting to wav however does work.