Recherche avancée

Médias (2)

Mot : - Tags -/documentation

Autres articles (96)

  • Emballe médias : à quoi cela sert ?

    4 février 2011, par

    Ce plugin vise à gérer des sites de mise en ligne de documents de tous types.
    Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;

  • Automated installation script of MediaSPIP

    25 avril 2011, par

    To overcome the difficulties mainly due to the installation of server side software dependencies, an "all-in-one" installation script written in bash was created to facilitate this step on a server with a compatible Linux distribution.
    You must have access to your server via SSH and a root account to use it, which will install the dependencies. Contact your provider if you do not have that.
    The documentation of the use of this installation script is available here.
    The code of this (...)

  • Contribute to translation

    13 avril 2011

    You can help us to improve the language used in the software interface to make MediaSPIP more accessible and user-friendly. You can also translate the interface into any language that allows it to spread to new linguistic communities.
    To do this, we use the translation interface of SPIP where the all the language modules of MediaSPIP are available. Just subscribe to the mailing list and request further informantion on translation.
    MediaSPIP is currently available in French and English (...)

Sur d’autres sites (5223)

  • Things I Have Learned About Emscripten

    1er septembre 2015, par Multimedia Mike — Cirrus Retro

    3 years ago, I released my Game Music Appreciation project, a website with a ludicrously uninspired title which allowed users a relatively frictionless method to experience a range of specialized music files related to old video games. However, the site required use of a special Chrome plugin. Ever since that initial release, my #1 most requested feature has been for a pure JavaScript version of the music player.

    “Impossible !” I exclaimed. “There’s no way JS could ever run fast enough to run these CPU emulators and audio synthesizers in real time, and allow for the visualization that I demand !” Well, I’m pleased to report that I have proved me wrong. I recently quietly launched a new site with what I hope is a catchier title, meant to evoke a cloud-based retro-music-as-a-service product : Cirrus Retro. Right now, it’s basically the same as the old site, but without the wonky Chrome-specific technology.

    Along the way, I’ve learned a few things about using Emscripten that I thought might be useful to share with other people who wish to embark on a similar journey. This is geared more towards someone who has a stronger low-level background (such as C/C++) vs. high-level (like JavaScript).

    General Goals
    Do you want to cross-compile an entire desktop application, one that relies on an extensive GUI toolkit ? That might be difficult (though I believe there is a path for porting qt code directly with Emscripten). Your better wager might be to abstract out the core logic and processes of the program and then create a new web UI to access them.

    Do you want to compile a game that basically just paints stuff to a 2D canvas ? You’re in luck ! Emscripten has a porting path for SDL. Make a version of your C/C++ software that targets SDL (generally not a tall order) and then compile that with Emscripten.

    Do you just want to cross-compile some functionality that lives in a library ? That’s what I’ve done with the Cirrus Retro project. For this, plan to compile the library into a JS file that exports some public functions that other, higher-level, native JS (i.e., JS written by a human and not a computer) will invoke.

    Memory Levels
    When porting C/C++ software to JavaScript using Emscripten, you have to think on 2 different levels. Or perhaps you need to force JavaScript into a low level C lens, especially if you want to write native JS code that will interact with Emscripten-compiled code. This often means somehow allocating chunks of memory via JS and passing them to the Emscripten-compiled functions. And you wouldn’t believe the type of gymnastics you need to execute to get native JS and Emscripten-compiled JS to cooperate.

    “Emscripten : Pointers and Pointers” is the best (and, really, ONLY) explanation I could find for understanding the basic mechanics of this process, at least when I started this journey. However, there’s a mistake in the explanation that left me confused for a little while, and I’m at a loss to contact the author (doesn’t anyone post a simple email address anymore ?).

    Per the best of my understanding, Emscripten allocates a large JS array and calls that the memory space that the compiled C/C++ code is allowed to operate in. A pointer in C/C++ code will just be an index into that mighty array. Really, that’s not too far off from how a low-level program process is supposed to view memory– as a flat array.

    Eventually, I just learned to cargo-cult my way through the memory allocation process. Here’s the JS code for allocating an Emscripten-compatible byte buffer, taken from my test harness (more on that later) :

    var musicBuffer = fs.readFileSync(testSpec[’filename’]) ;
    var musicBufferBytes = new Uint8Array(musicBuffer) ;
    var bytesMalloc = player._malloc(musicBufferBytes.length) ;
    var bytes = new Uint8Array(player.HEAPU8.buffer, bytesMalloc, musicBufferBytes.length) ;
    bytes.set(new Uint8Array(musicBufferBytes.buffer)) ;
    

    So, read the array of bytes from some input source, create a Uint8Array from the bytes, use the Emscripten _malloc() function to allocate enough bytes from the Emscripten memory array for the input bytes, then create a new array… then copy the bytes…

    You know what ? It’s late and I can’t remember how it works exactly, but it does. It has been a few months since I touched that code (been fighting with front-end website tech since then). You write that memory allocation code enough times and it begins to make sense, and then you hope you don’t have to write it too many more times.

    Multithreading
    You can’t port multithreaded code to JS via Emscripten. JavaScript has no notion of threads ! If you don’t understand the computer science behind this limitation, a more thorough explanation is beyond the scope of this post. But trust me, I’ve thought about it a lot. In fact, the official Emscripten literature states that you should be able to port most any C/C++ code as long as 1) none of the code is proprietary (i.e., all the raw source is available) ; and 2) there are no threads.

    Yes, I read about the experimental pthreads support added to Emscripten recently. Don’t get too excited ; that won’t be ready and widespread for a long time to come as it relies on a new browser API. In the meantime, figure out how to make your multithreaded C/C++ code run in a single thread if you want it to run in a browser.

    Printing Facility
    Eventually, getting software to work boils down to debugging, and the most primitive tool in many a programmer’s toolbox is the humble print statement. A print statement allows you to inspect a piece of a program’s state at key junctures. Eventually, when you try to cross-compile C/C++ code to JS using Emscripten, something is not going to work correctly in the generated JS “object code” and you need to understand what. You’ll be pleading for a method of just inspecting one variable deep in the original C/C++ code.

    I came up with this simple printf-workalike called emprintf() :

    #ifndef EMPRINTF_H
    #define EMPRINTF_H
    

    #include <stdio .h>
    #include <stdarg .h>
    #include <emscripten .h>

    #define MAX_MSG_LEN 1000

    /* NOTE : Don’t pass format strings that contain single quote (’) or newline
    * characters. */
    static void emprintf(const char *format, ...)

    char msg[MAX_MSG_LEN] ;
    char consoleMsg[MAX_MSG_LEN + 16] ;
    va_list args ;

    /* create the string */
    va_start(args, format) ;
    vsnprintf(msg, MAX_MSG_LEN, format, args) ;
    va_end(args) ;

    /* wrap the string in a console.log(’’) statement */
    snprintf(consoleMsg, MAX_MSG_LEN + 16, "console.log(’%s’)", msg) ;

    /* send the final string to the JavaScript console */
    emscripten_run_script(consoleMsg) ;

    #endif /* EMPRINTF_H */

    Put it in a file called “emprint.h”. Include it into any C/C++ file where you need debugging visibility, use emprintf() as a replacement for printf() and the output will magically show up on the browser’s JavaScript debug console. Heed the comments and don’t put any single quotes or newlines in strings, and keep it under 1000 characters. I didn’t say it was perfect, but it has helped me a lot in my Emscripten adventures.

    Optimization Levels
    Remember to turn on optimization when compiling. I have empirically found that optimizing for size (-Os) leads to the best performance all around, in addition to having the smallest size. Just be sure to specify some optimization level. If you don’t, the default is -O0 which offers horrible performance when running in JS.

    Static Compression For HTTP Delivery
    JavaScript code compresses pretty efficiently, even after it has been optimized for size using -Os. I routinely see compression ratios between 3.5:1 and 5:1 using gzip.

    Web servers in this day and age are supposed to be smart enough to detect when a requesting web browser can accept gzip-compressed data and do the compression on the fly. They’re even supposed to be smart enough to cache compressed output so the same content is not recompressed for each request. I would have to set up a series of tests to establish whether either of the foregoing assertions are correct and I can’t be bothered. Instead, I took it into my own hands. The trick is to pre-compress the JS files and then instruct the webserver to serve these files with a ‘Content-Type’ of ‘application/javascript’ and a ‘Content-Encoding’ of ‘gzip’.

    1. Compress your large Emscripten-build JS files with ‘gzip’ : ‘gzip compiled-code.js’
    2. Rename them from extension .js.gz to .jsgz
    3. Tell the webserver to deliver .jsgz files with the correct Content-Type and Content-Encoding headers

    To do that last step with Apache, specify these lines :

    AddType application/javascript jsgz
    AddEncoding gzip jsgz
    

    They belong in either a directory’s .htaccess file or in the sitewide configuration (/etc/apache2/mods-available/mime.conf works on my setup).

    Build System and Build Time Optimization
    Oh goodie, build systems ! I had a very specific manner in which I wanted to build my JS modules using Emscripten. Can I possibly coerce any of the many popular build systems to do this ? It has been a few months since I worked on this problem specifically but I seem to recall that the build systems I tried to used would freak out at the prospect of compiling stuff to a final binary target of .js.

    I had high hopes for Bazel, which Google released while I was developing Cirrus Retro. Surely, this is software that has been battle-tested in the harshest conditions of one of the most prominent software-developing companies in the world, needing to take into account the most bizarre corner cases and still build efficiently and correctly every time. And I have little doubt that it fulfills the order. Similarly, I’m confident that Google also has a team of no fewer than 100 or so people dedicated to developing and supporting the project within the organization. When you only have, at best, 1-2 hours per night to work on projects like this, you prefer not to fight with such cutting edge technology and after losing 2 or 3 nights trying to make a go of Bazel, I eventually put it aside.

    I also tried to use Autotools. It failed horribly for me, mostly for my own carelessness and lack of early-project source control.

    After that, it was strictly vanilla makefiles with no real dependency management. But you know what helps in these cases ? ccache ! Or at least, it would if it didn’t fail with Emscripten.

    Quick tip : ccache has trouble with LLVM unless you set the CCACHE_CPP2 environment variable (e.g. : “export CCACHE_CPP2=1”). I don’t remember the specifics, but it magically fixes things. Then, the lazy build process becomes “make clean && make”.

    Testing
    If you have never used Node.js, testing Emscripten-compiled JS code might be a good opportunity to start. I was able to use Node.js to great effect for testing the individually-compiled music player modules, wiring up a series of invocations using Python for a broader test suite (wouldn’t want to go too deep down the JS rabbit hole, after all).

    Be advised that Node.js doesn’t enjoy the same kind of JIT optimizations that the browser engines leverage. Thus, in the case of time critical code like, say, an audio synthesis library, the code might not run in real time. But as long as it produces the correct bitwise waveform, that’s good enough for continuous integration.

    Also, if you have largely been a low-level programmer for your whole career and are generally unfamiliar with the world of single-threaded, event-driven, callback-oriented programming, you might be in for a bit of a shock. When I wanted to learn how to read the contents of a file in Node.js, this is the first tutorial I found on the matter. I thought the code presented was a parody of bad coding style :

    var fs = require("fs") ;
    var fileName = "foo.txt" ;
    

    fs.exists(fileName, function(exists)
    if (exists)
    fs.stat(fileName, function(error, stats)
    fs.open(fileName, "r", function(error, fd)
    var buffer = new Buffer(stats.size) ;

    fs.read(fd, buffer, 0, buffer.length, null, function(error, bytesRead, buffer)
    var data = buffer.toString("utf8", 0, buffer.length) ;

    console.log(data) ;
    fs.close(fd) ;
    ) ;
    ) ;
    ) ;
    ) ;

    Apparently, this kind of thing doesn’t raise an eyebrow in the JS world.

    Now, I understand and respect the JS programming model. But this was seriously frustrating when I first encountered it because a simple script like the one I was trying to write just has an ordered list of tasks to complete. When it asks for bytes from a file, it really has nothing better to do than to wait for the answer.

    Thankfully, it turns out that Node’s fs module includes synchronous versions of the various file access functions. So it’s all good.

    Conclusion
    I’m sure I missed or underexplained some things. But if other brave souls are interested in dipping their toes in the waters of Emscripten, I hope these tips will come in handy.

  • FFmpeg RTP payload 96 instead of 97

    26 octobre 2016, par bot1131357

    I am trying to create an rtp audio stream with ffmpeg. The application output and SDP file configuration are as follows :

    Output #0, rtp, to 'rtp://127.0.0.1:8554':
       Stream #0:0: Audio: pcm_s16be, 8000 Hz, stereo, s16, 256 kb/s

    SDP:    
    v=0
    o=- 0 0 IN IP4 127.0.0.1
    s=No Name
    c=IN IP4 127.0.0.1
    t=0 0
    a=tool:libavformat 57.25.101
    m=audio 8554 RTP/AVP 96
    b=AS:256
    a=rtpmap:96 L16/8000/2

    However, when I try to read it with ffplay -i test.sdp -protocol_whitelist file,udp,rtp, it fails,shows the following :

    ffplay version N-78598-g98a0053 Copyright (c) 2003-2016 the FFmpeg developers
     built with gcc 5.3.0 (GCC)
     configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
     libavutil      55. 18.100 / 55. 18.100
     libavcodec     57. 24.103 / 57. 24.103
     libavformat    57. 25.101 / 57. 25.101
     libavdevice    57.  0.101 / 57.  0.101
     libavfilter     6. 34.100 /  6. 34.100
     libswscale      4.  0.100 /  4.  0.100
     libswresample   2.  0.101 /  2.  0.101
     libpostproc    54.  0.100 / 54.  0.100
       nan    :  0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0
       (...waits indefinitely.)

    The only way to make it work again is to modify the payload type in the SDP file from 96 to 97. Can someone tell me why ? Where is this number defined ?

    Here is my source. See if you can replicate it.

    #include
    extern "C"
    {
    #include <libavutil></libavutil>opt.h>
    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavutil></libavutil>channel_layout.h>
    #include <libavutil></libavutil>common.h>
    #include <libavutil></libavutil>imgutils.h>
    #include <libavutil></libavutil>mathematics.h>
    #include <libavutil></libavutil>samplefmt.h>
    #include <libavformat></libavformat>avformat.h>
    }


    static int write_frame(AVFormatContext *fmt_ctx, const AVRational *time_base, AVStream *st, AVPacket *pkt)
    {
       /* rescale output packet timestamp values from codec to stream timebase */
       av_packet_rescale_ts(pkt, *time_base, st->time_base);

       /* Write the compressed frame to the media file. */
       return av_interleaved_write_frame(fmt_ctx, pkt);
    }

    /*
    * Audio encoding example
    */
    static void audio_encode_example(const char *filename)
    {
       AVPacket pkt;
       int i, j, k, ret, got_output;
       int buffer_size;

       uint16_t *samples;
       float t, tincr;

       AVCodec *outCodec = NULL;
       AVCodecContext *outCodecCtx = NULL;
       AVFormatContext *outFormatCtx = NULL;
       AVStream * outAudioStream = NULL;
       AVFrame *outFrame = NULL;

       ret = avformat_alloc_output_context2(&amp;outFormatCtx, NULL, "rtp", filename);
       if (!outFormatCtx || ret &lt; 0)
       {
           fprintf(stderr, "Could not allocate output context");
       }

       outFormatCtx->flags |= AVFMT_FLAG_NOBUFFER | AVFMT_FLAG_FLUSH_PACKETS;
       outFormatCtx->oformat->audio_codec = AV_CODEC_ID_PCM_S16BE;

       /* find the encoder */
       outCodec = avcodec_find_encoder(outFormatCtx->oformat->audio_codec);
       if (!outCodec) {
           fprintf(stderr, "Codec not found\n");
           exit(1);
       }

       outAudioStream = avformat_new_stream(outFormatCtx, outCodec);
       if (!outAudioStream)
       {
           fprintf(stderr, "Cannot add new audio stream\n");
           exit(1);
       }

       outAudioStream->id = outFormatCtx->nb_streams - 1;
       outCodecCtx = outAudioStream->codec;
       outCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16;

       /* select other audio parameters supported by the encoder */
       outCodecCtx->sample_rate = 8000;
       outCodecCtx->channel_layout = AV_CH_LAYOUT_STEREO;
       outCodecCtx->channels = 2;

       /* open it */
       if (avcodec_open2(outCodecCtx, outCodec, NULL) &lt; 0) {
           fprintf(stderr, "Could not open codec\n");
           exit(1);
       }

       // PCM has no frame, so we have to explicitly specify
       outCodecCtx->frame_size = 1152;

       av_dump_format(outFormatCtx, 0, filename, 1);

       char buff[10000] = { 0 };
       ret = av_sdp_create(&amp;outFormatCtx, 1, buff, sizeof(buff));
       printf("%s", buff);

       ret = avio_open2(&amp;outFormatCtx->pb, filename, AVIO_FLAG_WRITE, NULL, NULL);
       ret = avformat_write_header(outFormatCtx, NULL);
       printf("ret = %d\n", ret);
       if (ret &lt;0) {
           exit(1);
       }

       /* frame containing input audio */
       outFrame = av_frame_alloc();
       if (!outFrame) {
           fprintf(stderr, "Could not allocate audio frame\n");
           exit(1);
       }

       outFrame->nb_samples = outCodecCtx->frame_size;
       outFrame->format = outCodecCtx->sample_fmt;
       outFrame->channel_layout = outCodecCtx->channel_layout;

       /* we calculate the size of the samples buffer in bytes */
       buffer_size = av_samples_get_buffer_size(NULL, outCodecCtx->channels, outCodecCtx->frame_size,
           outCodecCtx->sample_fmt, 0);
       if (buffer_size &lt; 0) {
           fprintf(stderr, "Could not get sample buffer size\n");
           exit(1);
       }
       samples = (uint16_t*)av_malloc(buffer_size);
       if (!samples) {
           fprintf(stderr, "Could not allocate %d bytes for samples buffer\n",
               buffer_size);
           exit(1);
       }
       /* setup the data pointers in the AVFrame */
       ret = avcodec_fill_audio_frame(outFrame, outCodecCtx->channels, outCodecCtx->sample_fmt,
           (const uint8_t*)samples, buffer_size, 0);
       if (ret &lt; 0) {
           fprintf(stderr, "Could not setup audio frame\n");
           exit(1);
       }

       /* encode a single tone sound */
       t = 0;
       int next_pts = 0;
       tincr = 2 * M_PI * 440.0 / outCodecCtx->sample_rate;
       for (i = 0; i &lt; 400000; i++) {
           av_init_packet(&amp;pkt);
           pkt.data = NULL; // packet data will be allocated by the encoder
           pkt.size = 0;

           for (j = 0; j &lt; outCodecCtx->frame_size; j++) {
               samples[2 * j] = (uint16_t)(sin(t) * 10000);

               for (k = 1; k &lt; outCodecCtx->channels; k++)
                   samples[2 * j + k] = samples[2 * j];
               t += tincr;
           }
           t = (t > 50000) ? 0 : t;

           // Sets time stamp
           next_pts += outFrame->nb_samples;
           outFrame->pts = next_pts;

           /* encode the samples */
           ret = avcodec_encode_audio2(outCodecCtx, &amp;pkt, outFrame, &amp;got_output);
           if (ret &lt; 0) {
               fprintf(stderr, "Error encoding audio frame\n");
               exit(1);
           }
           if (got_output) {
               write_frame(outFormatCtx, &amp;outCodecCtx->time_base, outAudioStream, &amp;pkt);
               av_packet_unref(&amp;pkt);
           }

           printf("i:%d\n", i); // waste some time to avoid over-filling jitter buffer
           printf("Audio: %d\t%d\n", samples[0], samples[1]); // waste some time to avoid over-filling jitter buffer
           printf("t: %f\n", t); // waste some time to avoid over-filling jitter buffer
       }

       /* get the delayed frames */
       for (got_output = 1; got_output; i++) {
           ret = avcodec_encode_audio2(outCodecCtx, &amp;pkt, NULL, &amp;got_output);
           if (ret &lt; 0) {
               fprintf(stderr, "Error encoding frame\n");
               exit(1);
           }

           if (got_output) {
               pkt.pts = AV_NOPTS_VALUE;
               write_frame(outFormatCtx, &amp;outCodecCtx->time_base, outAudioStream, &amp;pkt);
               av_packet_unref(&amp;pkt);
           }
       }

       av_freep(&amp;samples);
       av_frame_free(&amp;outFrame);
       avcodec_close(outCodecCtx);
       av_free(outCodecCtx);
    }


    int main(int argc, char **argv)
    {
       const char *output;

       av_register_all();
       avformat_network_init(); // for network streaming

       audio_encode_example("rtp://127.0.0.1:8554");

       return 0;
    }

    Update

    Curiously, running on Linux Ubuntu gives me the following instead :

    Output #0, rtp, to 'rtp://127.0.0.1:8554':
       Stream #0:0: Unknown: none (pcm_s16be)
    v=0
    o=- 0 0 IN IP4 127.0.0.1
    s=No Name
    c=IN IP4 127.0.0.1
    t=0 0
    a=tool:libavformat 57.48.100
    m=application 8554 RTP/AVP 3

    Does anyone know why the stream has been changed from audio to application ?

  • Revision 30148 : On pousse encore un peu plus loin la conf (toujours pas utilisable dans ...

    24 juillet 2009, par kent1@… — Log

    On pousse encore un peu plus loin la conf (toujours pas utilisable dans l’état)