Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove default format mp3 #793

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions pydub/audio_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ def _from_safe_wav(cls, file):
file.close()
return obj

def export(self, out_f=None, format='mp3', codec=None, bitrate=None, parameters=None, tags=None, id3v2_version='4',
def export(self, out_f=None, format=None, codec=None, bitrate=None, parameters=None, tags=None, id3v2_version='4',
cover=None):
"""
Export an AudioSegment to a file with given options
Expand All @@ -832,7 +832,9 @@ def export(self, out_f=None, format='mp3', codec=None, bitrate=None, parameters=

format (string)
Format for destination audio file.
('mp3', 'wav', 'raw', 'ogg' or other ffmpeg/avconv supported files)
By default, ffmpeg will guess format from output file extension.
See 'ffmpeg -muxers' for a list of supported output formats.
('mp3', 'wav', 'raw', 'ogg', 'ipod', 'matroska', ...)

codec (string)
Codec used to encode the destination file.
Expand Down Expand Up @@ -864,6 +866,8 @@ def export(self, out_f=None, format='mp3', codec=None, bitrate=None, parameters=
'specify an ffmpeg raw format like format="s16le" instead '
'or call export(format="raw") with no codec or parameters')

output_suffix = os.path.splitext(str(out_f))[1]

out_f, _ = _fd_or_path_or_tempfile(out_f, 'wb+')
out_f.seek(0)

Expand Down Expand Up @@ -900,7 +904,7 @@ def export(self, out_f=None, format='mp3', codec=None, bitrate=None, parameters=
out_f.seek(0)
return out_f

output = NamedTemporaryFile(mode="w+b", delete=False)
output = NamedTemporaryFile(mode="w+b", delete=False, suffix=output_suffix)

# build converter command to export
conversion_command = [
Expand Down Expand Up @@ -952,8 +956,13 @@ def export(self, out_f=None, format='mp3', codec=None, bitrate=None, parameters=
if sys.platform == 'darwin' and codec == 'mp3':
conversion_command.extend(["-write_xing", "0"])

# output options (filename last)
if format:
conversion_command.extend([
"-f", format
])
conversion_command.extend([
"-f", format, output.name, # output options (filename last)
output.name
])

log_conversion(conversion_command)
Expand Down