Recherche avancée

Médias (1)

Mot : - Tags -/wave

Autres articles (79)

  • Demande de création d’un canal

    12 mars 2010, par

    En fonction de la configuration de la plateforme, l’utilisateur peu avoir à sa disposition deux méthodes différentes de demande de création de canal. La première est au moment de son inscription, la seconde, après son inscription en remplissant un formulaire de demande.
    Les deux manières demandent les mêmes choses fonctionnent à peu près de la même manière, le futur utilisateur doit remplir une série de champ de formulaire permettant tout d’abord aux administrateurs d’avoir des informations quant à (...)

  • Librairies et binaires spécifiques au traitement vidéo et sonore

    31 janvier 2010, par

    Les logiciels et librairies suivantes sont utilisées par SPIPmotion d’une manière ou d’une autre.
    Binaires obligatoires FFMpeg : encodeur principal, permet de transcoder presque tous les types de fichiers vidéo et sonores dans les formats lisibles sur Internet. CF ce tutoriel pour son installation ; Oggz-tools : outils d’inspection de fichiers ogg ; Mediainfo : récupération d’informations depuis la plupart des formats vidéos et sonores ;
    Binaires complémentaires et facultatifs flvtool2 : (...)

  • Support audio et vidéo HTML5

    10 avril 2011

    MediaSPIP utilise les balises HTML5 video et audio pour la lecture de documents multimedia en profitant des dernières innovations du W3C supportées par les navigateurs modernes.
    Pour les navigateurs plus anciens, le lecteur flash Flowplayer est utilisé.
    Le lecteur HTML5 utilisé a été spécifiquement créé pour MediaSPIP : il est complètement modifiable graphiquement pour correspondre à un thème choisi.
    Ces technologies permettent de distribuer vidéo et son à la fois sur des ordinateurs conventionnels (...)

Sur d’autres sites (7842)

  • ffmpeg capture from ip camera video in h264 stream [closed]

    23 mars 2023, par Иванов Иван

    I can't read the frames from the camera and then write them to a video file (any). The fact is that I even get crooked frames, they seem to have violated the coordinates of the position of each point, the video is crooked, distorted

    


    c++ code.

    


    https://drive.google.com/file/d/1W2sZMR5D5pvVmnhiQyhiaQhC9frhdeII/view?usp=sharing

    


     #define INBUF_SIZE 4096&#xA;&#xA;&#xA;    //writing the minimal required header for a pgm file format&#xA;    //portable graymap format-> https://en.wikipedia.org/wiki/Netpbm_format#PGM_example&#xA;    fprintf (f, "P5\n%d %d\n%d\n", xsize, ysize, 255);&#xA;&#xA;    //writing line by line&#xA;    for (i = 0; i /contains data on a configuration of media content, such as bitrate, &#xA;        //frame rate, sampling frequency, channels, height and many other things.&#xA;        AVCodecContext * AVCodecContext_ = NULL;&#xA;        AVCodecParameters * AVCodecParametr_ = NULL;&#xA;        FILE * f;&#xA;        //This structure describes decoded (raw) audio- or video this.&#xA;        AVFrame * frame;&#xA;        uint8_t inbuf [INBUF_SIZE &#x2B; AV_INPUT_BUFFER_PADDING_SIZE];&#xA;        uint8_t * data;&#xA;        size_t data_size;&#xA;        int ret;&#xA;        int eof;&#xA;        AVFormatContext * AVfc = NULL;&#xA;        int ERRORS;&#xA;        //AVCodec * codec;&#xA;        char buf [1024];&#xA;        const char * FileName;&#xA;    &#xA;        //https://habr.com/ru/post/137793/&#xA;        //Stores the compressed one shot.&#xA;        AVPacket * pkt;&#xA;    &#xA;        //**********************************************************************&#xA;        //Beginning of reading video from the camera. &#xA;        //**********************************************************************&#xA;    &#xA;        avdevice_register_all ();&#xA;    &#xA;        filename = "rtsp://admin: 754HG@192.168.1.75:554/11";&#xA;        //filename = "c:\\1.avi";&#xA;        outfilename = "C:\\2.MP4";&#xA;    &#xA;        //We open a flow of video (it is the file or the camera). &#xA;        ERRORS = avformat_open_input (&amp; AVfc, filename, NULL, NULL);&#xA;        if (ERRORS &lt;0) {&#xA;            fprintf (stderr, "ffmpeg: could not open file \n");&#xA;            return-1;&#xA;        }&#xA;    &#xA;        //After opening, we can print out information on the video file (iformat = the name of a format; &#xA;        //duration = duration). But as I connected the camera to me wrote: Duration: N/A, &#xA;        //start: 0.000000, bitrate: N/A&#xA;        printf ("Format %s, duration %lld us", AVfc-> iformat-> long_name, AVfc-> duration);&#xA;    &#xA;    &#xA;        ERRORS = avformat_find_stream_info (AVfc, NULL);&#xA;        if (ERRORS &lt;0) {&#xA;            fprintf (stderr, "ffmpeg: Unable to find stream info\n");&#xA;            return-1;&#xA;        }&#xA;    &#xA;    &#xA;        int CountStream;&#xA;    &#xA;        //We learn quantity of streams. &#xA;        CountStream = AVfc-> nb_streams;&#xA;    &#xA;        //Let&#x27;s look for the codec. &#xA;        int video_stream;&#xA;        for (video_stream = 0; video_stream  nb_streams; &#x2B;&#x2B; video_stream) {&#xA;            if (AVfc-> streams[video_stream]-> codecpar-> codec_type == AVMEDIA_TYPE_VIDEO) {&#xA;                break;&#xA;            }&#xA;    &#xA;        }&#xA;    &#xA;        if (video_stream == AVfc-> nb_streams) {&#xA;            fprintf (stderr, "ffmpeg: Unable to find video stream\n");&#xA;            return-1;&#xA;        }&#xA;    &#xA;        //Here we define a type of the codec, for my camera it is equal as AV_CODEC_ID_HEVC (This that in what is broadcast by my camera)&#xA;        codec = avcodec_find_decoder(AVfc-> streams [video_stream]-> codecpar-> codec_id);&#xA;        //--------------------------------------------------------------------------------------&#xA;    &#xA;        //Functions for inquiry of opportunities of libavcodec,&#xA;        AVCodecContext_ = avcodec_alloc_context3(codec);&#xA;        if (! AVCodecContext _) {&#xA;            fprintf (stderr, "Was not succeeded to allocate a video codec context, since it not poddrerzhivayetsya\n");&#xA;            exit(1);&#xA;        }&#xA;    &#xA;        //This function is used for initialization &#xA;        //AVCodecContext of video and audio of the codec. The announcement of avcodec_open2 () is in libavcodecavcodec.h&#xA;        //We open the codec. &#xA;    &#xA;        ERRORS = avcodec_open2 (AVCodecContext _, codec, NULL);&#xA;        if (ERRORS &lt;0) {&#xA;            fprintf (stderr, "ffmpeg: It is not possible to open codec \n");&#xA;            return-1;&#xA;        }&#xA;    &#xA;        //It for processing of a sound - a reserve.&#xA;        //swr_alloc_set_opts ()&#xA;        //swr_init (); &#xA;    &#xA;        //To output all information on the video file. &#xA;        av_dump_format (AVfc, 0, argv[1], 0);&#xA;    &#xA;        //=========================================================================================&#xA;        //Further, we receive frames. before we only received all infomration about the entering video.&#xA;        //=========================================================================================&#xA;    &#xA;        //Now we are going to read packages from a stream and to decode them in shots, but at first &#xA;        //we need to mark out memory for both components (AVPacket and AVFrame).&#xA;        frame = av_frame_alloc ();&#xA;    &#xA;        if (! frame) {&#xA;            fprintf (stderr, "Is not possible to mark out memory for video footage \n");&#xA;            exit(1);&#xA;        }&#xA;        //We mark out memory for a package &#xA;        pkt = av_packet_alloc ();&#xA;        //We define a file name for saving the picture.&#xA;        const char * FileName1 = "C:\\Users\\Павел\\Desktop\\NyFile.PGM";&#xA;        //Data reading if they is. &#xA;        while (av_read_frame (AVfc, pkt)> = 0) {&#xA;            //It is a package from a video stream? Because there is still a soundtrack.&#xA;            if (pkt-> stream_index == video_stream) {&#xA;                int ret;&#xA;    &#xA;                //Transfer of the raw package data as input data in the decoder&#xA;                ret = avcodec_send_packet (AVCodecContext _, pkt);&#xA;                if (ret &lt;0 | | ret == AVERROR(EAGAIN) | | ret == AVERROR_EOF) {&#xA;                    std:: cout &lt;&lt;"avcodec_send_packet:" &lt;<ret while="while"> = 0) {&#xA;    &#xA;                    //Returns the decoded output data from the decoder or the encoder&#xA;                    ret = avcodec_receive_frame (AVCodecContext _, frame);&#xA;                    if (ret == AVERROR(EAGAIN) | | ret == AVERROR_EOF) {&#xA;                        //std:: cout &lt;&lt;"avcodec_receive_frame:" &lt;<ret cout="cout"> of frame_number &lt;/============================================================================================&#xA;    &#xA;                    //Experimentally - we will keep a shot in the picture. &#xA;    &#xA;                    save_gray_frame(frame-> data [0], frame-> linesize [0], frame-> width, frame-> height, (char *) FileName1);&#xA;                }&#xA;            }&#xA;        }&#xA;    &#xA;        //av_parser_close(parser);&#xA;        avcodec_free_context (&amp; AVCodecContext _);&#xA;        av_frame_free (&amp; frame);&#xA;        av_packet_free (&amp; pkt);&#xA;    &#xA;        return 0;&#xA;</ret></ret>

    &#xA;

  • 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.

  • ffmpeg API muxing h264 endoced frames to mkv

    24 mars 2017, par Pawel K

    Hi I’m having some problems with muxing h264 encoded frames into mkv container using code of ffmpeg-3.2.4.
    I have ended up with the following code that is a mashup of code found on SO and muxing.c example of ffmpeg :
    (and yes I am aware that it is ugly, no errors checked etc. it is meant to be like that for clarity :) )

    char *filename = "out.mkv";
    const uint8_t SPS[] = { 0x67, 0x42, 0x40, 0x1F, 0x96, 0x54, 0x02, 0x80, 0x2D, 0xD0, 0x0F, 0x39, 0xEA };
    const uint8_t PPS[] = { 0x68, 0xCE, 0x38, 0x80 };
    int fps = 5;

    typedef struct OutputStream
    {
      AVStream *st;
      AVCodecContext *enc;

      /* pts of the next frame that will be generated */
      int64_t next_pts;
      int samples_count;
      AVFrame *frame;
      AVFrame *tmp_frame;
      float t, tincr, tincr2;
      struct SwsContext *sws_ctx;
      struct SwrContext *swr_ctx;
    } OutputStream;

    static void avlog_cb(void *s, int level, const char *szFmt, va_list varg)
    {
      vprintf(szFmt, varg);
    }

    void main()
    {
      AVOutputFormat *fmt;
      AVFormatContext *formatCtx;
      AVCodec *audio_codec;
      AVCodec *video_codec;
      OutputStream video_st = { 0 };
      OutputStream audio_st = { 0 };
      av_register_all();

      av_log_set_level(AV_LOG_TRACE);
      //av_log_set_callback(avlog_cb);

      //allocate output and format ctxs
      avformat_alloc_output_context2(&amp;formatCtx, NULL, NULL, filename);
      fmt = formatCtx->oformat;

      //allocate streams
      video_codec = avcodec_find_encoder(fmt->video_codec);
      video_st.st = avformat_new_stream(formatCtx, NULL);
      video_st.st->id = 0;

      AVCodecContext *codecCtx =  avcodec_alloc_context3(video_codec);
      fmt->video_codec = AV_CODEC_ID_H264;
      video_st.enc = codecCtx;

      codecCtx->codec_id = fmt->video_codec;
      codecCtx->bit_rate = 400000;
      codecCtx->width  = 1080;
      codecCtx->height = 720;
      codecCtx->profile = FF_PROFILE_H264_CONSTRAINED_BASELINE;
      codecCtx->level = 31;

      video_st.st->time_base = (AVRational){ 1, fps };
      codecCtx->time_base = video_st.st->time_base;
      codecCtx->gop_size = 4;
      codecCtx->pix_fmt = AV_PIX_FMT_YUV420P;

      //open video codec
      codecCtx->extradata_size = 24;
      codecCtx->extradata = (uint8_t *)av_malloc(codecCtx->extradata_size);
      uint8_t extra_data_array[] = { 0x01, SPS[1], SPS[2], SPS[3], 0xFF, 0xE1, 0xc0, 0, 0x42, 0x40, 0x1F, 0x96, 0x54, 0x02, 0x80, 0x2D, 0xD0, 0x0F, 0x39, 0xEA, 0x03, 0xCE, 0x38, 0x80 };
      memcpy(codecCtx->extradata, extra_data_array, codecCtx->extradata_size);

      AVCodecContext *c = video_st.enc;
      AVDictionary *opt = NULL;
      avcodec_open2(c, video_codec, &amp;opt);
      avcodec_parameters_from_context(video_st.st->codecpar, c);

      //open output file
      avio_open(&amp;formatCtx->pb, filename, AVIO_FLAG_WRITE);

      //write header
      int res = avformat_write_header(formatCtx, NULL);

      //write frames

      // get the frames from file
      uint32_t u32frameCnt = 0;

      do
      {
         int8_t i8frame_name[64] = "";

         uint8_t  *pu8framePtr = NULL;
         AVPacket pkt = { 0 };

         av_init_packet(&amp;pkt);
         sprintf(i8frame_name, "frames/frame%d.bin", u32frameCnt++);
         //reading frames from files
         FILE *ph264Frame = fopen(i8frame_name, "r");
         if(NULL == ph264Frame)
         {
            goto leave;
         }

         //get file size
         fseek(ph264Frame, 0L, SEEK_END);
         uint32_t u32file_size = 0;
         u32file_size = ftell(ph264Frame);
         fseek(ph264Frame, 0L, SEEK_SET);

         pu8framePtr = malloc(u32file_size);
         uint32_t u32readout = fread(pu8framePtr, 1, u32file_size, ph264Frame);

         //if the read frame is a key frame i.e. nalu hdr type = 5 set it as a key frame
         if(0x65 == pu8framePtr[4])
         {
            pkt.flags = AV_PKT_FLAG_KEY;
         }
         pkt.data = (uint8_t *)pu8framePtr;
         pkt.size = u32readout;
         pkt.pts  = u32frameCnt;
         pkt.dts  = pkt.pts;

         av_packet_rescale_ts(&amp;pkt, c->time_base, video_st.st->time_base);
         pkt.stream_index = video_st.st->index;
         av_interleaved_write_frame(formatCtx, &amp;pkt);
         free(pu8framePtr);
         fclose(ph264Frame);
      }
      while(1);
    leave:

      av_write_trailer(formatCtx);
      av_dump_format(formatCtx, 0, filename, 1);
      avcodec_free_context(&amp;video_st.enc);
      avio_closep(&amp;formatCtx->pb);
      avformat_free_context(formatCtx);
    }

    It can be compiled with the following command line (after adding headers) :

    gcc file.c -o test_app -I/usr/local/include -L/usr/local/lib -lxcb-shm -lxcb -lX11 -lx264 -lm -lz -pthread -lswresample -lswscale -lavcodec -lavformat -lavdevice -lavutil

    The files that are read are valid annexB stream (valid as in it’s playable in vlc after concatenating into file) it is a Constrained Baseline 3.1 profile H264 and it comes from an IPcam’s interleaved RTCP/RTP stream (demuxed)

    The result is ... well I don’t see the picture. I get only black screen with the progress bar and timer running. I don’t know if I do something wrong with setting up the codecs and streams, or it’s just wrong timestamps.
    I know I got them wrong in some manner but I don’t understand that fully yet (how to calculate the correct presentation times), i.e. the stream and the codec both contain time_base field, and then I know that the sample rate of the video is 90kHz and the frame rate is 5 fps

    On top of it all the examples I’ve found have to some extend deprecated parts that change the flow/meaning of the application and that doesn’t help at all so thus If anyone could help I would appreciate it (I think not only me I would guess)

    Regards, Pawel