Recherche avancée

Médias (1)

Mot : - Tags -/MediaSPIP

Autres articles (15)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • Creating farms of unique websites

    13 avril 2011, par

    MediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
    This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)

  • Other interesting software

    13 avril 2011, par

    We don’t claim to be the only ones doing what we do ... and especially not to assert claims to be the best either ... What we do, we just try to do it well and getting better ...
    The following list represents softwares that tend to be more or less as MediaSPIP or that MediaSPIP tries more or less to do the same, whatever ...
    We don’t know them, we didn’t try them, but you can take a peek.
    Videopress
    Website : http://videopress.com/
    License : GNU/GPL v2
    Source code : (...)

Sur d’autres sites (2759)

  • Undefined reference to 'av_register_all' [duplicate]

    4 avril 2018, par Hask

    When I try to compile my cpp file in which the header files from ffmpeg are connected :

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

     int main(int argc, char* argv[])
     {
         if(argc < 2)
         {
             printf("Usage: %s filename\n", argv[0]);
         }
         av_register_all();
         return 0;
     }

    When compiling with a simple command I get :

     D:\gcc\bin>g++ -o a a.cpp
     C:\users\root\Temp\ccC9UvT7.o:a.cpp:(.text+0x2a): undefined reference to 'av_register_all'
     collect2.exe: error: ld returned 1 exit status

    Using a more complex I get :

     D:\gcc\bin>g++ -o a a.cpp -lavutil -lavformat -lavcodec -lz
     d:/gcc/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot -lavutil
     d:/gcc/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot -lavformat
     d:/gcc/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot -lavcodec
     d:/gcc/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot -lz
     collect2.exe: error: ld returned 1 exit status

    How can I fix this ?

  • C++ FFmpeg create mp4 file

    1er février 2021, par DDovzhenko

    I'm trying to create mp4 video file with FFmpeg and C++, but in result I receive broken file (windows player shows "Can't play ... 0xc00d36c4"). If I create .h264 file, it can be played with 'ffplay' and successfully converted to mp4 via CL.

    



    My code :

    



    int main() {
    char *filename = "tmp.mp4";
    AVOutputFormat *fmt;
    AVFormatContext *fctx;
    AVCodecContext *cctx;
    AVStream *st;

    av_register_all();
    avcodec_register_all();

    //auto detect the output format from the name
    fmt = av_guess_format(NULL, filename, NULL);
    if (!fmt) {
        cout << "Error av_guess_format()" << endl; system("pause"); exit(1);
    }

    if (avformat_alloc_output_context2(&fctx, fmt, NULL, filename) < 0) {
        cout << "Error avformat_alloc_output_context2()" << endl; system("pause"); exit(1);
    }


    //stream creation + parameters
    st = avformat_new_stream(fctx, 0);
    if (!st) {
        cout << "Error avformat_new_stream()" << endl; system("pause"); exit(1);
    }

    st->codecpar->codec_id = fmt->video_codec;
    st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
    st->codecpar->width = 352;
    st->codecpar->height = 288;
    st->time_base.num = 1;
    st->time_base.den = 25;

    AVCodec *pCodec = avcodec_find_encoder(st->codecpar->codec_id);
    if (!pCodec) {
        cout << "Error avcodec_find_encoder()" << endl; system("pause"); exit(1);
    }

    cctx = avcodec_alloc_context3(pCodec);
    if (!cctx) {
        cout << "Error avcodec_alloc_context3()" << endl; system("pause"); exit(1);
    }

    avcodec_parameters_to_context(cctx, st->codecpar);
    cctx->bit_rate = 400000;
    cctx->width = 352;
    cctx->height = 288;
    cctx->time_base.num = 1;
    cctx->time_base.den = 25;
    cctx->gop_size = 12;
    cctx->pix_fmt = AV_PIX_FMT_YUV420P;
    if (st->codecpar->codec_id == AV_CODEC_ID_H264) {
        av_opt_set(cctx->priv_data, "preset", "ultrafast", 0);
    }
    if (fctx->oformat->flags & AVFMT_GLOBALHEADER) {
        cctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
    }
    avcodec_parameters_from_context(st->codecpar, cctx);

    av_dump_format(fctx, 0, filename, 1);

    //OPEN FILE + WRITE HEADER
    if (avcodec_open2(cctx, pCodec, NULL) < 0) {
        cout << "Error avcodec_open2()" << endl; system("pause"); exit(1);
    }
    if (!(fmt->flags & AVFMT_NOFILE)) {
        if (avio_open(&fctx->pb, filename, AVIO_FLAG_WRITE) < 0) {
            cout << "Error avio_open()" << endl; system("pause"); exit(1);
        }
    }
    if (avformat_write_header(fctx, NULL) < 0) {
        cout << "Error avformat_write_header()" << endl; system("pause"); exit(1);
    }


    //CREATE DUMMY VIDEO
    AVFrame *frame = av_frame_alloc();
    frame->format = cctx->pix_fmt;
    frame->width = cctx->width;
    frame->height = cctx->height;
    av_image_alloc(frame->data, frame->linesize, cctx->width, cctx->height, cctx->pix_fmt, 32);

    AVPacket pkt;
    double video_pts = 0;
    for (int i = 0; i < 50; i++) {
        video_pts = (double)cctx->time_base.num / cctx->time_base.den * 90 * i;

        for (int y = 0; y < cctx->height; y++) {
            for (int x = 0; x < cctx->width; x++) {
                frame->data[0][y * frame->linesize[0] + x] = x + y + i * 3;
                if (y < cctx->height / 2 && x < cctx->width / 2) {
                    /* Cb and Cr */
                    frame->data[1][y * frame->linesize[1] + x] = 128 + y + i * 2;
                    frame->data[2][y * frame->linesize[2] + x] = 64 + x + i * 5;
                }
            }
        }

        av_init_packet(&pkt);
        pkt.flags |= AV_PKT_FLAG_KEY;
        pkt.pts = frame->pts = video_pts;
        pkt.data = NULL;
        pkt.size = 0;
        pkt.stream_index = st->index;

        if (avcodec_send_frame(cctx, frame) < 0) {
            cout << "Error avcodec_send_frame()" << endl; system("pause"); exit(1);
        }
        if (avcodec_receive_packet(cctx, &pkt) == 0) {
            //cout << "Write frame " << to_string((int) pkt.pts) << endl;
            av_interleaved_write_frame(fctx, &pkt);
            av_packet_unref(&pkt);
        }
    }

    //DELAYED FRAMES
    for (;;) {
        avcodec_send_frame(cctx, NULL);
        if (avcodec_receive_packet(cctx, &pkt) == 0) {
            //cout << "-Write frame " << to_string((int)pkt.pts) << endl;
            av_interleaved_write_frame(fctx, &pkt);
            av_packet_unref(&pkt);
        }
        else {
            break;
        }
    }

    //FINISH
    av_write_trailer(fctx);
    if (!(fmt->flags & AVFMT_NOFILE)) {
        if (avio_close(fctx->pb) < 0) {
            cout << "Error avio_close()" << endl; system("pause"); exit(1);
        }
    }
    av_frame_free(&frame);
    avcodec_free_context(&cctx);
    avformat_free_context(fctx);

    system("pause");
    return 0;
}


    



    Output of program :

    



    Output #0, mp4, to 'tmp.mp4':
    Stream #0:0: Video: h264, yuv420p, 352x288, q=2-31, 400 kb/s, 25 tbn
[libx264 @ 0000021c4a995ba0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0000021c4a995ba0] profile Constrained Baseline, level 2.0
[libx264 @ 0000021c4a995ba0] 264 - core 152 r2851 ba24899 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=12 keyint_min=1 scenecut=0 intra_refresh=0 rc=abr mbtree=0 bitrate=400 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
[libx264 @ 0000021c4a995ba0] frame I:5     Avg QP: 7.03  size:  9318
[libx264 @ 0000021c4a995ba0] frame P:45    Avg QP: 4.53  size:  4258
[libx264 @ 0000021c4a995ba0] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 0000021c4a995ba0] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4: 100.0%  0.0%  0.0%  0.0%  0.0%    skip: 0.0%
[libx264 @ 0000021c4a995ba0] final ratefactor: 9.11
[libx264 @ 0000021c4a995ba0] coded y,uvDC,uvAC intra: 18.9% 21.8% 14.5% inter: 7.8% 100.0% 15.5%
[libx264 @ 0000021c4a995ba0] i16 v,h,dc,p:  4%  5%  5% 86%
[libx264 @ 0000021c4a995ba0] i8c dc,h,v,p:  2%  9%  6% 82%
[libx264 @ 0000021c4a995ba0] kb/s:264.68


    



    If I will try to play mp4 file with 'ffplay' it prints :

    



    [mov,mp4,m4a,3gp,3g2,mj2 @ 00000000026bf900] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 352x288, 138953 kb/s): unspecified pixel format
[h264 @ 00000000006c6ae0] non-existing PPS 0 referenced
[h264 @ 00000000006c6ae0] decode_slice_header error
[h264 @ 00000000006c6ae0] no frame!


    



    I've spent a lot of time without success of finding issue, what could be the reason of it ?

    



    Thank for help !

    


  • libavcodec/ffmpeg reports two channels when decoding, but segfaults when trying to access the second

    1er décembre 2017, par Astrognome

    I am attempting to decode an audio file into raw pcm data using FFMpeg’s libavcodec. I have the following code so far, but it segfaults when trying to access the second audio channel for some reason.

    #include
    #include
    #include <ao></ao>ao.h>
    #include

    #include <libavutil></libavutil>opt.h>
    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavformat></libavformat>avformat.h>
    #include <libswresample></libswresample>swresample.h>

    #define BUF_SIZE 4096


    #define AUDIO_INBUF_SIZE 20480
    #define AUDIO_REFILL_THRESH 4096

    int decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, uint8_t* out_data, int* index) {

       int i, ch;
       int ret, data_size;

       ret = avcodec_send_packet(dec_ctx, pkt);
       if (ret &lt; 0) {
           fprintf(stderr, "Error submitting packet to decoder\n");
           exit(1);
       }

       while (ret >= 0) {
           ret = avcodec_receive_frame(dec_ctx, frame);
           if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
               return 0;
           }
           else if (ret &lt; 0) {
               fprintf(stderr, "Error during decoding\n");
               exit(1);
           }

           data_size = av_get_bytes_per_sample(dec_ctx->sample_fmt);
           if (data_size &lt; 0) {
               fprintf(stderr, "Failed to calculate data size\n");
               exit(1);
           }
           for (i = 0; i &lt; frame->nb_samples; ++i)
               for (ch = 0; ch &lt; dec_ctx->channels; ++ch) {

                   //Things go wrong here...
                   memcpy(out_data + *index, frame->data[ch] + (data_size*i), data_size);
                   *index += data_size;
               }
       }

       return 0;
    }

    int decode_audio_file(const char* path, uint8_t* out_data, int size) {
       const AVCodec *codec;
       AVCodecContext *c = NULL;
       AVCodecParserContext *parser = NULL;
       int len, ret;
       FILE *f;
       uint8_t inbuf[AUDIO_INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
       uint8_t *data;
       size_t data_size;
       AVPacket *pkt;
       AVFrame *decoded_frame = NULL;


       avcodec_register_all();
       pkt = av_packet_alloc();
       codec = avcodec_find_decoder(AV_CODEC_ID_FLAC);
       if (!codec) {
           fprintf(stderr, "Codec not found!\n");
           return -1;
       }

       parser = av_parser_init(codec->id);
       if (!parser) {
           fprintf(stderr, "Parser not found!\n");
           return -1;
       }

       c = avcodec_alloc_context3(codec);
       if (!c) {
           fprintf(stderr, "Could not allocate audio context!\n");
           return -1;
       }

       if(avcodec_open2(c, codec, NULL) &lt; 0) {
           fprintf(stderr, "Could not open codec\n");
           exit(1);
       }

       f = fopen(path, "rb");
       if(!f) {
           fprintf(stderr, "Could not open %s\n", path);
           exit(1);
       }

       data = inbuf;
       data_size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);

       int index = 0;  
       while (data_size > 0) {
           if (!decoded_frame) {
               if (!(decoded_frame = av_frame_alloc())) {
                   fprintf(stderr, "Could not allocate audio frame\n");
                   exit(1);
               }
           }

           ret = av_parser_parse2(parser, c, &amp;pkt->data, &amp;pkt->size, data, data_size, AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0);
           if (ret &lt; 0) {
               fprintf(stderr, "Error while parsing\n");
               exit(1);
           }
           data += ret;
           data_size -= ret;

           if (pkt->size)
               decode(c, pkt, decoded_frame, out_data, &amp;index);
           if (data_size &lt; AUDIO_REFILL_THRESH) {
               memmove(inbuf, data, data_size);
               data = inbuf;
               len = fread(data + data_size, 1, AUDIO_INBUF_SIZE - data_size, f);
               if (len > 0)
                   data_size += len;
           }
       }
       avcodec_free_context(&amp;c);
       av_parser_close(parser);
       av_frame_free(&amp;decoded_frame);
       av_packet_free(&amp;pkt);

       return 0;
    }


    int main(int argc, char **argv)
    {
       int bsize = 1024*1024*60;
       uint8_t* audio_buffer = calloc(bsize, sizeof(uint8_t));
       decode_audio_file("testsong.flac", audio_buffer, bsize);
    }

    Here is the offending line :

    memcpy(out_data + *index, frame->data[ch] + (data_size*i), data_size);

    If you access frame->data[0] it’s fine, but if you attempt to access frame->data[1] it segfaults. The context reports two channels and the file contains two channels (tried with several different tracks).
    But it gets even weirder. If I switch the offending line to

    memcpy(out_data + *index, frame->data[0] + (data_size*i*2 + ch), data_size);

    it will have the left channel with correct data and the right channel is white noise. This tells me (and I could be wrong) that the first channel actually contains 2 channels of audio interleaved, the actual left channel, plus a junk channel of white noise.
    I was wrong, I forgot to multiple ch by data_size. If the line is memcpy(out_data + *index, frame->data[0] + (data_size*i*2 + ch*data_size), data_size); things seem to work as expected. This all still seems very sketchy though so if anyone can thoroughly explain what’s happening here, that would be nice.

    I have been working off the decode_audio example available in the ffmpeg documentation here although modified slightly.

    This ALSO happens if I use the vanilla example with the only change being setting the codec to FLAC, so I assume it’s a bug in the library. In that case, how can I work around it.