Recherche avancée

Médias (91)

Autres articles (5)

  • Encoding and processing into web-friendly formats

    13 avril 2011, par

    MediaSPIP automatically converts uploaded files to internet-compatible formats.
    Video files are encoded in MP4, Ogv and WebM (supported by HTML5) and MP4 (supported by Flash).
    Audio files are encoded in MP3 and Ogg (supported by HTML5) and MP3 (supported by Flash).
    Where possible, text is analyzed in order to retrieve the data needed for search engine detection, and then exported as a series of image files.
    All uploaded files are stored online in their original format, so you can (...)

  • Supporting all media types

    13 avril 2011, par

    Unlike most software and media-sharing platforms, MediaSPIP aims to manage as many different media types as possible. The following are just a few examples from an ever-expanding list of supported formats : images : png, gif, jpg, bmp and more audio : MP3, Ogg, Wav and more video : AVI, MP4, OGV, mpg, mov, wmv and more text, code and other data : OpenOffice, Microsoft Office (Word, PowerPoint, Excel), web (html, CSS), LaTeX, Google Earth and (...)

  • MediaSPIP Init et Diogène : types de publications de MediaSPIP

    11 novembre 2010, par

    À l’installation d’un site MediaSPIP, le plugin MediaSPIP Init réalise certaines opérations dont la principale consiste à créer quatre rubriques principales dans le site et de créer cinq templates de formulaire pour Diogène.
    Ces quatre rubriques principales (aussi appelées secteurs) sont : Medias ; Sites ; Editos ; Actualités ;
    Pour chacune de ces rubriques est créé un template de formulaire spécifique éponyme. Pour la rubrique "Medias" un second template "catégorie" est créé permettant d’ajouter (...)

Sur d’autres sites (1298)

  • convert pcm stream data to encoded aac data

    24 décembre 2019, par Kumar

    I tried to convert pulse-audio pcm stream data to aac encoded data using ffmpeg.
    But after encoding I get noise-full data, not the correct one. Here I post my code, anyone help me with some ideas.

    Initial configuration :

       av_register_all();

       int error;
       if ((error = avio_open(&output_io_context,"out.aac",AVIO_FLAG_WRITE))<0) {
               printf("could not open output file\n");
       }

       if (!(output_format_context = avformat_alloc_context())) {
               printf("output_format_context error\n");
       }

       output_format_context->pb = output_io_context;

       if(!(output_format_context->oformat = av_guess_format(NULL, "out.aac", NULL))) {
               printf("guess format error\n");
       }

       codec = avcodec_find_encoder(AV_CODEC_ID_AAC);
       if (codec == NULL) {
               printf("avcodec_find_encoder: ERROR\n");
       }

       if (!(stream = avformat_new_stream(output_format_context, NULL))) {
               printf("stream create error\n");
       }
       output_codec_context = avcodec_alloc_context3(codec);
       if(!output_codec_context) {
               printf("output_codec_context is null\n");
       }

       output_codec_context->channels       = CHANNELS;
       output_codec_context->channel_layout = av_get_default_channel_layout(CHANNELS);
       output_codec_context->sample_rate    = SAMPLE_RATE; //input_codec_context->sample_rate;
       output_codec_context->sample_fmt     = codec->sample_fmts[0];
       output_codec_context->bit_rate       = 48000; //OUTPUT_BIT_RATE;

       stream->time_base.den = SAMPLE_RATE;//input_codec_context->sample_rate;
       stream->time_base.num = 1;

       if(output_format_context->oformat->flags & AVFMT_GLOBALHEADER)
               output_codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;

       if ((error = avcodec_open2(output_codec_context, codec, NULL)) < 0) {
           printf("error");
       }

       error = avcodec_parameters_from_context(stream->codecpar, output_codec_context);

       if (write_output_file_header(output_format_context)) {
               printf("write header failure...\n");
       }

    Data encoding :

    AVFrame *output_frame;
    int frame_pos = 0, ctx_frame_size = output_codec_context->frame_size;
    int size = av_samples_get_buffer_size(NULL, CHANNELS,
                 output_codec_context->frame_size,output_codec_context->sample_fmt, 1);
    if((x =  avcodec_fill_audio_frame(output_frame, CHANNELS,
                  output_codec_context->sample_fmt, data, length, 1)) < 0) {
         printf("avcodec_fill_audio_frame error : %s\n", av_err2str(x));
    }

    int data_written;
    if (encode_audio_frame(output_frame, output_format_context,
               output_codec_context, &data_written)) {
           printf("encode_audio_frame error\n");
     }

     av_frame_free(&output_frame);

    helper_function :

    int encode_audio_frame(AVFrame *frame,AVFormatContext *output_format_context,
                 AVCodecContext *output_codec_context, int *data_present)
    {
      AVPacket output_packet;
      int error;
      init_packet(&output_packet);

      if (frame) {
         frame->pts = pts;
         pts += frame->nb_samples;
      }

      error = avcodec_send_frame(output_codec_context, frame);
      if (error == AVERROR_EOF) {
        error = 0;
        goto cleanup;
      } else if (error < 0) {
         fprintf(stderr, "Could not send packet for encoding (error '%s')\n",
               av_err2str(error));
         return error;
      }

      error = avcodec_receive_packet(output_codec_context, &output_packet);
      if (error == AVERROR(EAGAIN)) {
        error = 0;
        goto cleanup;
      } else if (error == AVERROR_EOF) {
         error = 0;
         goto cleanup;
      } else if (error < 0) {
         fprintf(stderr, "Could not encode frame (error '%s')\n",
               av_err2str(error));
         goto cleanup;
      } else {
         *data_present = 1;
     }

     if (*data_present &&
         (error = av_write_frame(output_format_context, &output_packet)) < 0) {
         fprintf(stderr, "Could not write frame (error '%s')\n",
                av_err2str(error));
         goto cleanup;
     }

     cleanup:
         av_packet_unref(&output_packet);
         return error;
    }
    • Do we need to fill AVFrame with sizeof(av_samples_get_buffer_size) or context->frame_size ?

    TYIA :) !!

  • vp9lpf/x86 : save one register in loopfilter surface coverage.

    20 décembre 2014, par Ronald S. Bultje
    vp9lpf/x86 : save one register in loopfilter surface coverage.
    

    Signed-off-by : Anton Khirnov <anton@khirnov.net>

    • [DBH] libavcodec/x86/vp9lpf.asm
  • Problem : FFmpeg and C++ extract and save frame

    26 mai 2021, par Simba_cl25

    I am doing a project where I must do the following : extract frames (along with the associated metadata - KLV) from a video given a period (for the moment every 10 seconds).&#xA;I have followed codes found on internet but I get an error that I can find a solution to.

    &#xA;

    extern "C" {&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libavdevice></libavdevice>avdevice.h>&#xA;#include <libswscale></libswscale>swscale.h>&#xA;#include <libavfilter></libavfilter>avfilter.h>&#xA;#include <libswresample></libswresample>swresample.h>&#xA;#include <libavutil></libavutil>avutil.h>&#xA;#include <libavutil></libavutil>imgutils.h> &#xA;}&#xA;&#xA;static void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame);&#xA;&#xA;&#xA;int main(int argc, const char * argv[])&#xA;{&#xA;    AVFormatContext *pFormatCtx;&#xA;    int             i, videoStream;&#xA;    AVCodecContext  *pCodecCtx = NULL;&#xA;    const AVCodec         *pCodec = NULL;&#xA;    AVFrame         *pFrame;&#xA;    AVFrame         *pFrameRGB;&#xA;    AVPacket        *packet = av_packet_alloc();&#xA;    AVStream        *pStream;&#xA;    int             numBytes;&#xA;    int64_t         Duration;&#xA;    uint8_t         *buffer;&#xA;    bool frameFinished = false;&#xA;&#xA;    // Open video file - check for errors&#xA;    pFormatCtx = 0;&#xA;    if (avformat_open_input(&amp;pFormatCtx, "00Video\\VideoR.ts", 0, 0) != 0)&#xA;        return -1; &#xA;&#xA;    if (avformat_find_stream_info(pFormatCtx, 0) &lt; 0)&#xA;        return -1;&#xA;&#xA;    if (av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, 0, 0) &lt;0)&#xA;        return -1;&#xA;&#xA;    av_dump_format(pFormatCtx, 0, "00Video\\VideoR.ts", false);&#xA;&#xA;&#xA;    // Find the first video stream&#xA;    videoStream = -1;&#xA;    for (i = 0; i &lt; pFormatCtx->nb_streams; i&#x2B;&#x2B;)&#xA;        if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)&#xA;        {&#xA;            videoStream = i;&#xA;            break;&#xA;        }&#xA;    if (videoStream == -1)&#xA;        return -1; &#xA;    &#xA;&#xA;&#xA;    // Find the decoder for the video stream&#xA;    pCodec = avcodec_find_decoder(pFormatCtx->streams[videoStream]->codecpar->codec_id);&#xA;    pCodecCtx = avcodec_alloc_context3(pCodec);&#xA;&#xA;    if (pCodec == NULL)&#xA;    {&#xA;        fprintf(stderr, "Codec not found\n");&#xA;        return -1; &#xA;    }&#xA;&#xA;&#xA;    if (avcodec_open2(pCodecCtx, pCodec, NULL) &lt; 0)&#xA;    {&#xA;        fprintf(stderr, "Could not open codec\n");&#xA;        return -1; &#xA;    }&#xA;&#xA;    // Hack to correct wrong frame rates that seem to be generated by some codecs&#xA;    if (pCodecCtx->time_base.num > 1000 &amp;&amp; pCodecCtx->time_base.den == 1)&#xA;        pCodecCtx->time_base.den = 1000;&#xA;&#xA;&#xA;&#xA;&#xA;    // Allocate video frame - original frame &#xA;    pFrame = av_frame_alloc();&#xA;&#xA;    if (!pFrame) {&#xA;        fprintf(stderr, "Could not allocate video frame\n");&#xA;        return -1;&#xA;    }&#xA;&#xA;&#xA;    // Allocate an AVFrame structure&#xA;    pFrameRGB = av_frame_alloc();&#xA;&#xA;    if (pFrameRGB == NULL)&#xA;    {&#xA;        fprintf(stderr, "Could not allocate video RGB frame\n");&#xA;        return -1;&#xA;    }&#xA;&#xA;    &#xA;    Duration = av_rescale_q(vstrm->duration, vstrm->time_base, { 1,1000 });&#xA;    &#xA;    numBytes = av_image_get_buffer_size(pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, 0);&#xA;    buffer = (uint8_t*)av_malloc(numBytes * sizeof(uint8_t));&#xA;&#xA;&#xA;    av_image_fill_arrays(pFrameRGB->data, pFrameRGB->linesize, buffer, AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height, 1);&#xA;    &#xA;    &#xA;        &#xA;    &#xA;    i = 0;&#xA;    while (av_read_frame(pFormatCtx, packet) >= 0)&#xA;    {&#xA;        // Is this a packet from the video stream?&#xA;        if (packet->stream_index == videoStream)&#xA;        {&#xA;            int ret;&#xA;            ret = avcodec_send_packet(pCodecCtx, packet);&#xA;            if (ret &lt; 0 || ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {&#xA;                fprintf(stderr, "Error sending a packet for decoding\n");&#xA;                //break;&#xA;            }&#xA;            while (ret >= 0) {&#xA;                ret = avcodec_receive_frame(pCodecCtx, pFrame);&#xA;                if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)&#xA;                    return -1;&#xA;                else if (ret &lt; 0) {&#xA;                    fprintf(stderr, "Error during decoding\n");&#xA;                    return -1;&#xA;                 frameFinished = true;&#xA;                }&#xA;&#xA;&#xA;                // Did we get a video frame?&#xA;                if (frameFinished)&#xA;                {&#xA;                    static struct SwsContext *img_convert_ctx;&#xA;&#xA;                    &#xA;                    if (img_convert_ctx == NULL) {&#xA;                        int w = pCodecCtx->width;&#xA;                        int h = pCodecCtx->height;&#xA;                        img_convert_ctx = sws_getContext(w, h,&#xA;                            pCodecCtx->pix_fmt,&#xA;                            w, h, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR,&#xA;                            NULL, NULL, NULL);&#xA;&#xA;                        if (img_convert_ctx == NULL) {&#xA;                            fprintf(stderr, "Cannot initialize the conversion context!\n");&#xA;                            exit(1);&#xA;                        }&#xA;                    }&#xA;&#xA;                    int ret = sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0,&#xA;                        pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);&#xA;&#xA;&#xA;                    // Save the frame to disk&#xA;                    if (i &lt;= Duration)&#xA;                    {&#xA;                        SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, i);&#xA;                        i &#x2B;= 10*1000;&#xA;                    }&#xA;                }&#xA;            }&#xA;&#xA;        &#xA;        }&#xA;&#xA;        // Free the packet that was allocated by av_read_frame&#xA;        av_packet_unref(packet);&#xA;    }&#xA;&#xA;    &#xA;&#xA;    // Free the RGB image&#xA;    free(buffer);&#xA;    av_free(pFrameRGB);&#xA;&#xA;    // Free the YUV frame&#xA;    av_free(pFrame);&#xA;&#xA;    // Close the codec&#xA;    avcodec_close(pCodecCtx);&#xA;&#xA;    // Close the video file&#xA;    avformat_close_input(&amp;pFormatCtx);&#xA;    return 0;&#xA;    &#xA;}&#xA;&#xA;&#xA;&#xA;&#xA;static void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame)&#xA;{&#xA;    FILE *pFile;&#xA;    char szFilename[32];&#xA;    int  y;&#xA;&#xA;&#xA;    // Open file&#xA;    sprintf(szFilename, "Im\\frame%d.png", iFrame);&#xA;    pFile = fopen(szFilename, "wb");&#xA;    if (pFile == NULL)&#xA;        return;&#xA;&#xA;    // Write header&#xA;    fprintf(pFile, "P6\n%d %d\n255\n", width, height);&#xA;    // Write pixel data&#xA;    for (y = 0; y &lt; height; y&#x2B;&#x2B;)&#xA;        fwrite(pFrame->data[0] &#x2B; y * pFrame->linesize[0], 1, width*3, pFile);&#xA;&#xA;    // Close file&#xA;    fclose(pFile);&#xA;}&#xA;

    &#xA;

    The error I get is :

    &#xA;

    [swscaler @ 03055A80] bad dst image pointers&#xA;

    &#xA;

    I think is because

    &#xA;

    numBytes = av_image_get_buffer_size(pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, 0);&#xA;

    &#xA;

    Returns a negative value ( -22) but I don't know why.

    &#xA;

    Thanks,

    &#xA;