
Recherche avancée
Médias (21)
-
1,000,000
27 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Demon Seed
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
The Four of Us are Dying
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Corona Radiata
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Lights in the Sky
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Head Down
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
Autres articles (38)
-
Websites made with MediaSPIP
2 mai 2011, parThis page lists some websites based on MediaSPIP.
-
Creating farms of unique websites
13 avril 2011, parMediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...) -
Les autorisations surchargées par les plugins
27 avril 2010, parMediaspip core
autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs
Sur d’autres sites (7674)
-
Python : mp3 to alsaaudio through ffmpeg pipe and wave.open(f,'r')
16 avril 2015, par user2754098I’m trying to decode mp3 to wav using ffmpeg :
import alsaaudio
import wave
from subprocess import Popen, PIPE
with open('filename.mp3', 'rb') as infile:
p=Popen(['ffmpeg', '-i', '-', '-f', 'wav', '-'], stdin=infile, stdout=PIPE)
...Next i want redirect data from p.stdout.read() to wave.open(file, r) to use readframes(n) and other methods. But i cannot because ’file’ in wave.open(file,’r’) can be only name of file or an open file pointer.
...
file = wave.open(p.stdout.read(),'r')
card='default'
device=alsaaudio.PCM(card=card)
device.setchannels(file.getnchannels())
device.setrate(file.getframerate())
device.setformat(alsaaudio.PCM_FORMAT_S16_LE)
device.setsetperiodsize(320)
data = file.readframes(320)
while data:
device.write(data)
data = file.readframes(320)I got :
TypeError: file() argument 1 must be encoded string without NULL bytes, not str
So is it possible to handle data from p.stdout.read() by wave.open() ?
Making temporary .wav file isn’t solution.Sorry for my english.
Thanks.UPDATE
Thanks to PM 2Ring for hit about io.BytesIO.
However resulting code does not work.
import alsaaudio
import wave
from subprocess import Popen, PIPE
with open('sometrack.mp3', 'rb') as infile:
p=Popen(['ffmpeg', '-i', '-', '-f','wav', '-'], stdin=infile , stdout=PIPE , stderr=PIPE)
fobj = io.BytesIO(p.stdout.read())
fwave = wave.open(fobj, 'rb')Trace :
File "./script.py", line x, in <module>
fwave = wave.open(fobj, 'rb')
File "/usr/lib/python2.7/wave.py", line x, in open
return Wave_read(f)
File "/usr/lib/python2.7/wave.py", line x, in __init__
self.initfp(f)
File "/usr/lib/python2.7/wave.py", line x, in initfp
raise Error, 'not a WAVE file'
wave.Error: not a WAVE file
</module>From /usr/lib/python2.7/wave.py :
...
self._file = Chunk(file, bigendian = 0)
if self._file.getname() != 'RIFF':
raise Error, 'file does not start with RIFF id'
if self._file.read(4) != 'WAVE':
raise Error, 'not a WAVE file'
...Checking has been failed due to ’bad’ self._file object.
Inside /usr/lib/python2.7/chunk.py i have found a source of problem :
...
try:
self.chunksize = struct.unpack(strflag+'L', file.read(4))[0]
except struct.error:
raise EOFError
...Because struct.unpack(strflag+’L’, file.read(4))[0] returns 0.
But this function works correct.As specified here :
"5-8 bytes - File size(integer)
Size of the overall file - 8 bytes, in bytes (32-bit integer). Typically, you’d fill this in after creation."
That’s why my script doesn’t work. wave.open and other functions cannot handle my file object because self.chunksize = 0. Looks like ffmpeg cannot insert File size when using PIPE.SOLUTION
It’s simple.
I’ve changed init function of Chunk class :After :
...
try:
self.chunksize = struct.unpack(strflag+'L', file.read(4))[0]
except struct.error:
raise EOFError
...Before :
...
try:
self.chunksize = struct.unpack(strflag+'L', file.read(4))[0]
currtell = file.tell()
if self.chunksize == 0:
file.seek(0)
file.read(currtell)
self.chunksize = len(file.read())-4
file.seek(0)
file.read(currtell)
except struct.error:
raise EOFError
...Of course editing of original module is bad idia. So I’ve create custom forks for 2 classes Chunk and Wave_read.
Working but unstable full code you can find here.
Sorry for my awful english.
Thanks.
-
Python : mp3 to alsaaudio through ffmpeg pipe and wave.open(f,'r')
3 juillet 2017, par user2754098I’m trying to decode mp3 to wav using ffmpeg :
import alsaaudio
import wave
from subprocess import Popen, PIPE
with open('filename.mp3', 'rb') as infile:
p=Popen(['ffmpeg', '-i', '-', '-f', 'wav', '-'], stdin=infile, stdout=PIPE)
...Next i want redirect data from p.stdout.read() to wave.open(file, r) to use readframes(n) and other methods. But i cannot because ’file’ in wave.open(file,’r’) can be only name of file or an open file pointer.
...
file = wave.open(p.stdout.read(),'r')
card='default'
device=alsaaudio.PCM(card=card)
device.setchannels(file.getnchannels())
device.setrate(file.getframerate())
device.setformat(alsaaudio.PCM_FORMAT_S16_LE)
device.setsetperiodsize(320)
data = file.readframes(320)
while data:
device.write(data)
data = file.readframes(320)I got :
TypeError: file() argument 1 must be encoded string without NULL bytes, not str
So is it possible to handle data from p.stdout.read() by wave.open() ?
Making temporary .wav file isn’t solution.Sorry for my english.
Thanks.UPDATE
Thanks to PM 2Ring for hit about io.BytesIO.
However resulting code does not work.
import alsaaudio
import wave
from subprocess import Popen, PIPE
with open('sometrack.mp3', 'rb') as infile:
p=Popen(['ffmpeg', '-i', '-', '-f','wav', '-'], stdin=infile , stdout=PIPE , stderr=PIPE)
fobj = io.BytesIO(p.stdout.read())
fwave = wave.open(fobj, 'rb')Trace :
File "./script.py", line x, in <module>
fwave = wave.open(fobj, 'rb')
File "/usr/lib/python2.7/wave.py", line x, in open
return Wave_read(f)
File "/usr/lib/python2.7/wave.py", line x, in __init__
self.initfp(f)
File "/usr/lib/python2.7/wave.py", line x, in initfp
raise Error, 'not a WAVE file'
wave.Error: not a WAVE file
</module>From /usr/lib/python2.7/wave.py :
...
self._file = Chunk(file, bigendian = 0)
if self._file.getname() != 'RIFF':
raise Error, 'file does not start with RIFF id'
if self._file.read(4) != 'WAVE':
raise Error, 'not a WAVE file'
...Checking has been failed due to ’bad’ self._file object.
Inside /usr/lib/python2.7/chunk.py i have found a source of problem :
...
try:
self.chunksize = struct.unpack(strflag+'L', file.read(4))[0]
except struct.error:
raise EOFError
...Because struct.unpack(strflag+’L’, file.read(4))[0] returns 0.
But this function works correct.As specified here :
"5-8 bytes - File size(integer)
Size of the overall file - 8 bytes, in bytes (32-bit integer). Typically, you’d fill this in after creation."
That’s why my script doesn’t work. wave.open and other functions cannot handle my file object because self.chunksize = 0. Looks like ffmpeg cannot insert File size when using PIPE.SOLUTION
It’s simple.
I’ve changed init function of Chunk class :After :
...
try:
self.chunksize = struct.unpack(strflag+'L', file.read(4))[0]
except struct.error:
raise EOFError
...Before :
...
try:
self.chunksize = struct.unpack(strflag+'L', file.read(4))[0]
currtell = file.tell()
if self.chunksize == 0:
file.seek(0)
file.read(currtell)
self.chunksize = len(file.read())-4
file.seek(0)
file.read(currtell)
except struct.error:
raise EOFError
...Of course editing of original module is bad idia. So I’ve create custom forks for 2 classes Chunk and Wave_read.
Working but unstable full code you can find here.
Sorry for my awful english.
Thanks.
-
python 3 using ffmpeg in a subprocess getting stderr decoding error
4 mai 2024, par jdauthreI am running ffmpeg as a subprocess and using the stderr to get various bits of data like the subtitles stream Id's. It works fine for most videos, but one with japanese subtitles results in an error :


'charmap' codec can't decode byte in position xxx : character maps to


Much googling suggests the problem is that the japanese requires unicode, whereas English does not. Solutions offered refer to problems with files, and I cannot find a way of doing the same with the stderr. Relevent Code is below :


command = [ffmpeg,"-y","-i",fileSelected,"-acodec","pcm_s16le",
 "-vn","-t","3", "-f", "null","-"]
print(command) 
proc = subprocess.Popen(command,stderr=PIPE,Jstdin=subprocess.PIPE,
 universal_newlines=True,startupinfo=startupinfo)
 
stream = "" 
for line in proc.stderr:
 try:
 print("line",line)
 except exception as error:
 print("print",error)
 line = line[:-1]
 if "Stream #" in line:
 estream = line.split("#",1)[1]
 estream =estream.split(" (",1)[0]
 print("estream",estream)
 stream = stream + estream +"\n" #.split("(",1)[0] 
 stream = stream + estream +"\n"