-
-
Save treeform/2727938 to your computer and use it in GitHub Desktop.
Create HTML5 <audio> compatible files out of MP3 using ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf8 -*- | |
import os | |
import subprocess | |
def create_prelisten_ogg(mp3, ogg): | |
""" | |
Run en-code for a single file | |
Do 48 kbit files for prelisten. | |
""" | |
FFMPEG = os.environ['FFMPEG'] | |
cmdline = [ FFMPEG, '-y', '-i', mp3, '-acodec', 'libvorbis', '-ar', '22050', '-ac', '1', '-ab', '48000', ogg ] | |
return subprocess.call(cmdline) | |
def create_prelisten_aac(mp3, aac): | |
""" | |
Run en-code for a single file | |
Do 48 kbit files for prelisten. | |
""" | |
FFMPEG = os.environ['FFMPEG'] | |
cmdline = [ FFMPEG, '-y', '-i', mp3, '-acodec', 'libfaac', '-ar', '22050', '-ac', '1', '-ab', '48000', aac ] | |
return subprocess.call(cmdline) | |
getBrowserAudioFormat : function(url) { | |
var audio = document.createElement("audio"); | |
var needAAC = audio.canPlayType('audio/mp4; codecs="mp4a.40.5"') !== ""; | |
var needOGG = audio.canPlayType('audio/ogg; codecs="vorbis"') !== ""; | |
if(needOGG) { | |
url = url.replace(".mp3", ".ogg"); | |
} else if(needAAC){ | |
url = url.replace(".mp3", ".m4a"); | |
} else { | |
console.error("Could not detect prelisten audio format support"); | |
} | |
return url; | |
}, | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment