
Advanced search
Medias (16)
-
#7 Ambience
16 October 2011, by
Updated: June 2015
Language: English
Type: Audio
-
#6 Teaser Music
16 October 2011, by
Updated: February 2013
Language: English
Type: Audio
-
#5 End Title
16 October 2011, by
Updated: February 2013
Language: English
Type: Audio
-
#3 The Safest Place
16 October 2011, by
Updated: February 2013
Language: English
Type: Audio
-
#4 Emo Creates
15 October 2011, by
Updated: February 2013
Language: English
Type: Audio
-
#2 Typewriter Dance
15 October 2011, by
Updated: February 2013
Language: English
Type: Audio
Other articles (70)
-
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 September 2013, byCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo; l’ajout d’une bannière l’ajout d’une image de fond;
-
Ecrire une actualité
21 June 2013, byPrésentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
Vous pouvez personnaliser le formulaire de création d’une actualité.
Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...) -
Publier sur MédiaSpip
13 June 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
On other websites (11427)
-
How to transcribe the recording for speech recognization
29 May 2021, by 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)



-
Rust Win32 FFI: User-mode data execution prevention (DEP) violation
28 April 2022, by TheElixI'm trying to pass a ID3D11Device instance from Rust to a C FFI Library (FFMPEG).


I made this sample code:


pub fn create_d3d11_device(&mut self, device: &mut Box, context: &mut Box) {
 let av_device : Box<avbufferref> = self.alloc(HwDeviceType::D3d11va);
 unsafe {
 let device_context = Box::from_raw(av_device.data as *mut AVHWDeviceContext);
 let mut d3d11_device_context = Box::from_raw(device_context.hwctx as *mut AVD3D11VADeviceContext);
 d3d11_device_context.device = device.as_mut() as *mut _;
 d3d11_device_context.device_context = context.as_mut() as *mut _;
 let avp = Box::into_raw(av_device);
 av_hwdevice_ctx_init(avp);
 self.av_hwdevice = Some(Box::from_raw(avp));
 }
 }
</avbufferref>


On the Rust side the Device does work, but on the C side, when FFMEPG calls
ID3D11DeviceContext_QueryInterface
the app crashes with the following error:Exception 0xc0000005 encountered at address 0x7ff9fb99ad38: User-mode data execution prevention (DEP) violation at location 0x7ff9fb99ad38


The address is actually the pointer for the lpVtbl of QueryInterface, like seen here:


The disassembly of the address also looks correct (this is done on an another debugging session):


(lldb) disassemble --start-address 0x00007ffffdf3ad38
 0x7ffffdf3ad38: addb %ah, 0x7ffffd(%rdi,%riz,8)
 0x7ffffdf3ad3f: addb %al, (%rax)
 0x7ffffdf3ad41: movabsl -0x591fffff80000219, %eax
 0x7ffffdf3ad4a: outl %eax, $0xfd



Do you have any pointer to debug this further?


EDIT: I made a Minimal Reproducion Sample. Interestingly this does not causes a DEP Violation, but simply a Segfault.


On the C side:


int test_ffi(ID3D11Device *device){
 ID3D11DeviceContext *context;
 device->lpVtbl->GetImmediateContext(device, &context);
 if (!context) return 1;
 return 0;
}



On the Rust side:


unsafe fn main_rust(){
 let mut device = None;
 let mut device_context = None;
 let _ = match windows::Win32::Graphics::Direct3D11::D3D11CreateDevice(None, D3D_DRIVER_TYPE_HARDWARE, OtherHinstance::default(), D3D11_CREATE_DEVICE_DEBUG, &[], D3D11_SDK_VERSION, &mut device, std::ptr::null_mut(), &mut device_context) {
 Ok(e) => e,
 Err(e) => panic!("Creation Failed: {}", e)
 };
 let mut device = match device {
 Some(e) => e,
 None => panic!("Creation Failed2")
 };
 let mut f2 : ID3D11Device = transmute_copy(&device); //Transmuting the WinAPI into a bindgen ID3D11Device
 test_ffi(&mut f2);
}



The bindgen build.rs:


extern crate bindgen;

use std::env;
use std::path::PathBuf;

fn main() {
 // Tell cargo to tell rustc to link the system bzip2
 // shared library.
 println!("cargo:rustc-link-lib=ffi_demoLIB");
 println!("cargo:rustc-link-lib=d3d11");

 // Tell cargo to invalidate the built crate whenever the wrapper changes
 println!("cargo:rerun-if-changed=library.h");

 // The bindgen::Builder is the main entry point
 // to bindgen, and lets you build up options for
 // the resulting bindings.
 let bindings = bindgen::Builder::default()
 // The input header we would like to generate
 // bindings for.
 .header("library.h")
 // Tell cargo to invalidate the built crate whenever any of the
 // included header files changed.
 .parse_callbacks(Box::new(bindgen::CargoCallbacks))
 .blacklist_type("_IMAGE_TLS_DIRECTORY64")
 .blacklist_type("IMAGE_TLS_DIRECTORY64")
 .blacklist_type("PIMAGE_TLS_DIRECTORY64")
 .blacklist_type("IMAGE_TLS_DIRECTORY")
 .blacklist_type("PIMAGE_TLS_DIRECTORY")
 // Finish the builder and generate the bindings.
 .generate()
 // Unwrap the Result and panic on failure.
 .expect("Unable to generate bindings");

 // Write the bindings to the $OUT_DIR/bindings.rs file.
 let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
 bindings
 .write_to_file(out_path.join("bindings.rs"))
 .expect("Couldn't write bindings!");
}



The Complete Repo can be found over here: https://github.com/TheElixZammuto/demo-ffi


-
FFmpeg: unspecified pixel format when opening video with custom context
14 February 2021, by PedroI am trying to decode a video with a custom context. The purpose is that I want to decode the video directly from memory. In the following code, I am reading from file in the
read
function passed toavio_alloc_context
- but this is just for testing purposes.


I think I've read any post there is on Stackoverflow or on any other website related to this topic. At least I definitely tried my best to do so. While there is much in common, the details differ: people set different flags, some say
av_probe_input_format
is required, some say it isn't, etc. And for some reason nothing works for me.


My problem is that the pixel format is unspecified (see output below), which is why I run into problems later when calling
sws_getContext
. I checkedpFormatContext->streams[videoStreamIndex]->codec->pix_fmt
, and it is -1.


Please note my comments
// things I tried
and// seems not to help
in the code. I think, the answer might be hidden somehwere there. I tried many combinations of hints that I've read so far, but I am missing a detail I guess.


The problem is not the video file, because when I go the standard way and just call
avformat_open_input(&pFormatContext, pFilePath, NULL, NULL)
without a custom context, everything runs fine.


The code compiles and runs as is.



#include <libavformat></libavformat>avformat.h>
#include 
#include 

FILE *f;

static int read(void *opaque, uint8_t *buf, int buf_size) {
 if (feof(f)) return -1;
 return fread(buf, 1, buf_size, f);
}

int openVideo(const char *pFilePath) {
 const int bufferSize = 32768;
 int ret;

 av_register_all();

 f = fopen(pFilePath, "rb");
 uint8_t *pBuffer = (uint8_t *) av_malloc(bufferSize + AVPROBE_PADDING_SIZE);
 AVIOContext *pAVIOContext = avio_alloc_context(pBuffer, bufferSize, 0, NULL,
 &read, NULL, NULL);

 if (!f || !pBuffer || !pAVIOContext) {
 printf("error: open / alloc failed\n");
 // cleanup...
 return 1;
 }

 AVFormatContext *pFormatContext = avformat_alloc_context();
 pFormatContext->pb = pAVIOContext;

 const int readBytes = read(NULL, pBuffer, bufferSize);

 printf("readBytes = %i\n", readBytes);

 if (readBytes <= 0) {
 printf("error: read failed\n");
 // cleanup...
 return 2;
 }

 if (fseek(f, 0, SEEK_SET) != 0) {
 printf("error: fseek failed\n");
 // cleanup...
 return 3;
 }

 // required for av_probe_input_format
 memset(pBuffer + readBytes, 0, AVPROBE_PADDING_SIZE);

 AVProbeData probeData;
 probeData.buf = pBuffer;
 probeData.buf_size = readBytes;
 probeData.filename = "";
 probeData.mime_type = NULL;

 pFormatContext->iformat = av_probe_input_format(&probeData, 1);

 // things I tried:
 //pFormatContext->flags = AVFMT_FLAG_CUSTOM_IO;
 //pFormatContext->iformat->flags |= AVFMT_NOFILE;
 //pFormatContext->iformat->read_header = NULL;

 // seems not to help (therefore commented out here):
 AVDictionary *pDictionary = NULL;
 //av_dict_set(&pDictionary, "analyzeduration", "8000000", 0);
 //av_dict_set(&pDictionary, "probesize", "8000000", 0);

 if ((ret = avformat_open_input(&pFormatContext, "", NULL, &pDictionary)) < 0) {
 char buffer[4096];
 av_strerror(ret, buffer, sizeof(buffer));
 printf("error: avformat_open_input failed: %s\n", buffer);
 // cleanup...
 return 4;
 }

 printf("retrieving stream information...\n");

 if ((ret = avformat_find_stream_info(pFormatContext, NULL)) < 0) {
 char buffer[4096];
 av_strerror(ret, buffer, sizeof(buffer));
 printf("error: avformat_find_stream_info failed: %s\n", buffer);
 // cleanup...
 return 5;
 }

 printf("nb_streams = %i\n", pFormatContext->nb_streams);

 // further code...

 // cleanup...
 return 0;
}

int main() {
 openVideo("video.mp4");
 return 0;
}




This is the output that I get:

readBytes = 32768

retrieving stream information...

[mov,mp4,m4a,3gp,3g2,mj2 @ 0xdf8d20] stream 0, offset 0x30: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0xdf8d20] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 640x360, 351 kb/s): unspecified pixel format

Consider increasing the value for the 'analyzeduration' and 'probesize' options

nb_streams = 2


UPDATE:

Thanks to WLGfx, here is the solution: The only thing that was missing was the seek function. Apparently, implementing it is mandatory for decoding. It is important to return the new offset - and not 0 in case of success (some solutions found in the web just return the return value of fseek, and that is wrong). Here is the minimal solution that made it work:


static int64_t seek(void *opaque, int64_t offset, int whence) {
 if (whence == SEEK_SET && fseek(f, offset, SEEK_SET) == 0) {
 return offset;
 }
 // handling AVSEEK_SIZE doesn't seem mandatory
 return -1;
}




Of course, the call to
avio_alloc_context
needs to be adapted accordingly:


AVIOContext *pAVIOContext = avio_alloc_context(pBuffer, bufferSize, 0, NULL,
 &read, NULL, &seek);