Beispiel #1
0
def initSongs():
    """ This function creates wav files from MP3s and Song objects into 'songs' list. Used in LTunez """
    global songs
    mp3_filenames = os.listdir("MP3s")
    
    for mp3_filename in mp3_filenames:
        mp3_path = "MP3s/" + mp3_filename
        wav_filename = os.path.splitext(mp3_filename)[0] + ".wav" # wav filename is the same as mp3 except the extension
        wav_path = "Wavs/" + wav_filename
        
        # construct and run ffmpeg command
        input_mp3 = Input(mp3_path)
        output_wav = Output(wav_path, AudioCodec("pcm_mulaw"))
        opt_dict = dict([("-ar", "8000"), ("-ac", "1"), ("-ab", "64000")]) # sampling rate 8000 Hz, 1 audio channel (mono), bitrate 64kbits/s
        opt = options.Option(opt_dict)
        ffmpeg_command = FFmpeg("ffmpeg", input_mp3, opt, output_wav)
        ffmpeg_command.run()
        print "Playlist Server: File created: '" + wav_filename + "'"
        
        mp3header = eyeD3.Mp3AudioFile(mp3_path)
        length = str(mp3header.getPlayTime())
        tag = eyeD3.Tag()
        tag.link(mp3_path)
        song = Song(length, tag.getArtist(), tag.getTitle(), wav_path)
        songs.append(song)
Beispiel #2
0
    def test_stream_specifier(self):
        input = Input('/old')
        stream1 = Stream()
        stream1.add_parameter('-threads', '0')
        output = Output('/new', stream1)

        ffmpeg = FFmpeg('ffmpeg', input, output)
        #ffmpeg.add_parameter('-threads', '0')
        self.assertEqual(list(ffmpeg), ['ffmpeg', '-i', '/old', '-threads', '0', '/new'])

        stream1 = Stream(1)
        stream1.add_parameter('-threads', '0')
        output = Output('/new', stream1)

        ffmpeg = FFmpeg('ffmpeg', input, output)
        self.assertEqual(list(ffmpeg), ['ffmpeg', '-i', '/old', '-threads:1', '0', '/new'])

        stream1 = Stream(1, 'v')
        stream1.add_parameter('-threads', '0')
        output = Output('/new', stream1)

        ffmpeg = FFmpeg('ffmpeg', input, output)
        self.assertEqual(list(ffmpeg), ['ffmpeg', '-i', '/old', '-threads:v:1', '0', '/new'])

        stream1 = Stream(stream_type='v')
        stream1.add_parameter('-threads', '0')
        output = Output('/new', stream1)

        ffmpeg = FFmpeg('ffmpeg', input, output)
        self.assertEqual(list(ffmpeg), ['ffmpeg', '-i', '/old', '-threads:v', '0', '/new'])
Beispiel #3
0
    def test_ffmpeg_interface(self):
        input = Input('/old')
        output = Output('/new')

        ffmpeg = FFmpeg('ffmpeg', input, output)
        self.assertEqual(list(ffmpeg), ['ffmpeg', '-i', '/old', '/new'])

        with ffmpeg as process:
            result = list(process.readlines())
            self.assertEqual(result, ['this is a line', 'this too'])
Beispiel #4
0
    def test_ffmpeg_interface(self):
        input = Input('/old')
        output = Output('/new')

        ffmpeg = FFmpeg('ffmpeg', input, output)
        self.assertEqual(list(ffmpeg), ['ffmpeg', '-i', '/old', '/new'])
Beispiel #5
0
"""
from ffmpegwrapper import FFmpeg, Input, Output, AudioCodec


codec = AudioCodec('wav')

input_file = Input('/Users/jw/Desktop/FEBr/cant_hold_us')
output_file = Output('/Users/jw/Desktop/FEBr/cant_hold_us', codec)

FFmpeg('ffmpeg', input_file, output_file)
"""

from ffmpegwrapper import FFmpeg, AudioCodec, Input, Output

input1 = Input("cant_hold_us.mp3")
codec = AudioCodec("pcm_s16le")
output = Output("cant_hold_us.wav", codec)
ffmpeg = FFmpeg("ffmpeg", input1, output)
"""
# If you need the output at converting
with ffmpeg as process:
    for line in process.readlines():
        print line
"""
# If you don't need the output at converting
ffmpeg.run()