Recherche avancée

Médias (1)

Mot : - Tags -/Christian Nold

Autres articles (23)

  • Installation en mode ferme

    4 février 2011, par

    Le mode ferme permet d’héberger plusieurs sites de type MediaSPIP en n’installant qu’une seule fois son noyau fonctionnel.
    C’est la méthode que nous utilisons sur cette même plateforme.
    L’utilisation en mode ferme nécessite de connaïtre un peu le mécanisme de SPIP contrairement à la version standalone qui ne nécessite pas réellement de connaissances spécifique puisque l’espace privé habituel de SPIP n’est plus utilisé.
    Dans un premier temps, vous devez avoir installé les mêmes fichiers que l’installation (...)

  • 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" ;

  • Ajouter notes et légendes aux images

    7 février 2011, par

    Pour pouvoir ajouter notes et légendes aux images, la première étape est d’installer le plugin "Légendes".
    Une fois le plugin activé, vous pouvez le configurer dans l’espace de configuration afin de modifier les droits de création / modification et de suppression des notes. Par défaut seuls les administrateurs du site peuvent ajouter des notes aux images.
    Modification lors de l’ajout d’un média
    Lors de l’ajout d’un média de type "image" un nouveau bouton apparait au dessus de la prévisualisation (...)

Sur d’autres sites (6119)

  • How to get FFMPEG to encode H264 using libx264 ?

    4 mai 2020, par Basit Anwer

    FFMPEG encode example fails to create a H264 video. MPEG1 works fine though.

    



    Pasting the code here as well

    



    &#xA;     * @file&#xA;     * video encoding with libavcodec API example&#xA;     *&#xA;     * @example encode_video.c&#xA;     */&#xA;    #include &#xA;    #include &#xA;    #include &#xA;    #include <libavcodec></libavcodec>avcodec.h>&#xA;    #include <libavutil></libavutil>opt.h>&#xA;    #include <libavutil></libavutil>imgutils.h>&#xA;    static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,&#xA;                       FILE *outfile)&#xA;    {&#xA;        int ret;&#xA;        /* send the frame to the encoder */&#xA;        if (frame)&#xA;            printf("Send frame %3"PRId64"\n", frame->pts);&#xA;        ret = avcodec_send_frame(enc_ctx, frame);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Error sending a frame for encoding\n");&#xA;            exit(1);&#xA;        }&#xA;        while (ret >= 0) {&#xA;            ret = avcodec_receive_packet(enc_ctx, pkt);&#xA;            if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)&#xA;                return;&#xA;            else if (ret &lt; 0) {&#xA;                fprintf(stderr, "Error during encoding\n");&#xA;                exit(1);&#xA;            }&#xA;            printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size);&#xA;            fwrite(pkt->data, 1, pkt->size, outfile);&#xA;            av_packet_unref(pkt);&#xA;        }&#xA;    }&#xA;&#xA;    int main(int argc, char **argv)&#xA;    {&#xA;        const char *filename, *codec_name;&#xA;        const AVCodec *codec;&#xA;        AVCodecContext *c= NULL;&#xA;        int i, ret, x, y;&#xA;        FILE *f;&#xA;        AVFrame *frame;&#xA;        AVPacket *pkt;&#xA;        uint8_t endcode[] = { 0, 0, 1, 0xb7 };&#xA;        if (argc &lt;= 2) {&#xA;            fprintf(stderr, "Usage: %s <output file="file"> <codec>\n", argv[0]);&#xA;            exit(0);&#xA;        }&#xA;        filename = argv[1];&#xA;        codec_name = argv[2];&#xA;        /* find the mpeg1video encoder */&#xA;        codec = avcodec_find_encoder_by_name(codec_name);&#xA;        if (!codec) {&#xA;            fprintf(stderr, "Codec &#x27;%s&#x27; not found\n", codec_name);&#xA;            exit(1);&#xA;        }&#xA;        c = avcodec_alloc_context3(codec);&#xA;        if (!c) {&#xA;            fprintf(stderr, "Could not allocate video codec context\n");&#xA;            exit(1);&#xA;        }&#xA;        pkt = av_packet_alloc();&#xA;        if (!pkt)&#xA;            exit(1);&#xA;        /* put sample parameters */&#xA;        c->bit_rate = 400000;&#xA;        /* resolution must be a multiple of two */&#xA;        c->width = 352;&#xA;        c->height = 288;&#xA;        /* frames per second */&#xA;        c->time_base = (AVRational){1, 25};&#xA;        c->framerate = (AVRational){25, 1};&#xA;        /* emit one intra frame every ten frames&#xA;         * check frame pict_type before passing frame&#xA;         * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I&#xA;         * then gop_size is ignored and the output of encoder&#xA;         * will always be I frame irrespective to gop_size&#xA;         */&#xA;        c->gop_size = 10;&#xA;        c->max_b_frames = 1;&#xA;        c->pix_fmt = AV_PIX_FMT_YUV420P;&#xA;        if (codec->id == AV_CODEC_ID_H264)&#xA;            av_opt_set(c->priv_data, "preset", "slow", 0);&#xA;        /* open it */&#xA;        ret = avcodec_open2(c, codec, NULL);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Could not open codec: %s\n", av_err2str(ret));&#xA;            exit(1);&#xA;        }&#xA;        f = fopen(filename, "wb");&#xA;        if (!f) {&#xA;            fprintf(stderr, "Could not open %s\n", filename);&#xA;            exit(1);&#xA;        }&#xA;        frame = av_frame_alloc();&#xA;        if (!frame) {&#xA;            fprintf(stderr, "Could not allocate video frame\n");&#xA;            exit(1);&#xA;        }&#xA;        frame->format = c->pix_fmt;&#xA;        frame->width  = c->width;&#xA;        frame->height = c->height;&#xA;        ret = av_frame_get_buffer(frame, 32);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Could not allocate the video frame data\n");&#xA;            exit(1);&#xA;        }&#xA;        /* encode 1 second of video */&#xA;        for (i = 0; i &lt; 25; i&#x2B;&#x2B;) {&#xA;            fflush(stdout);&#xA;            /* make sure the frame data is writable */&#xA;            ret = av_frame_make_writable(frame);&#xA;            if (ret &lt; 0)&#xA;                exit(1);&#xA;            /* prepare a dummy image */&#xA;            /* Y */&#xA;            for (y = 0; y &lt; c->height; y&#x2B;&#x2B;) {&#xA;                for (x = 0; x &lt; c->width; x&#x2B;&#x2B;) {&#xA;                    frame->data[0][y * frame->linesize[0] &#x2B; x] = x &#x2B; y &#x2B; i * 3;&#xA;                }&#xA;            }&#xA;            /* Cb and Cr */&#xA;            for (y = 0; y &lt; c->height/2; y&#x2B;&#x2B;) {&#xA;                for (x = 0; x &lt; c->width/2; x&#x2B;&#x2B;) {&#xA;                    frame->data[1][y * frame->linesize[1] &#x2B; x] = 128 &#x2B; y &#x2B; i * 2;&#xA;                    frame->data[2][y * frame->linesize[2] &#x2B; x] = 64 &#x2B; x &#x2B; i * 5;&#xA;                }&#xA;            }&#xA;            frame->pts = i;&#xA;            /* encode the image */&#xA;            encode(c, frame, pkt, f);&#xA;        }&#xA;        /* flush the encoder */&#xA;        encode(c, NULL, pkt, f);&#xA;        /* add sequence end code to have a real MPEG file */&#xA;        if (codec->id == AV_CODEC_ID_MPEG1VIDEO || codec->id == AV_CODEC_ID_MPEG2VIDEO)&#xA;            fwrite(endcode, 1, sizeof(endcode), f);&#xA;        fclose(f);&#xA;        avcodec_free_context(&amp;c);&#xA;        av_frame_free(&amp;frame);&#xA;        av_packet_free(&amp;pkt);&#xA;        return 0;&#xA;    }&#xA;</codec></output>

    &#xA;&#xA;

    The code fails at encode call and every avcodec_receive_packet call returns AVERROR(EAGAIN)

    &#xA;&#xA;

    What am i missing here ?

    &#xA;

  • Unable to encode H264 video using FFMPEG example

    4 mai 2020, par Basit Anwer

    FFMPEG encode example fails to create a H264 video. MPEG1 works fine though.

    &#xA;&#xA;

    Pasting the code here as well

    &#xA;&#xA;

    &#xA;     * @file&#xA;     * video encoding with libavcodec API example&#xA;     *&#xA;     * @example encode_video.c&#xA;     */&#xA;    #include &#xA;    #include &#xA;    #include &#xA;    #include <libavcodec></libavcodec>avcodec.h>&#xA;    #include <libavutil></libavutil>opt.h>&#xA;    #include <libavutil></libavutil>imgutils.h>&#xA;    static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,&#xA;                       FILE *outfile)&#xA;    {&#xA;        int ret;&#xA;        /* send the frame to the encoder */&#xA;        if (frame)&#xA;            printf("Send frame %3"PRId64"\n", frame->pts);&#xA;        ret = avcodec_send_frame(enc_ctx, frame);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Error sending a frame for encoding\n");&#xA;            exit(1);&#xA;        }&#xA;        while (ret >= 0) {&#xA;            ret = avcodec_receive_packet(enc_ctx, pkt);&#xA;            if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)&#xA;                return;&#xA;            else if (ret &lt; 0) {&#xA;                fprintf(stderr, "Error during encoding\n");&#xA;                exit(1);&#xA;            }&#xA;            printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size);&#xA;            fwrite(pkt->data, 1, pkt->size, outfile);&#xA;            av_packet_unref(pkt);&#xA;        }&#xA;    }&#xA;&#xA;    int main(int argc, char **argv)&#xA;    {&#xA;        const char *filename, *codec_name;&#xA;        const AVCodec *codec;&#xA;        AVCodecContext *c= NULL;&#xA;        int i, ret, x, y;&#xA;        FILE *f;&#xA;        AVFrame *frame;&#xA;        AVPacket *pkt;&#xA;        uint8_t endcode[] = { 0, 0, 1, 0xb7 };&#xA;        if (argc &lt;= 2) {&#xA;            fprintf(stderr, "Usage: %s <output file="file"> <codec>\n", argv[0]);&#xA;            exit(0);&#xA;        }&#xA;        filename = argv[1];&#xA;        codec_name = argv[2];&#xA;        /* find the mpeg1video encoder */&#xA;        codec = avcodec_find_encoder_by_name(codec_name);&#xA;        if (!codec) {&#xA;            fprintf(stderr, "Codec &#x27;%s&#x27; not found\n", codec_name);&#xA;            exit(1);&#xA;        }&#xA;        c = avcodec_alloc_context3(codec);&#xA;        if (!c) {&#xA;            fprintf(stderr, "Could not allocate video codec context\n");&#xA;            exit(1);&#xA;        }&#xA;        pkt = av_packet_alloc();&#xA;        if (!pkt)&#xA;            exit(1);&#xA;        /* put sample parameters */&#xA;        c->bit_rate = 400000;&#xA;        /* resolution must be a multiple of two */&#xA;        c->width = 352;&#xA;        c->height = 288;&#xA;        /* frames per second */&#xA;        c->time_base = (AVRational){1, 25};&#xA;        c->framerate = (AVRational){25, 1};&#xA;        /* emit one intra frame every ten frames&#xA;         * check frame pict_type before passing frame&#xA;         * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I&#xA;         * then gop_size is ignored and the output of encoder&#xA;         * will always be I frame irrespective to gop_size&#xA;         */&#xA;        c->gop_size = 10;&#xA;        c->max_b_frames = 1;&#xA;        c->pix_fmt = AV_PIX_FMT_YUV420P;&#xA;        if (codec->id == AV_CODEC_ID_H264)&#xA;            av_opt_set(c->priv_data, "preset", "slow", 0);&#xA;        /* open it */&#xA;        ret = avcodec_open2(c, codec, NULL);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Could not open codec: %s\n", av_err2str(ret));&#xA;            exit(1);&#xA;        }&#xA;        f = fopen(filename, "wb");&#xA;        if (!f) {&#xA;            fprintf(stderr, "Could not open %s\n", filename);&#xA;            exit(1);&#xA;        }&#xA;        frame = av_frame_alloc();&#xA;        if (!frame) {&#xA;            fprintf(stderr, "Could not allocate video frame\n");&#xA;            exit(1);&#xA;        }&#xA;        frame->format = c->pix_fmt;&#xA;        frame->width  = c->width;&#xA;        frame->height = c->height;&#xA;        ret = av_frame_get_buffer(frame, 32);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Could not allocate the video frame data\n");&#xA;            exit(1);&#xA;        }&#xA;        /* encode 1 second of video */&#xA;        for (i = 0; i &lt; 25; i&#x2B;&#x2B;) {&#xA;            fflush(stdout);&#xA;            /* make sure the frame data is writable */&#xA;            ret = av_frame_make_writable(frame);&#xA;            if (ret &lt; 0)&#xA;                exit(1);&#xA;            /* prepare a dummy image */&#xA;            /* Y */&#xA;            for (y = 0; y &lt; c->height; y&#x2B;&#x2B;) {&#xA;                for (x = 0; x &lt; c->width; x&#x2B;&#x2B;) {&#xA;                    frame->data[0][y * frame->linesize[0] &#x2B; x] = x &#x2B; y &#x2B; i * 3;&#xA;                }&#xA;            }&#xA;            /* Cb and Cr */&#xA;            for (y = 0; y &lt; c->height/2; y&#x2B;&#x2B;) {&#xA;                for (x = 0; x &lt; c->width/2; x&#x2B;&#x2B;) {&#xA;                    frame->data[1][y * frame->linesize[1] &#x2B; x] = 128 &#x2B; y &#x2B; i * 2;&#xA;                    frame->data[2][y * frame->linesize[2] &#x2B; x] = 64 &#x2B; x &#x2B; i * 5;&#xA;                }&#xA;            }&#xA;            frame->pts = i;&#xA;            /* encode the image */&#xA;            encode(c, frame, pkt, f);&#xA;        }&#xA;        /* flush the encoder */&#xA;        encode(c, NULL, pkt, f);&#xA;        /* add sequence end code to have a real MPEG file */&#xA;        if (codec->id == AV_CODEC_ID_MPEG1VIDEO || codec->id == AV_CODEC_ID_MPEG2VIDEO)&#xA;            fwrite(endcode, 1, sizeof(endcode), f);&#xA;        fclose(f);&#xA;        avcodec_free_context(&amp;c);&#xA;        av_frame_free(&amp;frame);&#xA;        av_packet_free(&amp;pkt);&#xA;        return 0;&#xA;    }&#xA;</codec></output>

    &#xA;&#xA;

    The code fails at encode call and every avcodec_receive_packet call returns AVERROR(EAGAIN)

    &#xA;&#xA;

    What am i missing here ?

    &#xA;

  • Unable to encode H264 video using FFMPEG example

    4 mai 2020, par Basit Anwer

    FFMPEG encode example fails to create a H264 video. MPEG1 works fine though.

    &#xA;&#xA;

    Pasting the code here as well

    &#xA;&#xA;

    &#xA;     * @file&#xA;     * video encoding with libavcodec API example&#xA;     *&#xA;     * @example encode_video.c&#xA;     */&#xA;    #include &#xA;    #include &#xA;    #include &#xA;    #include <libavcodec></libavcodec>avcodec.h>&#xA;    #include <libavutil></libavutil>opt.h>&#xA;    #include <libavutil></libavutil>imgutils.h>&#xA;    static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,&#xA;                       FILE *outfile)&#xA;    {&#xA;        int ret;&#xA;        /* send the frame to the encoder */&#xA;        if (frame)&#xA;            printf("Send frame %3"PRId64"\n", frame->pts);&#xA;        ret = avcodec_send_frame(enc_ctx, frame);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Error sending a frame for encoding\n");&#xA;            exit(1);&#xA;        }&#xA;        while (ret >= 0) {&#xA;            ret = avcodec_receive_packet(enc_ctx, pkt);&#xA;            if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)&#xA;                return;&#xA;            else if (ret &lt; 0) {&#xA;                fprintf(stderr, "Error during encoding\n");&#xA;                exit(1);&#xA;            }&#xA;            printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size);&#xA;            fwrite(pkt->data, 1, pkt->size, outfile);&#xA;            av_packet_unref(pkt);&#xA;        }&#xA;    }&#xA;&#xA;    int main(int argc, char **argv)&#xA;    {&#xA;        const char *filename, *codec_name;&#xA;        const AVCodec *codec;&#xA;        AVCodecContext *c= NULL;&#xA;        int i, ret, x, y;&#xA;        FILE *f;&#xA;        AVFrame *frame;&#xA;        AVPacket *pkt;&#xA;        uint8_t endcode[] = { 0, 0, 1, 0xb7 };&#xA;        if (argc &lt;= 2) {&#xA;            fprintf(stderr, "Usage: %s <output file="file"> <codec>\n", argv[0]);&#xA;            exit(0);&#xA;        }&#xA;        filename = argv[1];&#xA;        codec_name = argv[2];&#xA;        /* find the mpeg1video encoder */&#xA;        codec = avcodec_find_encoder_by_name(codec_name);&#xA;        if (!codec) {&#xA;            fprintf(stderr, "Codec &#x27;%s&#x27; not found\n", codec_name);&#xA;            exit(1);&#xA;        }&#xA;        c = avcodec_alloc_context3(codec);&#xA;        if (!c) {&#xA;            fprintf(stderr, "Could not allocate video codec context\n");&#xA;            exit(1);&#xA;        }&#xA;        pkt = av_packet_alloc();&#xA;        if (!pkt)&#xA;            exit(1);&#xA;        /* put sample parameters */&#xA;        c->bit_rate = 400000;&#xA;        /* resolution must be a multiple of two */&#xA;        c->width = 352;&#xA;        c->height = 288;&#xA;        /* frames per second */&#xA;        c->time_base = (AVRational){1, 25};&#xA;        c->framerate = (AVRational){25, 1};&#xA;        /* emit one intra frame every ten frames&#xA;         * check frame pict_type before passing frame&#xA;         * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I&#xA;         * then gop_size is ignored and the output of encoder&#xA;         * will always be I frame irrespective to gop_size&#xA;         */&#xA;        c->gop_size = 10;&#xA;        c->max_b_frames = 1;&#xA;        c->pix_fmt = AV_PIX_FMT_YUV420P;&#xA;        if (codec->id == AV_CODEC_ID_H264)&#xA;            av_opt_set(c->priv_data, "preset", "slow", 0);&#xA;        /* open it */&#xA;        ret = avcodec_open2(c, codec, NULL);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Could not open codec: %s\n", av_err2str(ret));&#xA;            exit(1);&#xA;        }&#xA;        f = fopen(filename, "wb");&#xA;        if (!f) {&#xA;            fprintf(stderr, "Could not open %s\n", filename);&#xA;            exit(1);&#xA;        }&#xA;        frame = av_frame_alloc();&#xA;        if (!frame) {&#xA;            fprintf(stderr, "Could not allocate video frame\n");&#xA;            exit(1);&#xA;        }&#xA;        frame->format = c->pix_fmt;&#xA;        frame->width  = c->width;&#xA;        frame->height = c->height;&#xA;        ret = av_frame_get_buffer(frame, 32);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Could not allocate the video frame data\n");&#xA;            exit(1);&#xA;        }&#xA;        /* encode 1 second of video */&#xA;        for (i = 0; i &lt; 25; i&#x2B;&#x2B;) {&#xA;            fflush(stdout);&#xA;            /* make sure the frame data is writable */&#xA;            ret = av_frame_make_writable(frame);&#xA;            if (ret &lt; 0)&#xA;                exit(1);&#xA;            /* prepare a dummy image */&#xA;            /* Y */&#xA;            for (y = 0; y &lt; c->height; y&#x2B;&#x2B;) {&#xA;                for (x = 0; x &lt; c->width; x&#x2B;&#x2B;) {&#xA;                    frame->data[0][y * frame->linesize[0] &#x2B; x] = x &#x2B; y &#x2B; i * 3;&#xA;                }&#xA;            }&#xA;            /* Cb and Cr */&#xA;            for (y = 0; y &lt; c->height/2; y&#x2B;&#x2B;) {&#xA;                for (x = 0; x &lt; c->width/2; x&#x2B;&#x2B;) {&#xA;                    frame->data[1][y * frame->linesize[1] &#x2B; x] = 128 &#x2B; y &#x2B; i * 2;&#xA;                    frame->data[2][y * frame->linesize[2] &#x2B; x] = 64 &#x2B; x &#x2B; i * 5;&#xA;                }&#xA;            }&#xA;            frame->pts = i;&#xA;            /* encode the image */&#xA;            encode(c, frame, pkt, f);&#xA;        }&#xA;        /* flush the encoder */&#xA;        encode(c, NULL, pkt, f);&#xA;        /* add sequence end code to have a real MPEG file */&#xA;        if (codec->id == AV_CODEC_ID_MPEG1VIDEO || codec->id == AV_CODEC_ID_MPEG2VIDEO)&#xA;            fwrite(endcode, 1, sizeof(endcode), f);&#xA;        fclose(f);&#xA;        avcodec_free_context(&amp;c);&#xA;        av_frame_free(&amp;frame);&#xA;        av_packet_free(&amp;pkt);&#xA;        return 0;&#xA;    }&#xA;</codec></output>

    &#xA;&#xA;

    The code fails at encode call and every avcodec_receive_packet call returns AVERROR(EAGAIN)

    &#xA;&#xA;

    What am i missing here ?

    &#xA;