
Recherche avancée
Autres articles (66)
-
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains 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 ;
-
MediaSPIP : Modification des droits de création d’objets et de publication définitive
11 novembre 2010, parPar défaut, MediaSPIP permet de créer 5 types d’objets.
Toujours par défaut les droits de création et de publication définitive de ces objets sont réservés aux administrateurs, mais ils sont bien entendu configurables par les webmestres.
Ces droits sont ainsi bloqués pour plusieurs raisons : parce que le fait d’autoriser à publier doit être la volonté du webmestre pas de l’ensemble de la plateforme et donc ne pas être un choix par défaut ; parce qu’avoir un compte peut servir à autre choses également, (...) -
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 (11226)
-
Can't initialize "h264_mediacodec" for hw accelerated decoding, FFMPEG, Android
27 mars 2024, par Ramil GalinI am trying to create hw accelerated decoding on Android through JNI and following this example but, unfortunately,
avcodec_get_hw_config
returns nullptr.

I have also tried using
avcodec_find_decoder_by_name("h264_mediacodec")
, also returns nullptr.

I built ffmpeg (version 4.4) using this script with the flags :


--enable-jni \
--enable-mediacodec \
--enable-decoder=h264_mediacodec \
--enable-hwaccel=h264_mediacodec \



When configuring build I saw in logs
WARNING: Option --enable-hwaccel=h264_mediacodec did not match anything
, which is actually strange. FFMPEG 4.4 should support hw accelerated decoding using mediacodec.

Edit : (providing minimal reproducible example)


In the JNI method I init input context of decoder and init decoder :


void Decoder::initInputContext(
 const std::string& source,
 AVDictionary* options
 ) { // open input, and allocate format context
 if (
 avformat_open_input(
 &m_inputFormatContext,
 source.c_str(),
 NULL,
 options ? &options : nullptr
 ) < 0
 ) {
 throw FFmpegException(
 fmt::format("Decoder: Could not open source {}", source)
 );
 }
 
 // retrieve stream information
 if (avformat_find_stream_info(m_inputFormatContext, NULL) < 0) {
 throw FFmpegException(
 "Decoder: Could not find stream information"
 );
 }

 // get audio and video streams
 for (size_t i = 0; i < m_inputFormatContext->nb_streams; i++) {
 AVStream* inStream = m_inputFormatContext->streams[i];
 AVCodecParameters* inCodecpar = inStream->codecpar;
 if (
 inCodecpar->codec_type != AVMEDIA_TYPE_AUDIO &&
 inCodecpar->codec_type != AVMEDIA_TYPE_VIDEO
 ) {
 continue;
 }

 if (inCodecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
 m_videoStreamIdx = i;
 m_videoStream = inStream;

 m_codecParams.videoCodecId = m_videoStream->codecpar->codec_id;
 m_codecParams.fps = static_cast<int>(av_q2d(m_videoStream->r_frame_rate) + 0.5);
 m_codecParams.clockrate = m_videoStream->time_base.den;

 spdlog::debug(
 "Decoder: fps: {}, clockrate: {}",
 m_codecParams.fps,
 m_codecParams.clockrate
 )
 ;
 }

 if (inCodecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
 m_audioStreamIdx = i;
 m_audioStream = inStream;

 m_codecParams.audioCodecId = m_audioStream->codecpar->codec_id;
 m_codecParams.audioSamplerate = m_audioStream->codecpar->sample_rate;
 m_codecParams.audioChannels = m_audioStream->codecpar->channels;
 m_codecParams.audioProfile = m_audioStream->codecpar->profile;

 spdlog::debug(
 "Decoder: audio samplerate: {}, audio channels: {}, x: {}",
 m_codecParams.audioSamplerate,
 m_codecParams.audioChannels,
 m_audioStream->codecpar->channels
 )
 ;
 }
 }
 }

 void Decoder::initDecoder() {
 AVCodecParameters* videoStreamCodecParams = m_videoStream->codecpar;

 m_swsContext = sws_getContext(
 videoStreamCodecParams->width, videoStreamCodecParams->height, m_pixFormat,
 videoStreamCodecParams->width, videoStreamCodecParams->height, m_targetPixFormat,
 SWS_BICUBIC, nullptr, nullptr, nullptr);

 // find best video stream info and decoder
 int ret = av_find_best_stream(m_inputFormatContext, AVMEDIA_TYPE_VIDEO, -1, -1, &m_decoder, 0);
 if (ret < 0) {
 throw FFmpegException(
 "Decoder: Cannot find a video stream in the input file"
 );
 }

 if (!m_decoder) {
 throw FFmpegException(
 "Decoder: Can't find decoder"
 );
 }

 // search for supported HW decoder configuration
 for (size_t i = 0;; i++) {
 const AVCodecHWConfig* config = avcodec_get_hw_config(m_decoder, i);
 if (!config) {
 spdlog::error(
 "Decoder {} does not support device type {}. "
 "Will use SW decoder...",
 m_decoder->name,
 av_hwdevice_get_type_name(m_deviceType)
 );
 break;
 }

 if (
 config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX &&
 config->device_type == m_deviceType
 ) {
 // set up pixel format for HW decoder
 g_hwPixFmt = config->pix_fmt;
 m_hwDecoderSupported = true;
 break;
 }
 }
 }
</int>


And I have
AVHWDeviceType m_deviceType{AV_HWDEVICE_TYPE_MEDIACODEC};


avcodec_get_hw_config
returns nullptr.

Any help is appreciated.


-
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)



-
ffmpeg not recording frames
28 mai 2024, par RCamI am using Python to record 5 second videos from 3 webcams at once using ffmpeg. The recordings repeat at intervals of 25 seconds. The code seems to work except intermittently a recording from one of the cameras will be 0 seconds long. There don't seem to be any obvious errors, and the file is created it just doesn't contain any frames. The key components of the code are :


def take_vid1(path1, video_length, sampleN): 
 dt = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
 save1 = os.path.join(path1, dt+'_1'+sampleN+'.mp4')
 command = [ffmpeg_path, '-hide_banner', '-y', '-f', 'dshow', '-thread_queue_size', '4096', '-rtbufsize', '500M', '-c:v', 'mjpeg', '-video_size', '1600x896', '-framerate', '30', '-i', 'video='+dev1, '-map', '0', '-t', video_length, save1]
 sp = subprocess.run(command, capture_output=True, text=True) 
 print(dt + ' vid1 returncode: ' + str(sp.returncode)) 
def take_vid2(path2, video_length, sampleN): 
 dt = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
 save2 = os.path.join(path2, dt+'_2'+sampleN+'.mp4')
 command = [ffmpeg_path, '-hide_banner', '-y', '-f', 'dshow', '-thread_queue_size', '4096', '-rtbufsize', '500M', '-c:v', 'mjpeg', '-video_size', '1600x896', '-framerate', '30', '-i', 'video='+dev2, '-map', '0', '-t', video_length, save2]
 sp = subprocess.run(command, capture_output=True, text=True) 
 print(dt + ' vid2 returncode: ' + str(sp.returncode)) 
def take_vid3(path3, video_length, sampleN): 
 dt = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
 save3 = os.path.join(path3, dt+'_3'+sampleN+'.mp4')
 command = [ffmpeg_path, '-hide_banner', '-y', '-f', 'dshow', '-thread_queue_size', '4096', '-rtbufsize', '500M', '-c:v', 'mjpeg', '-video_size', '1600x896', '-framerate', '30', '-i', 'video='+dev3, '-report', '-map', '0', '-t', video_length, save3]
 sp = subprocess.run(command, capture_output=True, text=True) 
 print(dt + ' vid3 returncode: ' + str(sp.returncode)) 

t1 = Thread(target=take_vid1, args=[cam1Path, video_length,sampleN])
t2 = Thread(target=take_vid2, args=[cam2Path, video_length,sampleN])
t3 = Thread(target=take_vid3, args=[cam3Path, video_length,sampleN])
threads = [t1,t2,t3]
if __name__ == '__main__':
 for t in threads:
 t.start()
 for t in threads:
 t.join()



I'm not sure if this is a coincidence but this issue only affects recordings from camera 3. It doesn't seem to be hardware related because I have switched camera 3 with another camera and it still happens. I've tried calling the threads in different orders, no change. I've updated ffmpeg to the most recent static build. CPU usage and memory are reasonable when the recordings are taking place. At this point I don't know what could be causing ffmpeg to fail to write frames. The link to the log file from a failed recording is below, I'm hoping someone might see something to indicate what is going on or at least have suggestions as to what to try next ?


https://drive.google.com/file/d/1VKBBsf8pZbqNyYLE6o2C0kFHeBAh2kZ1/view?usp=sharing