Recherche avancée

Médias (2)

Mot : - Tags -/media

Autres articles (56)

  • Personnaliser en ajoutant son logo, sa bannière ou son image de fond

    5 septembre 2013, par

    Certains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;

  • Ecrire une actualité

    21 juin 2013, par

    Présentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
    Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
    Vous pouvez personnaliser le formulaire de création d’une actualité.
    Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

Sur d’autres sites (8934)

  • how to decode wmp3 video using libavcodec ? (ffmpeg)

    13 mars 2012, par Renan Elias

    I'm developing an application that reads a live tv stream from the internet and I need to play it on my ipad application.

    I've compiled the ffmpeg into my ipad application to use the libavcodec lib, but I've not been able to use it in this lib...

    I know how to get the stream packets, read if it is an audio or video packet, but I don't know how to use the lib to convert the original packet codecs to h264 and mp3 codec...

    I need to convert an stream packet wmv3 to h264 and save it on a file.

    My code is below...

    AVFormatContext* pFormatCtx = avformat_alloc_context();
    int             i, videoStream, audioStream;
    AVCodecContext  *pCodecCtx;
    AVCodecContext *aCodecCtx;
    AVCodec         *pCodec;
    AVCodec         *aCodec;
    AVFrame         *pFrame;
    AVFrame         *pFrameRGB;
    AVPacket        packet;
    int             frameFinished;
    int             numBytes;
    uint8_t         *buffer;

    static struct SwsContext *img_convert_ctx;


    // Register all formats and codecs
    av_register_all();
    avcodec_register_all();
    avformat_network_init();

    // Open video file
    if(avformat_open_input(&pFormatCtx, [objURL cStringUsingEncoding:NSASCIIStringEncoding] ,NULL,NULL) != 0){
       return -1;
    }

    // Retrieve stream information
    if(avformat_find_stream_info(pFormatCtx, NULL)<0)
       return -1; // Couldn't find stream information

    // Dump information about file onto standard error
    av_dump_format(pFormatCtx, 0, [objURL cStringUsingEncoding:NSASCIIStringEncoding], 0);

    // Find the first video stream
    videoStream=-1;
    audioStream=-1;
    for(i=0; i < pFormatCtx->nb_streams; i++) {
       if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO && videoStream < 0) {
           videoStream=i;
       }
       if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO && audioStream < 0) {
           audioStream=i;
       }
    }
    if(videoStream==-1)
       return -1; // Didn't find a video stream
    if(audioStream==-1)
       return -1;

    // Get a pointer to the codec context for the video stream
    pCodecCtx=pFormatCtx->streams[videoStream]->codec;

    // Find the decoder for the video stream
    pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
    if(pCodec==NULL) {
       fprintf(stderr, "Unsupported codec!\n");
       return -1; // Codec not found
    }

    // Open codec
    if(avcodec_open2(pCodecCtx, pCodec, NULL)<0)
       return -1; // Could not open codec

    // Get a pointer to the codec context for the audio stream
    aCodecCtx=pFormatCtx->streams[audioStream]->codec;

    // Find the decoder for the audio stream
    aCodec = avcodec_find_decoder(aCodecCtx->codec_id);
    if(!aCodec) {
       fprintf(stderr, "Unsupported codec!\n");
       return -1; // Codec not found
    }

    // Open codec
    if(avcodec_open2(aCodecCtx, aCodec, NULL)<0)
       return -1; // Could not open codec

    // Allocate video frame
    pFrame=avcodec_alloc_frame();

    // Allocate an AVFrame structure
    pFrameRGB=avcodec_alloc_frame();
    if(pFrameRGB==NULL)
       return -1;

    // Determine required buffer size and allocate buffer
    numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,
                               pCodecCtx->height);
    buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));

    // Assign appropriate parts of buffer to image planes in pFrameRGB
    // Note that pFrameRGB is an AVFrame, but AVFrame is a superset
    // of AVPicture
    avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
                  pCodecCtx->width, pCodecCtx->height);

    // Read frames and save first five frames to disk
    i=0;
    while(av_read_frame(pFormatCtx, &packet)>=0) {
       // Is this a packet from the video stream?
       if(packet.stream_index==audioStream) {
           NSLog(@"Audio.. i'll solve the video first...");
       } else if(packet.stream_index==videoStream) {

           /// HOW CONVERT THIS VIDEO PACKET TO H264 and save on a file? :(
       }

       // Free the packet that was allocated by av_read_frame
       av_free_packet(&packet);
    }

    // Free the RGB image
    av_free(buffer);
    av_free(pFrameRGB);

    // Free the YUV frame
    av_free(pFrame);

    // Close the codec
    avcodec_close(pCodecCtx);

    // Close the video file
    avformat_close_input(&pFormatCtx);

    return 0;
  • ffmpeg transcode

    12 novembre 2015, par user2004388

    I want to do a audio trancode using ffmpeg library. Now i have out file but I can listen only noise .
    The steps of my program are :
    1) Open input file and decode in raw format using avcodec_decode_audio4
    2) encode and save the raw format .
    I don’t Know where I wrong. This is my code.

    /*
    * File:   newmain.c
    * Author: antonello
    *
    * Created on 23 gennaio 2013, 11.24
    */

    #include
    #include


    #include <libavutil></libavutil>samplefmt.h>
    #include <libavutil></libavutil>timestamp.h>
    #include <libavformat></libavformat>avformat.h>
    #include <libavcodec></libavcodec>old_codec_ids.h>

    static AVCodecContext *get_encoder(int sampleRate, int channels, int audioBitrate)
    {
       AVCodecContext  *audioCodec;
       AVCodec *codec;



       //Set up audio encoder
       codec = avcodec_find_encoder(CODEC_ID_AAC);
       if (codec == NULL)
       {
           printf("avcodec_find_encoder: ERROR\n");
           return NULL;
       }
       audioCodec = avcodec_alloc_context();
       audioCodec->bit_rate = audioBitrate;
       audioCodec->sample_fmt = AV_SAMPLE_FMT_S16P;
       audioCodec->sample_rate = sampleRate;
       audioCodec->channels = channels;
       audioCodec->profile = FF_PROFILE_AAC_MAIN;
       audioCodec->channel_layout=AV_CH_LAYOUT_MONO;
       //audioCodec->time_base = (AVRational){1, sampleRate};
       audioCodec->time_base.num  = 1;
       audioCodec->time_base.den  = sampleRate;

       audioCodec->codec_type = AVMEDIA_TYPE_AUDIO;
       if (avcodec_open(audioCodec, codec) &lt; 0)
       {
           printf("avcodec_open: ERROR\n");
           return NULL;
       }

       return audioCodec;
    }


    int main(int argc, char** argv) {
     AVFormatContext *aFormatCtx_decoder = NULL;
     AVFormatContext *aFormatCtx_encoder = NULL;
     int             i, audioStream;
     AVPacket        packet_decoder;
     AVPacket        packet_encoder;
     int             got_frame=0;
     int             complete_decode=0;
     int             len;
     AVFrame         *decoded_frame = NULL;
     AVCodecContext  *aCodec_decoderCtx = NULL;
     AVCodec         *aCodec_decoder = NULL;
     FILE            *outfile;
     //reding input file
     avcodec_register_all();

      //register all codecs
       av_register_all();

    //open file
       if(avformat_open_input(&amp;aFormatCtx_decoder, "sample.aac", NULL, NULL)!=0){
           fprintf(stderr, "Could not open source file \n");
           return -1; // Couldn't open file
       }

     // Retrieve stream information
     if(avformat_find_stream_info(aFormatCtx_decoder, NULL)&lt;0){
         fprintf(stderr, "Couldn't find stream information \n");
         return -1; // Couldn't find stream information
     }

     // Dump information about file onto standard error
     //av_dump_format(aFormatCtx_decode, 0, argv[1], 0);

     // Find the first audio stream
     audioStream=-1;

     for(i=0; inb_streams; i++) {
       if(aFormatCtx_decoder->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO &amp;&amp;
          audioStream &lt; 0) {
         audioStream=i;
       }
     }
     if(audioStream==-1){
         fprintf(stderr, "File haven't sudio stream \n");
         return -1;
     }

     //get audio codec contex
     aCodec_decoderCtx=aFormatCtx_decoder->streams[audioStream]->codec;
     //get audio codec
     aCodec_decoder = avcodec_find_decoder(aCodec_decoderCtx->codec_id);
     aCodec_decoder->sample_fmts=AV_SAMPLE_FMT_S16P;
     if(!aCodec_decoder) {
       fprintf(stderr, "Unsupported codec!\n");
       return -1;//Unsupported codec!
     }
     //open codec
     // Open codec
     if(avcodec_open2(aCodec_decoderCtx, aCodec_decoder, NULL)&lt;0)
       return -1; // Could not open codec
     // allocate audio frame
     decoded_frame = avcodec_alloc_frame();
     if (!decoded_frame) {
       fprintf(stderr, "Could not allocate audio frame\n");
       return -1;//Could not allocate audio frame
       }
     aCodec_decoderCtx->bit_rate=12000;
     aFormatCtx_encoder=get_encoder(8000,1,12000);
     av_init_packet(&amp;packet_encoder);

     printf("param %d %d %d",aCodec_decoderCtx->sample_fmt,aCodec_decoderCtx->channels,aCodec_decoderCtx->bit_rate);

     outfile = fopen("out.aac", "wb");
       if (!outfile) {
           printf(stderr, "Could not open outfile \n");
           return -1;//Could not open outfile
       }
     while(av_read_frame(aFormatCtx_decoder, &amp;packet_decoder)>=0) {
        // decode frame
        len = avcodec_decode_audio4(aCodec_decoderCtx, decoded_frame, &amp;got_frame, &amp;packet_decoder);
           if (len &lt; 0) {
               fprintf(stderr, "Error while decoding\n");
               return -1;
               }

           if (got_frame){
             avcodec_encode_audio2(aFormatCtx_encoder,&amp;packet_encoder,decoded_frame,&amp;complete_decode);
             if(complete_decode){
             //    printf("complete decode frame");
                 fwrite(packet_encoder.data, 1, packet_encoder.size, outfile);
                 av_free_packet(&amp;packet_encoder);
             }
           }



       }
     fclose(outfile);
       return (EXIT_SUCCESS);
    }
  • ffmpeg rtsp on C

    2 juillet 2017, par gogoer

    I need to write RTSP steram from IP-cam to file. I use FFMPEG to do this. I found code example on C++, but i need to use only C. Can anyone help me ?

    i have problems in file operations. how can i write stream to file ?

    #include
    #include
    #include <iostream>
    #include <fstream>
    #include <sstream>

    extern "C" {
    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavformat></libavformat>avformat.h>
    #include <libavformat></libavformat>avio.h>
    #include <libswscale></libswscale>swscale.h>
    }

    int main(int argc, char** argv) {

       // Open the initial context variables that are needed
       SwsContext *img_convert_ctx;
       AVFormatContext* format_ctx = avformat_alloc_context();
       AVCodecContext* codec_ctx = NULL;
       int video_stream_index;

       // Register everything
       av_register_all();
       avformat_network_init();

       //open RTSP
       if (avformat_open_input(&amp;format_ctx, "rtsp://134.169.178.187:8554/h264.3gp",
               NULL, NULL) != 0) {
           return EXIT_FAILURE;
       }

       if (avformat_find_stream_info(format_ctx, NULL) &lt; 0) {
           return EXIT_FAILURE;
       }

       //search video stream
       for (int i = 0; i &lt; format_ctx->nb_streams; i++) {
           if (format_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
               video_stream_index = i;
       }

       AVPacket packet;
       av_init_packet(&amp;packet);

       //open output file
       AVFormatContext* output_ctx = avformat_alloc_context();

       AVStream* stream = NULL;
       int cnt = 0;

       //start reading packets from stream and write them to file
       av_read_play(format_ctx);    //play RTSP

       // Get the codec
       AVCodec *codec = NULL;
       codec = avcodec_find_decoder(AV_CODEC_ID_H264);
       if (!codec) {
           exit(1);
       }

       // Add this to allocate the context by codec
       codec_ctx = avcodec_alloc_context3(codec);

       avcodec_get_context_defaults3(codec_ctx, codec);
       avcodec_copy_context(codec_ctx, format_ctx->streams[video_stream_index]->codec);
       std::ofstream output_file;

       if (avcodec_open2(codec_ctx, codec, NULL) &lt; 0)
           exit(1);

       img_convert_ctx = sws_getContext(codec_ctx->width, codec_ctx->height,
               codec_ctx->pix_fmt, codec_ctx->width, codec_ctx->height, AV_PIX_FMT_RGB24,
               SWS_BICUBIC, NULL, NULL, NULL);

       int size = avpicture_get_size(AV_PIX_FMT_YUV420P, codec_ctx->width,
               codec_ctx->height);
       uint8_t* picture_buffer = (uint8_t*) (av_malloc(size));
       AVFrame* picture = av_frame_alloc();
       AVFrame* picture_rgb = av_frame_alloc();
       int size2 = avpicture_get_size(AV_PIX_FMT_RGB24, codec_ctx->width,
               codec_ctx->height);
       uint8_t* picture_buffer_2 = (uint8_t*) (av_malloc(size2));
       avpicture_fill((AVPicture *) picture, picture_buffer, AV_PIX_FMT_YUV420P,
               codec_ctx->width, codec_ctx->height);
       avpicture_fill((AVPicture *) picture_rgb, picture_buffer_2, AV_PIX_FMT_RGB24,
               codec_ctx->width, codec_ctx->height);

       while (av_read_frame(format_ctx, &amp;packet) >= 0 &amp;&amp; cnt &lt; 1000) { //read ~ 1000 frames

           std::cout &lt;&lt; "1 Frame: " &lt;&lt; cnt &lt;&lt; std::endl;
           if (packet.stream_index == video_stream_index) {    //packet is video
               std::cout &lt;&lt; "2 Is Video" &lt;&lt; std::endl;
               if (stream == NULL) {    //create stream in file
                   std::cout &lt;&lt; "3 create stream" &lt;&lt; std::endl;
                   stream = avformat_new_stream(output_ctx,
                           format_ctx->streams[video_stream_index]->codec->codec);
                   avcodec_copy_context(stream->codec,
                           format_ctx->streams[video_stream_index]->codec);
                   stream->sample_aspect_ratio =
                           format_ctx->streams[video_stream_index]->codec->sample_aspect_ratio;
               }
               int check = 0;
               packet.stream_index = stream->id;
               std::cout &lt;&lt; "4 decoding" &lt;&lt; std::endl;
               int result = avcodec_decode_video2(codec_ctx, picture, &amp;check, &amp;packet);
               std::cout &lt;&lt; "Bytes decoded " &lt;&lt; result &lt;&lt; " check " &lt;&lt; check
                       &lt;&lt; std::endl;
               if (cnt > 100)    //cnt &lt; 0)
                       {
                   sws_scale(img_convert_ctx, picture->data, picture->linesize, 0,
                           codec_ctx->height, picture_rgb->data, picture_rgb->linesize);
                   std::stringstream file_name;
                   file_name &lt;&lt; "test" &lt;&lt; cnt &lt;&lt; ".ppm";
                   output_file.open(file_name.str().c_str());
                   output_file &lt;&lt; "P3 " &lt;&lt; codec_ctx->width &lt;&lt; " " &lt;&lt; codec_ctx->height
                           &lt;&lt; " 255\n";
                   for (int y = 0; y &lt; codec_ctx->height; y++) {
                       for (int x = 0; x &lt; codec_ctx->width * 3; x++)
                           output_file
                                   &lt;&lt; (int) (picture_rgb->data[0]
                                           + y * picture_rgb->linesize[0])[x] &lt;&lt; " ";
                   }
                   output_file.close();
               }
               cnt++;
           }
           av_free_packet(&amp;packet);
           av_init_packet(&amp;packet);
       }
       av_free(picture);
       av_free(picture_rgb);
       av_free(picture_buffer);
       av_free(picture_buffer_2);

       av_read_pause(format_ctx);
       avio_close(output_ctx->pb);
       avformat_free_context(output_ctx);

       return (EXIT_SUCCESS);
    }
    </sstream></fstream></iostream>

    please help me to compile this by C-compiler.