
Recherche avancée
Autres articles (37)
-
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 ;
-
Ecrire une actualité
21 juin 2013, parPré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 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 (7264)
-
How to save the stream URL chunks as a video in NodeJs
2 octobre 2020, par Harsh LodhiI'm trying to download a piece of video from the below URL using axios.


https://r5---sn-gwpa-civy.googlevideo.com/videoplayback?...&range=32104-500230



I'm using below code to fetch the above URL and for save the chunk to the mp4 file.


axios({
 url: MY_URL`,
 method: 'GET',
 responseType: 'stream'
 }).then(function (response) {
 let buffArray = []
 response.data.on('data', (chunk) => {
 buffArray .push(chunk)
 })

 response.data.on('end', (chunk) => {
 let buff = Buffer.concat(buffArray)
 fs.writeFile('output.mp4', buff, (dt) => {
 console.log("File created");
 })
 })
 })



above code is working fine and I'm able to save the video but the video is not able to play.
when I set the range in URL from
&range=32104-500230
to&range=0-500230
then video is working properly. Please try to help that how can I save a video from small chunk of video stream instead of saving full video.

-
Convert audio blob to mp3 on expressjs server
27 septembre 2020, par islaloboI have a little app that captures sound and stores the audio as an audio blob encoded as base64 on an expressjs server. I would like to convert these audio files into
.mp3
or.wav
- any binary usable format. My understanding of audio files is very basic and I'm looking to gain a better understanding. Any guidance is appreciated. I've read through several posts and issues, but I'm just a bit lost right now.

Here is my client-side capture of the audio, encoding and then posting to expressjs server.


const saveMessage = async function(base64AudioMessage) {
 await fetch('/messages', {
 method: 'POST',
 headers: { 'Content-Type': 'application/json' },
 body: JSON.stringify({ message: base64AudioMessage })
 }).then(res => {
 if (res.status === 201) {
 const response = res.json()
 .then(response => {
 console.log(response);
 populateAudioMessages(response.id); // shows the recording that was just saved
 });
 }
 console.log('Invalid status saving audio message: ' + res.status);
 });
 return true;
 }

 sendButton.addEventListener('click', () => {
 const reader = new FileReader();
 reader.readAsDataURL(audio.audioBlob);
 reader.onload = async () => {
 const base64AudioMessage = reader.result.split(',')[1];
 
 await saveMessage(base64AudioMessage);
 };
 });



Here is the post method on my expressjs server. It's very messy as I have been trying to use
ffmpeg
to convert the posted files to.mp3
format.

app.post('/messages', (req, res) => {
 if (!req.body.message) {
 return res.status(400).json({ error: 'No req.body.message' });
 }
 const messageId = v4();
 writeFile(messageFolder + messageId, req.body.message, 'base64')
 .then(() => {
 console.log('messages was saved!');
 try {
 console.log('attempting to make an mp3 ', audioFolder + messageId);
 const process = new ffmpeg(`${messageFolder}${messageId}`);
 process.then((audio) => {
 console.log('audio is ready to be processed ', audio);
 audio.fnExtractSoundToMP3(`${audioFolder}${messageId}.mp3`, (error, file) => {
 console.log('There is an error ', error);
 console.log('There is a file ', file);
 if (!error) {
 console.log('Audio File ', file);
 const file = file;
 console.log('what a success! ', messageId && messageId, file && file);
 res.status(201).json({
 message: 'Saved message',
 });
 }
 })
 }, (err) => {
 console.log('An error occurred, ', err);
 });
 } catch(e) {
 console.log('error code ', e.code);
 console.log('error message ', e.msg);
 }
 })
 .catch(err => {
 console.log('Error writing message to file', err);
 res.sendStatus(500);
 });
});



-
FFmpeg conversion RGB to YUV420 to RGB wrong result
29 août 2020, par sipwizI'm attempting to sort out a video encoding issue and along the way making sure I can convert between pixel formats with FFmpeg. I'm having a problem converting a dummy RGB24 bitmap to YUV420 and back again.


Below is my test program :


#include "Windows.h"

#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libavformat></libavformat>avio.h>
#include <libavutil></libavutil>imgutils.h>
#include <libswscale></libswscale>swscale.h>
#include <libavutil></libavutil>time.h>

#define WIDTH 32
#define HEIGHT 32
#define ERROR_LEN 128
#define SWS_FLAGS SWS_BICUBIC

char _errorLog[ERROR_LEN];
void CreateBitmapFile(LPCWSTR fileName, long width, long height, WORD bitsPerPixel, BYTE* bitmapData, DWORD bitmapDataLength);

int main()
{
 printf("FFmpeg Pixel Conversion Test\n");

 av_log_set_level(AV_LOG_DEBUG);

 int w = WIDTH;
 int h = HEIGHT;

 struct SwsContext* rgbToI420Context;
 struct SwsContext* i420ToRgbContext;

 rgbToI420Context = sws_getContext(w, h, AV_PIX_FMT_RGB24, w, h, AV_PIX_FMT_YUV420P, SWS_FLAGS, NULL, NULL, NULL);
 if (rgbToI420Context == NULL) {
 fprintf(stderr, "Failed to allocate RGB to I420 conversion context.\n");
 }

 i420ToRgbContext = sws_getContext(w, h, AV_PIX_FMT_YUV420P, w, h, AV_PIX_FMT_RGB24, SWS_FLAGS, NULL, NULL, NULL);
 if (i420ToRgbContext == NULL) {
 fprintf(stderr, "Failed to allocate I420 to RGB conversion context.\n");
 }

 // Create dummy bitmap.
 uint8_t rgbRaw[WIDTH * HEIGHT * 3];
 for (int row = 0; row < 32; row++)
 {
 for (int col = 0; col < 32; col++)
 {
 int index = row * WIDTH * 3 + col * 3;

 int red = (row < 16 && col < 16) ? 255 : 0;
 int green = (row < 16 && col > 16) ? 255 : 0;
 int blue = (row > 16 && col < 16) ? 255 : 0;

 rgbRaw[index] = (byte)red;
 rgbRaw[index + 1] = (byte)green;
 rgbRaw[index + 2] = (byte)blue;
 }
 }

 CreateBitmapFile(L"test-reference.bmp", WIDTH, HEIGHT, 24, rgbRaw, WIDTH * HEIGHT * 3);

 printf("Converting RGB to I420.\n");

 uint8_t* rgb[3];
 uint8_t* i420[3];
 int rgbStride[3], i420Stride[3];

 rgbStride[0] = w * 3;
 i420Stride[0] = w * h;
 i420Stride[1] = w * h / 4;
 i420Stride[2] = w * h / 4;

 rgb[0] = rgbRaw;
 i420[0] = (uint8_t*)malloc((size_t)i420Stride[0] * h);
 i420[1] = (uint8_t*)malloc((size_t)i420Stride[1] * h);
 i420[2] = (uint8_t*)malloc((size_t)i420Stride[2] * h);

 int toI420Res = sws_scale(rgbToI420Context, rgb, rgbStride, 0, h, i420, i420Stride);
 if (toI420Res < 0) {
 fprintf(stderr, "Conversion from RGB to I420 failed, %s.\n", av_make_error_string(_errorLog, ERROR_LEN, toI420Res));
 }

 printf("Converting I420 to RGB.\n");

 uint8_t* rgbOut[3];
 int rgbOutStride[3];

 rgbOutStride[0] = w * 3;
 rgbOut[0] = (uint8_t*)malloc((size_t)rgbOutStride[0] * h);

 int toRgbRes = sws_scale(i420ToRgbContext, i420, i420Stride, 0, h, rgbOut, rgbOutStride);
 if (toRgbRes < 0) {
 fprintf(stderr, "Conversion from RGB to I420 failed, %s.\n", av_make_error_string(_errorLog, ERROR_LEN, toRgbRes));
 }

 CreateBitmapFile(L"test-output.bmp", WIDTH, HEIGHT, 24, rgbOut, WIDTH * HEIGHT * 3);

 free(rgbOut[0]);

 for (int i = 0; i < 3; i++) {
 free(i420[i]);
 }

 sws_freeContext(rgbToI420Context);
 sws_freeContext(i420ToRgbContext);

 return 0;
}

/**
* Creates a bitmap file and writes to disk.
* @param[in] fileName: the path to save the file at.
* @param[in] width: the width of the bitmap.
* @param[in] height: the height of the bitmap.
* @param[in] bitsPerPixel: colour depth of the bitmap pixels (typically 24 or 32).
* @param[in] bitmapData: a pointer to the bytes containing the bitmap data.
* @param[in] bitmapDataLength: the number of pixels in the bitmap.
*/
void CreateBitmapFile(LPCWSTR fileName, long width, long height, WORD bitsPerPixel, BYTE* bitmapData, DWORD bitmapDataLength)
{
 HANDLE file;
 BITMAPFILEHEADER fileHeader;
 BITMAPINFOHEADER fileInfo;
 DWORD writePosn = 0;

 file = CreateFile(fileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); //Sets up the new bmp to be written to

 fileHeader.bfType = 19778; //Sets our type to BM or bmp
 fileHeader.bfSize = sizeof(fileHeader.bfOffBits) + sizeof(RGBTRIPLE); //Sets the size equal to the size of the header struct
 fileHeader.bfReserved1 = 0; //sets the reserves to 0
 fileHeader.bfReserved2 = 0;
 fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); //Sets offbits equal to the size of file and info header
 fileInfo.biSize = sizeof(BITMAPINFOHEADER);
 fileInfo.biWidth = width;
 fileInfo.biHeight = height;
 fileInfo.biPlanes = 1;
 fileInfo.biBitCount = bitsPerPixel;
 fileInfo.biCompression = BI_RGB;
 fileInfo.biSizeImage = width * height * (bitsPerPixel / 8);
 fileInfo.biXPelsPerMeter = 2400;
 fileInfo.biYPelsPerMeter = 2400;
 fileInfo.biClrImportant = 0;
 fileInfo.biClrUsed = 0;

 WriteFile(file, &fileHeader, sizeof(fileHeader), &writePosn, NULL);

 WriteFile(file, &fileInfo, sizeof(fileInfo), &writePosn, NULL);

 WriteFile(file, bitmapData, bitmapDataLength, &writePosn, NULL);

 CloseHandle(file);
}



The source bitmap is :




The output bmp after the two conversions is :