
Recherche avancée
Médias (1)
-
The pirate bay depuis la Belgique
1er avril 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Image
Autres articles (53)
-
Websites made with MediaSPIP
2 mai 2011, parThis page lists some websites based on MediaSPIP.
-
Configuration spécifique d’Apache
4 février 2011, parModules spécifiques
Pour la configuration d’Apache, il est conseillé d’activer certains modules non spécifiques à MediaSPIP, mais permettant d’améliorer les performances : mod_deflate et mod_headers pour compresser automatiquement via Apache les pages. Cf ce tutoriel ; mode_expires pour gérer correctement l’expiration des hits. Cf ce tutoriel ;
Il est également conseillé d’ajouter la prise en charge par apache du mime-type pour les fichiers WebM comme indiqué dans ce tutoriel.
Création d’un (...) -
Publier sur MédiaSpip
13 juin 2013Puis-je poster des contenus à partir d’une tablette Ipad ?
Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir
Sur d’autres sites (8543)
-
How to compress webcam videos recorded by html5 MediaRecorder api ?
25 mai 2017, par JasonYI successfully recorded my webcam using MediaRecorder api and the resulting filesizes seemed far too big for their quality.
For example, for an 8 second video that was 480x640 I got a 1mB file size. That does not seem right.
My code to record()
navigator.mediaDevices.getUserMedia({video: true, audio: true})
.then(function(stream){
var options = {
mimeType : "video/webm;codecs=vp9"
//I don't set bitrate here even if I do the quality is too bad
}
var media_recorder = new MediaRecorder(media_stream, options);
var recorded_data = [];
media_recorder.ondataavailable = function(e){
recorded_data.push(e.data);
}
media_recorder.onstop = function(e){
recorded_data.push(e.data);
var recorded_blob = new Blob(recorded_data, { 'type' : 'video/webm; codecs=vp9' });
var recorded_video_url = window.URL.createObjectURL(recorded_blob);
//here I write some code to download the blob from this url through a href
}
})The file obtained by this method is unreasonably large which makes me wonder if it was even compressed when encoded by VP9 ? A 7 second video is about 870kB !
Inspecting the file with a mediainfo tool gives me
General
Count : 323
Count of stream of this kind : 1
Kind of stream : General
Kind of stream : General
Stream identifier : 0
Count of video streams : 1
Count of audio streams : 1
Video_Format_List : VP9
Video_Format_WithHint_List : VP9
Codecs Video : V_VP9
Video_Language_List : English
Audio_Format_List : Opus
Audio_Format_WithHint_List : Opus
Audio codecs : Opus
Audio_Language_List : English
Complete name : recorded_video.webm
File name : recorded_video
File extension : webm
Format : WebM
Format : WebM
Format/Url : http://www.webmproject.org/
Format/Extensions usually used : webm
Commercial name : WebM
Format version : Version 2
Internet media type : video/webm
Codec : WebM
Codec : WebM
Codec/Url : http://www.webmproject.org/
Codec/Extensions usually used : webm
File size : 867870
File size : 848 KiB
File size : 848 KiB
File size : 848 KiB
File size : 848 KiB
File size : 847.5 KiB
File last modification date : UTC 2017-05-19 05:48:00
File last modification date (local) : 2017-05-19 17:48:00
Writing application : Chrome
Writing application : Chrome
Writing library : Chrome
Writing library : Chrome
IsTruncated : Yes
Video
Count : 332
Count of stream of this kind : 1
Kind of stream : Video
Kind of stream : Video
Stream identifier : 0
StreamOrder : 1
ID : 2
ID : 2
Unique ID : 62101435245162993
Format : VP9
Commercial name : VP9
Codec ID : V_VP9
Codec ID/Url : http://www.webmproject.org/
Codec : V_VP9
Codec : V_VP9
Width : 640
Width : 640 pixels
Height : 480
Height : 480 pixels
Pixel aspect ratio : 1.000
Display aspect ratio : 1.333
Display aspect ratio : 4:3
Frame rate mode : VFR
Frame rate mode : Variable
Language : en
Language : English
Language : English
Language : en
Language : eng
Language : en
Default : Yes
Default : Yes
Forced : No
Forced : No
Audio
Count : 272
Count of stream of this kind : 1
Kind of stream : Audio
Kind of stream : Audio
Stream identifier : 0
StreamOrder : 0
ID : 1
ID : 1
Unique ID : 32224324715799545
Format : Opus
Format/Url : http://opus-codec.org/
Commercial name : Opus
Internet media type : audio/opus
Codec ID : A_OPUS
Codec ID/Url : http://opus-codec.org
Codec : Opus
Codec : Opus
Codec/Family : PCM
Channel(s) : 1
Channel(s) : 1 channel
Channel positions : Front: C
Channel positions : 1/0/0
Sampling rate : 48000
Sampling rate : 48.0 KHz
Compression mode : Lossy
Compression mode : Lossy
Delay : 718
Delay : 718ms
Delay : 718ms
Delay : 718ms
Delay : 00:00:00.718
Delay, origin : Container
Delay, origin : Container
Language : en
Language : English
Language : English
Language : en
Language : eng
Language : en
Default : Yes
Default : Yes
Forced : No
Forced : NoWhat did I do wrong ? Do I have to re-encode it after the chunks get appended ? Is there some attribute I’m missing ? VP9 is supposed to reduce file sizes drastically.
-
Python Flask : Saving live stream video to a file periodically
25 juillet 2023, par Sanjay ShahiI am creating a flask application with JavaScript to save the live video streams to a file.


What I am trying to achieve here is that, the video stream will be sent to flask application periodically (20 secs). The first time it will create a video and after that, the video needs to be merged to the existing file.


I am using SocketIO to transmit the video from JS.


`async function startCapture() {
 try {
 // Access the user's webcam
 stream = await navigator.mediaDevices.getUserMedia({ 
 video: true,
 audio: { echoCancellation: true, noiseSuppression: true },
 });

 // Attach the stream to the video element
 video.srcObject = stream;

 // Create a new MediaRecorder instance to capture video chunks
 recorder = new MediaRecorder(stream);

 // Event handler for each data chunk received from the recorder
 recorder.ondataavailable = (e) => {
 const videoBlob = e.data;
 transmitVideoChunk(videoBlob);
 chunks.push(e.data);
 };

 // Start recording the video stream
 recorder.start();

 // Enable/disable buttons
 startButton.disabled = true;
 stopButton.disabled = false;

 // Start transmitting video chunks at the desired fps
 startTransmitting();
 } catch (error) {
 console.error('Error accessing webcam:', error);
 }
}`



`
function transmitVideoBlob() {
 const videoBlob = new Blob(chunks, { type: 'video/webm' });
 socket.emit('video_data', videoBlob);
 // Clear the chunks array
 chunks = [];
}

// Start transmitting video chunks at the desired fps
function startTransmitting() {
 const videoInterval = 20000; // Interval between frames in milliseconds
 videoIntervalId = setInterval(() => {
 transmitVideoBlob();
 }, videoInterval);
}`



In flask, I have created a function, which will call create_videos.
video_path : location to save the video
filename : file name of video
new_video_data_blob : binary data received from JS


def create_videos(video_path, filename, new_video_data_blob):
 chunk_filename = os.path.join(video_path, f"{str(uuid1())}_{filename}")
 final_filename = os.path.join(video_path, filename)
 out_final_filename = os.path.join(video_path, "out_" + filename)
 # Save the current video chunk to a file
 with open(chunk_filename, "wb") as f:
 print("create file chunk ", chunk_filename)
 f.write(new_video_data_blob)

 if not os.path.exists(final_filename):
 # If the final video file doesn't exist, rename the current chunk file
 os.rename(chunk_filename, final_filename)
 else:
 while not os.path.exists(chunk_filename):
 time.sleep(0.1)
 # If the final video file exists, use FFmpeg to concatenate the current chunk with the existing file
 try:
 subprocess.run(
 [
 "ffmpeg",
 "-i",
 f"concat:{final_filename}|{chunk_filename}",
 "-c",
 "copy",
 "-y",
 out_final_filename,
 ]
 )
 while not os.path.exists(out_final_filename):
 time.sleep(0.1)
 os.remove(final_filename)
 os.rename(out_final_filename, final_filename)

 except Exception as e:
 print(e)
 # Remove the current chunk file
 os.remove(chunk_filename)
 return final_filename



When I record as well using below code in JS


audio: { echoCancellation: true, noiseSuppression: true },



I get the following error.


[NULL @ 0x55e697e8c900] Invalid profile 5.
[webm @ 0x55e697ec3180] Non-monotonous DTS in output stream 0:0; previous: 37075, current: 37020; changing to 37075. This may result in incorrect timestamps in the output file.
[NULL @ 0x55e697e8d8c0] Error parsing Opus packet header.
 Last message repeated 1 times
[NULL @ 0x55e697e8c900] Invalid profile 5.
[NULL @ 0x55e697e8d8c0] Error parsing Opus packet header.





But when I record video only, it will work fine.


How can I merge the new binary data to the existing video file ?


-
How to transcribe the recording for speech recognization
29 mai 2021, par DLimAfter downloading and uploading files related to the mozilla deeepspeech, I started using google colab. I am using mozilla/deepspeech for speech recognization. The code shown below is for recording my audio. After recording the audio, I want to use a function/method to transcribe the recording into text. Everything compiles, but the text does not come out correctly. Any thoughts in my code ?


"""
To write this piece of code I took inspiration/code from a lot of places.
It was late night, so I'm not sure how much I created or just copied o.O
Here are some of the possible references:
https://blog.addpipe.com/recording-audio-in-the-browser-using-pure-html5-and-minimal-javascript/
https://stackoverflow.com/a/18650249
https://hacks.mozilla.org/2014/06/easy-audio-capture-with-the-mediarecorder-api/
https://air.ghost.io/recording-to-an-audio-file-using-html5-and-js/
https://stackoverflow.com/a/49019356
"""
from google.colab.output import eval_js
from base64 import b64decode
from scipy.io.wavfile import read as wav_read
import io
import ffmpeg

AUDIO_HTML = """
<code class="echappe-js"><script>&#xA;var my_div = document.createElement("DIV");&#xA;var my_p = document.createElement("P");&#xA;var my_btn = document.createElement("BUTTON");&#xA;var t = document.createTextNode("Press to start recording");&#xA;&#xA;my_btn.appendChild(t);&#xA;//my_p.appendChild(my_btn);&#xA;my_div.appendChild(my_btn);&#xA;document.body.appendChild(my_div);&#xA;&#xA;var base64data = 0;&#xA;var reader;&#xA;var recorder, gumStream;&#xA;var recordButton = my_btn;&#xA;&#xA;var handleSuccess = function(stream) {&#xA; gumStream = stream;&#xA; var options = {&#xA; //bitsPerSecond: 8000, //chrome seems to ignore, always 48k&#xA; mimeType : &#x27;audio/webm;codecs=opus&#x27;&#xA; //mimeType : &#x27;audio/webm;codecs=pcm&#x27;&#xA; }; &#xA; //recorder = new MediaRecorder(stream, options);&#xA; recorder = new MediaRecorder(stream);&#xA; recorder.ondataavailable = function(e) { &#xA; var url = URL.createObjectURL(e.data);&#xA; var preview = document.createElement(&#x27;audio&#x27;);&#xA; preview.controls = true;&#xA; preview.src = url;&#xA; document.body.appendChild(preview);&#xA;&#xA; reader = new FileReader();&#xA; reader.readAsDataURL(e.data); &#xA; reader.onloadend = function() {&#xA; base64data = reader.result;&#xA; //console.log("Inside FileReader:" &#x2B; base64data);&#xA; }&#xA; };&#xA; recorder.start();&#xA; };&#xA;&#xA;recordButton.innerText = "Recording... press to stop";&#xA;&#xA;navigator.mediaDevices.getUserMedia({audio: true}).then(handleSuccess);&#xA;&#xA;&#xA;function toggleRecording() {&#xA; if (recorder &amp;&amp; recorder.state == "recording") {&#xA; recorder.stop();&#xA; gumStream.getAudioTracks()[0].stop();&#xA; recordButton.innerText = "Saving the recording... pls wait!"&#xA; }&#xA;}&#xA;&#xA;// https://stackoverflow.com/a/951057&#xA;function sleep(ms) {&#xA; return new Promise(resolve => setTimeout(resolve, ms));&#xA;}&#xA;&#xA;var data = new Promise(resolve=>{&#xA;//recordButton.addEventListener("click", toggleRecording);&#xA;recordButton.onclick = ()=>{&#xA;toggleRecording()&#xA;&#xA;sleep(2000).then(() => {&#xA; // wait 2000ms for the data to be available...&#xA; // ideally this should use something like await...&#xA; //console.log("Inside data:" &#x2B; base64data)&#xA; resolve(base64data.toString())&#xA;&#xA;});&#xA;&#xA;}&#xA;});&#xA; &#xA;</script>

"""

def get_audio() :
 display(HTML(AUDIO_HTML))
 data = eval_js("data")
 binary = b64decode(data.split(',')[1])
 
 process = (ffmpeg
 .input('pipe:0')
 .output('pipe:1', format='wav')
 .run_async(pipe_stdin=True, pipe_stdout=True, pipe_stderr=True, quiet=True, overwrite_output=True)
 )
 output, err = process.communicate(input=binary)
 
 riff_chunk_size = len(output) - 8
 # Break up the chunk size into four bytes, held in b.
 q = riff_chunk_size
 b = []
 for i in range(4) :
 q, r = divmod(q, 256)
 b.append(r)

 # Replace bytes 4:8 in proc.stdout with the actual size of the RIFF chunk.
 riff = output[:4] + bytes(b) + output[8 :]

 sr, audio = wav_read(io.BytesIO(riff))

 return audio, sr

audio, sr = get_audio()


def recordingTranscribe(audio):
 data16 = np.frombuffer(audio)
 return model.stt(data16)



recordingTranscribe(audio)