
Recherche avancée
Médias (91)
-
Géodiversité
9 septembre 2011, par ,
Mis à jour : Août 2018
Langue : français
Type : Texte
-
USGS Real-time Earthquakes
8 septembre 2011, par
Mis à jour : Septembre 2011
Langue : français
Type : Texte
-
SWFUpload Process
6 septembre 2011, par
Mis à jour : Septembre 2011
Langue : français
Type : Texte
-
La conservation du net art au musée. Les stratégies à l’œuvre
26 mai 2011
Mis à jour : Juillet 2013
Langue : français
Type : Texte
-
Podcasting Legal guide
16 mai 2011, par
Mis à jour : Mai 2011
Langue : English
Type : Texte
-
Creativecommons informational flyer
16 mai 2011, par
Mis à jour : Juillet 2013
Langue : English
Type : Texte
Autres articles (15)
-
La file d’attente de SPIPmotion
28 novembre 2010, parUne file d’attente stockée dans la base de donnée
Lors de son installation, SPIPmotion crée une nouvelle table dans la base de donnée intitulée spip_spipmotion_attentes.
Cette nouvelle table est constituée des champs suivants : id_spipmotion_attente, l’identifiant numérique unique de la tâche à traiter ; id_document, l’identifiant numérique du document original à encoder ; id_objet l’identifiant unique de l’objet auquel le document encodé devra être attaché automatiquement ; objet, le type d’objet auquel (...) -
Contribute to documentation
13 avril 2011Documentation is vital to the development of improved technical capabilities.
MediaSPIP welcomes documentation by users as well as developers - including : critique of existing features and functions articles contributed by developers, administrators, content producers and editors screenshots to illustrate the above translations of existing documentation into other languages
To contribute, register to the project users’ mailing (...) -
HTML5 audio and video support
13 avril 2011, parMediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
For older browsers the Flowplayer flash fallback is used.
MediaSPIP allows for media playback on major mobile platforms with the above (...)
Sur d’autres sites (2672)
-
Perspective transformations
Finally (after a long break) I managed to force myself to update the PHP documentation and this time it was distortImage code example. Things have been hectic lately but that does not quite explain the 6 months(?) break between this and the previous post. As a matter of a fact there is no excuse for such a long silence so I will try to update this blog a bit more often from now on.
Back in the day I used to blog the examples and update the documentation if I remembered but I am trying to fix this bad habit. Most of the latest examples have been updated in to the manual. In the case of the two last examples I updated the documentation first and then blogged on the subject.
I took some time to actually understand the perspective transformations properly using the excellent ImageMagick examples (mainly created by Anthony Thyssen) as a reference. The basic idea of perspective distortion seems simple : to distort the control points to new locations. Grabbing the syntax for Imagick was easy, an array of control point pairs in the form of :
-
array(source_x, source_y, dest_x, dest_y ... )
The following example uses the built-in checkerboard pattern to demonstrate perspective distortion :
-
< ?php
-
/* Create new object */
-
$im = new Imagick() ;
-
-
/* Create new checkerboard pattern */
-
$im->newPseudoImage(100, 100, "pattern:checkerboard") ;
-
-
/* Set the image format to png */
-
$im->setImageFormat(’png’) ;
-
-
/* Fill background area with transparent */
-
$im->setImageVirtualPixelMethod(Imagick: :VIRTUALPIXELMETHOD_TRANSPARENT) ;
-
-
/* Activate matte */
-
$im->setImageMatte(true) ;
-
-
/* Control points for the distortion */
-
$controlPoints = array( 10, 10,
-
10, 5,
-
-
10, $im->getImageHeight() - 20,
-
10, $im->getImageHeight() - 5,
-
-
$im->getImageWidth() - 10, 10,
-
$im->getImageWidth() - 10, 20,
-
-
$im->getImageWidth() - 10, $im->getImageHeight() - 10,
-
$im->getImageWidth() - 10, $im->getImageHeight() - 30) ;
-
-
/* Perform the distortion */
-
$im->distortImage(Imagick: :DISTORTION_PERSPECTIVE, $controlPoints, true) ;
-
-
/* Ouput the image */
-
header("Content-Type : image/png") ;
-
echo $im ;
-
?>
Here is the source image :
And the result :
-
-
Node js async/await promise problem with ytdl and ffmpeg
31 août 2020, par WorkoutBuddyI built a simple youtube downloader cli. It looks like this (without any arg parsing for easier reproduction) :


const ytdl = require('ytdl-core');
const config = require('config');
const progressBar = require('./progressBar');
const logger = require('./logger');
const ffmpeg = require('fluent-ffmpeg');

const url = 'https://www.youtube.com/watch?v=Np8ibIagn3M';

const getInfo = async (url) => {
 logger.info(`Getting metadata for ${url}`);
 const response = await ytdl.getBasicInfo(url);
 const info = response.videoDetails.title;
 logger.info(`Title: ${info}`);
 return info;
};

const getStream = async (url) => {
 logger.info(`Downloading from ${url} ...`);

 let allReceived = false;
 return new Promise((resolve, reject) => {
 const stream = ytdl(url, {
 quality: 'highest',
 filter: (format) => format.container === 'mp4',
 })
 .on('progress', (_, totalDownloaded, total) => {
 if (!allReceived) {
 progressBar.start(total, 0, {
 mbTotal: (total / 1024 / 1024).toFixed(2),
 mbValue: 0,
 });
 allReceived = true;
 }
 progressBar.increment();
 progressBar.update(totalDownloaded, {
 mbValue: (totalDownloaded / 1024 / 1024).toFixed(2),
 });
 })
 .on('end', () => {
 progressBar.stop();
 logger.info('Successfully downloaded the stream!');
 });
 return resolve(stream);
 });
};

const convertToMp3 = async (stream, title) => {
 return new Promise((resolve, reject) => {
 ffmpeg({ source: stream })
 .output(`${config.get('audioDir')}/${title}.mp3`)
 .audioBitrate('192k')
 .run();
 return resolve();
 });
};

const main = async (url) => {
 const info = await getInfo(url);
 console.log('here 1');
 const stream = await getStream(url);
 console.log('here 2');
 await convertToMp3(stream, info);
 console.log('done');
};

main(url);



The output looks like :


➜ node youtube.js
info: Getting metadata for https://www.youtube.com/watch?v=Np8ibIagn3M
info: Title: Tu boca - (Bachata Remix Dj Khalid)
here 1
info: Downloading from https://www.youtube.com/watch?v=Np8ibIagn3M ...
here 2
done
[Progress] [████████████████████████████████████████] 100% | Downloaded: 7.15/7.15 MB | Elapsed Time: 5s
info: Successfully downloaded the stream!



However, I would expect this output :


➜ node youtube.js
info: Getting metadata for https://www.youtube.com/watch?v=Np8ibIagn3M
info: Title: Tu boca - (Bachata Remix Dj Khalid)
here 1
info: Downloading from https://www.youtube.com/watch?v=Np8ibIagn3M ...
[Progress] [████████████████████████████████████████] 100% | Downloaded: 7.15/7.15 MB | Elapsed Time: 5s
here 2
info: Successfully downloaded the stream!
done



I think I have troubles to understand async/await. As far as I understood, promisifying a function allows me wait for the result. However, it seems that it does not work. I do not know why and how to properly debug it.


EDITED :


const getStream = async (url) => {
 logger.info(`Downloading from ${url} ...`);

 let allReceived = false;
 return new Promise((resolve, reject) => {
 const stream = ytdl(url, {
 quality: 'highest',
 filter: (format) => format.container === 'mp4',
 })
 .on('progress', (_, totalDownloaded, total) => {
 console.log('totalDownloaded: ' + totalDownloaded);
 if (!allReceived) {
 console.log('total: ' + total);
 progressBar.start(total, 0, {
 mbTotal: (total / 1024 / 1024).toFixed(2),
 mbValue: 0,
 });
 allReceived = true;
 }
 progressBar.increment();
 progressBar.update(totalDownloaded, {
 mbValue: (totalDownloaded / 1024 / 1024).toFixed(2),
 });
 })
 .on('end', () => {
 progressBar.stop();
 logger.info('Successfully downloaded the stream!');
 resolve(stream);
 });
 });
};



But now it is like this :


➜ node youtube.js
info: Getting metadata for https://www.youtube.com/watch?v=Np8ibIagn3M
info: Title: Tu boca - (Bachata Remix Dj Khalid)
here 1
info: Downloading from https://www.youtube.com/watch?v=Np8ibIagn3M ...
[Progress] [██████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 14% | Downloaded: 1.02/7.15 MB | Elapsed Time: 52s



Added console.log :


totalDownloaded: 16384
total: 7493903
[Progress] [░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0% | Downloaded: 0/7.15 MB | Elapsed Time: 0stotalDownloaded: 32768
totalDownloaded: 49152
totalDownloaded: 65536
totalDownloaded: 81920
totalDownloaded: 98304
totalDownloaded: 114688
totalDownloaded: 131072
totalDownloaded: 147456
totalDownloaded: 163840
totalDownloaded: 180224
totalDownloaded: 196608
totalDownloaded: 212992
totalDownloaded: 229376
totalDownloaded: 245760
totalDownloaded: 262144
totalDownloaded: 278528
totalDownloaded: 294912
totalDownloaded: 311296
totalDownloaded: 327680
totalDownloaded: 344064
totalDownloaded: 360448
totalDownloaded: 376832
totalDownloaded: 393216
totalDownloaded: 409600
totalDownloaded: 425984
totalDownloaded: 442368
totalDownloaded: 458752
totalDownloaded: 475136
totalDownloaded: 491520
totalDownloaded: 507904
totalDownloaded: 524288
totalDownloaded: 540672
totalDownloaded: 557056
totalDownloaded: 573440
totalDownloaded: 589824
totalDownloaded: 606208
totalDownloaded: 622592
totalDownloaded: 638976
totalDownloaded: 655360
totalDownloaded: 671744
totalDownloaded: 688128
totalDownloaded: 704512
totalDownloaded: 720896
totalDownloaded: 737280
totalDownloaded: 753664
totalDownloaded: 770048
totalDownloaded: 786432
totalDownloaded: 802816
totalDownloaded: 819200
totalDownloaded: 835584
totalDownloaded: 851968
totalDownloaded: 868352
totalDownloaded: 884736
totalDownloaded: 901120
totalDownloaded: 917504
totalDownloaded: 933888
totalDownloaded: 950272
totalDownloaded: 966656
totalDownloaded: 983040
totalDownloaded: 999424
totalDownloaded: 1015808
totalDownloaded: 1032192
totalDownloaded: 1048576
totalDownloaded: 1064960
[Progress] [██████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 14% | Downloaded: 1.02/7.15 MB | Elapsed Time: 25s