Recherche avancée

Médias (29)

Mot : - Tags -/Musique

Autres articles (80)

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

  • Gestion des droits de création et d’édition des objets

    8 février 2011, par

    Par défaut, beaucoup de fonctionnalités sont limitées aux administrateurs mais restent configurables indépendamment pour modifier leur statut minimal d’utilisation notamment : la rédaction de contenus sur le site modifiables dans la gestion des templates de formulaires ; l’ajout de notes aux articles ; l’ajout de légendes et d’annotations sur les images ;

  • Menus personnalisés

    14 novembre 2010, par

    MediaSPIP utilise le plugin Menus pour gérer plusieurs menus configurables pour la navigation.
    Cela permet de laisser aux administrateurs de canaux la possibilité de configurer finement ces menus.
    Menus créés à l’initialisation du site
    Par défaut trois menus sont créés automatiquement à l’initialisation du site : Le menu principal ; Identifiant : barrenav ; Ce menu s’insère en général en haut de la page après le bloc d’entête, son identifiant le rend compatible avec les squelettes basés sur Zpip ; (...)

Sur d’autres sites (11749)

  • Fighting with the VP8 Spec

    4 juin 2010, par Multimedia Mike — VP8

    As stated in a previous blog post on the matter, FFmpeg’s policy is to reimplement codecs rather than adopt other codebases wholesale. And so it is with Google’s recently open sourced VP8 codec, the video portion of their Webm initiative. I happen to know that the new FFmpeg implementation is in the capable hands of several of my co-developers so I’m not even worrying about that angle.

    Instead, I thought of another of my characteristically useless exercises : Create an independent VP8 decoder implementation entirely in pure Python. Silly ? Perhaps. But it has one very practical application : By attempting to write a new decoder based on the official bitstream documentation, this could serve as a mechanism for validating said spec, something near and dear to my heart.

    What is the current state of the spec ? Let me reiterate that I’m glad it exists. As I stated during the initial open sourcing event, everything that Google produced for the initial event went well beyond my wildest expectations. Having said that, the documentation does fall short in a number of places. Fortunately, I am on the Webm mailing lists and am sending in corrections and ideas for general improvement. For the most part, I have been able to understand the general ideas behind the decoding flow based on the spec and am even able to implement certain pieces correctly. Then I usually instrument the libvpx source code with output statements in order to validate that I’m doing everything right.

    Token Blocker
    Unfortunately, I’m quite blocked right now on the chapter regarding token/DCT coefficient decoding (chapter 13 in the current document iteration). In his seminal critique of the codec, Dark Shikari complained that large segments of the spec are just C code fragments copy and pasted from the official production decoder. As annoying as that is, the biggest insult comes at the end of section 13.3 :

    While we have in fact completely described the coefficient decoding procedure, the reader will probably find it helpful to consult the reference implementation, which can be found in the file detokenize.c.

    The reader most certainly will not find it helpful to consult the file detokenize.c. The file in question implements the coefficient residual decoding with an unholy sequence of C macros that contain goto statements. Honestly, I thought I did understand the coefficient decoding procedure based on the spec’s description. But my numbers don’t match up with the official decoder. Instrumenting or tracing macro’d code is obviously painful and studying the same code is making me think I don’t understand the procedure after all. To be fair, entropy decoding often occupies a lot of CPU time for many video decoders and I have little doubt that the macro/goto approach is much faster than clearer, more readable methods. It’s just highly inappropriate to refer to it for pedagogical purposes.

    Aside : For comparison, check out the reference implementation for the VC-1 codec. It was written so clearly and naively that the implementors used an O(n) Huffman decoder. That’s commitment to clarity.

    I wonder if my FFmpeg cohorts are having better luck with the DCT residue decoding in their new libavcodec implementation ? Maybe if I can get this Python decoder working, it can serve as a more appropriate reference decoder.

    Update : Almost immediately after I posted this entry, I figured out a big problem that was holding me back, and then several more small ones, and finally decoded by first correct DCT coefficient from the stream (I’ve never been so happy to see the number -448). I might be back on track now. Even better was realizing that my original understanding of the spec was correct.

    Unrelated
    I found this image on the Doom9 forums. I ROFL’d :



    It’s probably unfair and inaccurate but you have to admit it’s funny. Luckily, quality nitpickings aren’t my department. I’m just interested in getting codecs working, tested, and documented so that more people can use them reliably.

  • aaccoder : Implement Perceptual Noise Substitution for AAC

    15 avril 2015, par Rostislav Pehlivanov
    aaccoder : Implement Perceptual Noise Substitution for AAC
    

    This commit implements the perceptual noise substitution AAC extension. This is a proof of concept
    implementation, and as such, is not enabled by default. This is the fourth revision of this patch,
    made after some problems were noted out. Any changes made since the previous revisions have been indicated.

    In order to extend the encoder to use an additional codebook, the array holding each codebook has been
    modified with two additional entries - 13 for the NOISE_BT codebook and 12 which has a placeholder function.
    The cost system was modified to skip the 12th entry using an array to map the input and outputs it has. It
    also does not accept using the 13th codebook for any band which is not marked as containing noise, thereby
    restricting its ability to arbitrarily choose it for bands. The use of arrays allows the system to be easily
    extended to allow for intensity stereo encoding, which uses additional codebooks.

    The 12th entry in the codebook function array points to a function which stops the execution of the program
    by calling an assert with an always ’false’ argument. It was pointed out in an email discussion with
    Claudio Freire that having a ’NULL’ entry can result in unexpected behaviour and could be used as
    a security hole. There is no danger of this function being called during encoding due to the codebook maps introduced.

    Another change from version 1 of the patch is the addition of an argument to the encoder, ’-aac_pns’ to
    enable and disable the PNS. This currently defaults to disable the PNS, as it is experimental.
    The switch will be removed in the future, when the algorithm to select noise bands has been improved.
    The current algorithm simply compares the energy to the threshold (multiplied by a constant) to determine
    noise, however the FFPsyBand structure contains other useful figures to determine which bands carry noise more accurately.

    Some of the sample files provided triggered an assertion when the parameter to tune the threshold was set to
    a value of ’2.2’. Claudio Freire reported the problem’s source could be in the range of the scalefactor
    indices for noise and advised to measure the minimal index and clip anything above the maximum allowed
    value. This has been implemented and all the files which used to trigger the asserion now encode without error.

    The third revision of the problem also removes unneded variabes and comparisons. All of them were
    redundant and were of little use for when the PNS implementation would be extended.

    The fourth revision moved the clipping of the noise scalefactors outside the second loop of the two-loop
    algorithm in order to prevent their redundant calculations. Also, freq_mult has been changed to a float
    variable due to the fact that rounding errors can prove to be a problem at low frequencies.
    Considerations were taken whether the entire expression could be evaluated inside the expression
    , but in the end it was decided that it would be for the best if just the type of the variable were
    to change. Claudio Freire reported the two problems. There is no change of functionality
    (except for low sampling frequencies) so the spectral demonstrations at the end of this commit’s message were not updated.

    Finally, the way energy values are converted to scalefactor indices has changed since the first commit,
    as per the suggestion of Claudio Freire. This may still have some drawbacks, but unlike the first commit
    it works without having redundant offsets and outputs what the decoder expects to have, in terms of the
    ranges of the scalefactor indices.

    Some spectral comparisons : https://trac.ffmpeg.org/attachment/wiki/Encode/AAC/Original.png (original),
    https://trac.ffmpeg.org/attachment/wiki/Encode/AAC/PNS_NO.png (encoded without PNS),
    https://trac.ffmpeg.org/attachment/wiki/Encode/AAC/PNS1.2.png (encoded with PNS, const = 1.2),
    https://trac.ffmpeg.org/attachment/wiki/Encode/AAC/Difference1.png (spectral difference).
    The constant is the value which multiplies the threshold when it gets compared to the energy, larger
    values means more noise will be substituded by PNS values. Example when const = 2.2 :
    https://trac.ffmpeg.org/attachment/wiki/Encode/AAC/PNS_2.2.png

    Reviewed-by : Claudio Freire <klaussfreire@gmail.com>
    Signed-off-by : Michael Niedermayer <michaelni@gmx.at>

    • [DH] libavcodec/aaccoder.c
    • [DH] libavcodec/aacenc.c
    • [DH] libavcodec/aacenc.h
  • How to encode opus audio file from raw S16 format by ffmpeg c

    13 août 2023, par Nyan Htet

    I used c sample code from ffmpeg tutorial link. In this tutorial, encode to mp2 file. I have tested encoding with AV_CODEC_ID_MP2. And then ffplay can play it. When I change to AV_CODEC_ID_OPUS, ffplay cannot play it.&#xA;I have found both encoder support AV_SAMPLE_FMT_S16 format input.

    &#xA;

    Here is the sample code.

    &#xA;

    #include &#xA;#include &#xA;#include &#xA; &#xA;#include "libavcodec/avcodec.h"&#xA; &#xA;#include "libavutil/channel_layout.h"&#xA;#include "libavutil/common.h"&#xA;#include "libavutil/frame.h"&#xA;#include "libavutil/samplefmt.h"&#xA; &#xA;/* check that a given sample format is supported by the encoder */&#xA;static int check_sample_fmt(const AVCodec *codec, enum AVSampleFormat sample_fmt)&#xA;{&#xA;    const enum AVSampleFormat *p = codec->sample_fmts;&#xA; &#xA;    while (*p != AV_SAMPLE_FMT_NONE) {&#xA;        fprintf(stderr, "%s checking\n", av_get_sample_fmt_name(*p));&#xA;        if (*p == sample_fmt)&#xA;            return 1;&#xA;        p&#x2B;&#x2B;;&#xA;    }&#xA;    return 0;&#xA;}&#xA; &#xA;/* just pick the highest supported samplerate */&#xA;static int select_sample_rate(const AVCodec *codec)&#xA;{&#xA;    const int *p;&#xA;    int best_samplerate = 0;&#xA; &#xA;    if (!codec->supported_samplerates)&#xA;        return 44100;&#xA; &#xA;    p = codec->supported_samplerates;&#xA;    while (*p) {&#xA;        if (!best_samplerate || abs(44100 - *p) &lt; abs(44100 - best_samplerate))&#xA;            best_samplerate = *p;&#xA;        p&#x2B;&#x2B;;&#xA;    }&#xA;    return best_samplerate;&#xA;}&#xA; &#xA;/* select layout with the highest channel count */&#xA;static int select_channel_layout(const AVCodec *codec, AVChannelLayout *dst)&#xA;{&#xA;    const AVChannelLayout *p, *best_ch_layout;&#xA;    int best_nb_channels   = 0;&#xA; &#xA;    if (!codec->ch_layouts)&#xA;        return av_channel_layout_copy(dst, &amp;(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);&#xA; &#xA;    p = codec->ch_layouts;&#xA;    while (p->nb_channels) {&#xA;        int nb_channels = p->nb_channels;&#xA; &#xA;        if (nb_channels > best_nb_channels) {&#xA;            best_ch_layout   = p;&#xA;            best_nb_channels = nb_channels;&#xA;        }&#xA;        p&#x2B;&#x2B;;&#xA;    }&#xA;    return av_channel_layout_copy(dst, best_ch_layout);&#xA;}&#xA; &#xA;static void encode(AVCodecContext *ctx, AVFrame *frame, AVPacket *pkt,&#xA;                   FILE *output)&#xA;{&#xA;    int ret;&#xA; &#xA;    /* send the frame for encoding */&#xA;    ret = avcodec_send_frame(ctx, frame);&#xA;    fprintf(stdout, "This is send frame ret = %i\n",ret);&#xA;    if (ret &lt; 0) {&#xA;        fprintf(stderr, "Error sending the frame to the encoder\n");&#xA;        exit(1);&#xA;    }&#xA; &#xA;    /* read all the available output packets (in general there may be any&#xA;     * number of them */&#xA;    while (ret >= 0) {&#xA;        ret = avcodec_receive_packet(ctx, pkt);&#xA;        fprintf(stdout, "This is receive pkt ret = %i\n",ret);&#xA;        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)&#xA;            return;&#xA;        else if (ret &lt; 0) {&#xA;            fprintf(stderr, "Error encoding audio frame\n");&#xA;            exit(1);&#xA;        }&#xA; &#xA;        fwrite(pkt->data, 1, pkt->size, output);&#xA;        av_packet_unref(pkt);&#xA;    }&#xA;}&#xA; &#xA;int main(int argc, char **argv)&#xA;{&#xA;    const char *filename;&#xA;    const AVCodec *codec;&#xA;    AVCodecContext *c= NULL;&#xA;    AVFrame *frame;&#xA;    AVPacket *pkt;&#xA;    int i, j, k, ret;&#xA;    FILE *f;&#xA;    uint16_t *samples;&#xA;    float t, tincr;&#xA; &#xA;    if (argc &lt;= 1) {&#xA;        fprintf(stderr, "Usage: %s <output file="file">\n", argv[0]);&#xA;        return 0;&#xA;    }&#xA;    filename = argv[1];&#xA; &#xA;    /* find the MP2 encoder */&#xA;    codec = avcodec_find_encoder(AV_CODEC_ID_OPUS);&#xA;    if (!codec) {&#xA;        fprintf(stderr, "Codec not found\n");&#xA;        exit(1);&#xA;    }&#xA; &#xA;    c = avcodec_alloc_context3(codec);&#xA;    if (!c) {&#xA;        fprintf(stderr, "Could not allocate audio codec context\n");&#xA;        exit(1);&#xA;    }&#xA; &#xA;    /* put sample parameters */&#xA;    c->bit_rate = 64000;&#xA; &#xA;    /* check that the encoder supports s16 pcm input */&#xA;    c->sample_fmt = AV_SAMPLE_FMT_S16;&#xA;    if (!check_sample_fmt(codec, c->sample_fmt)) {&#xA;        fprintf(stderr, "Encoder does not support sample format %s",&#xA;                av_get_sample_fmt_name(c->sample_fmt));&#xA;        exit(1);&#xA;    }&#xA; &#xA;    /* select other audio parameters supported by the encoder */&#xA;    c->sample_rate    = select_sample_rate(codec);&#xA;    ret = select_channel_layout(codec, &amp;c->ch_layout);&#xA;    if (ret &lt; 0)&#xA;        exit(1);&#xA; &#xA;    /* open it */&#xA;    if (avcodec_open2(c, codec, NULL) &lt; 0) {&#xA;        fprintf(stderr, "Could not open codec\n");&#xA;        exit(1);&#xA;    }&#xA; &#xA;    f = fopen(filename, "wb");&#xA;    if (!f) {&#xA;        fprintf(stderr, "Could not open %s\n", filename);&#xA;        exit(1);&#xA;    }&#xA; &#xA;    /* packet for holding encoded output */&#xA;    pkt = av_packet_alloc();&#xA;    if (!pkt) {&#xA;        fprintf(stderr, "could not allocate the packet\n");&#xA;        exit(1);&#xA;    }&#xA; &#xA;    /* frame containing input raw audio */&#xA;    frame = av_frame_alloc();&#xA;    if (!frame) {&#xA;        fprintf(stderr, "Could not allocate audio frame\n");&#xA;        exit(1);&#xA;    }&#xA; &#xA;    frame->nb_samples     = c->frame_size;&#xA;    frame->format         = c->sample_fmt;&#xA;    ret = av_channel_layout_copy(&amp;frame->ch_layout, &amp;c->ch_layout);&#xA;    if (ret &lt; 0)&#xA;        exit(1);&#xA; &#xA;    /* allocate the data buffers */&#xA;    ret = av_frame_get_buffer(frame, 0);&#xA;    if (ret &lt; 0) {&#xA;        fprintf(stderr, "Could not allocate audio data buffers\n");&#xA;        exit(1);&#xA;    }&#xA; &#xA;    /* encode a single tone sound */&#xA;    t = 0;&#xA;    tincr = 2 * M_PI * 440.0 / c->sample_rate;&#xA;    for (i = 0; i &lt; 200; i&#x2B;&#x2B;) {&#xA;        /* make sure the frame is writable -- makes a copy if the encoder&#xA;         * kept a reference internally */&#xA;        ret = av_frame_make_writable(frame);&#xA;        if (ret &lt; 0)&#xA;            exit(1);&#xA;        samples = (uint16_t*)frame->data[0];&#xA; &#xA;        for (j = 0; j &lt; c->frame_size; j&#x2B;&#x2B;) {&#xA;            samples[2*j] = (int)(sin(t) * 10000);&#xA; &#xA;            for (k = 1; k &lt; c->ch_layout.nb_channels; k&#x2B;&#x2B;)&#xA;                samples[2*j &#x2B; k] = samples[2*j];&#xA;            t &#x2B;= tincr;&#xA;        }&#xA;        encode(c, frame, pkt, f);&#xA;    }&#xA; &#xA;    /* flush the encoder */&#xA;    encode(c, NULL, pkt, f);&#xA; &#xA;    fclose(f);&#xA; &#xA;    av_frame_free(&amp;frame);&#xA;    av_packet_free(&amp;pkt);&#xA;    avcodec_free_context(&amp;c);&#xA; &#xA;    return 0;&#xA;}&#xA;</output>

    &#xA;

    Thank you for your attention.

    &#xA;

    The executable file is compiled and a.out executable file is generated. How to encode to opus format from raw uint16_t S16 format ?

    &#xA;

    $ gcc encode.c -lavcodec -lavutil -lavformat -lswresample&#xA;

    &#xA;

    // encode to output.mp3 with AV_CODEC_ID_MP2.&#xA;$ ./a.out output.mp3&#xA;$ ffplay output.mp3&#xA;&#xA;// encode to output.opus with AV_CODEC_ID_OPUS.&#xA;$ ./a.out output.opus&#xA;$ ffplay output.opus&#xA;output.opus: Invalid data found when processing input&#xA;

    &#xA;