Recherche avancée

Médias (39)

Mot : - Tags -/audio

Autres articles (56)

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

  • Configuration spécifique d’Apache

    4 février 2011, par

    Modules spécifiques
    Pour la configuration d’Apache, il est conseillé d’activer certains modules non spécifiques à MediaSPIP, mais permettant d’améliorer les performances : mod_deflate et mod_headers pour compresser automatiquement via Apache les pages. Cf ce tutoriel ; mode_expires pour gérer correctement l’expiration des hits. Cf ce tutoriel ;
    Il est également conseillé d’ajouter la prise en charge par apache du mime-type pour les fichiers WebM comme indiqué dans ce tutoriel.
    Création d’un (...)

  • HTML5 audio and video support

    13 avril 2011, par

    MediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
    The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
    For older browsers the Flowplayer flash fallback is used.
    MediaSPIP allows for media playback on major mobile platforms with the above (...)

Sur d’autres sites (6859)

  • Encoding video using FFmpeg and FreeImage

    14 mai 2014, par mike

    I have to make a video encoder to encode video using mjpeg codec from many jpgs saved on the disk. I use FreeImage to load images and ffmpeg to encode. Unfortunately, the output video isn’t that what I expect. I can’t play it in MPC. VLC can play it but there is only a single quick flash of the last picture I loaded. I want to have 1 fps video and for example I loaded 4 frames so my video should last 4 seconds.

    Input pictures are in BGR24 pixel format.

    What is more, when I run my code I got swscaler warning that picture format YUVJ420P is deprecated but I cant find another pixel format which is suitable for MJPEG codec.

    Here is my source code :

    AVPixelFormat in_pix_fmt = AV_PIX_FMT_BGR24;
    AVPixelFormat out_pix_fmt = AV_PIX_FMT_YUVJ420P;

    AVCodec *pCodec;
    AVCodecContext *pCodecCtx = NULL;
    int out_size = 0;
    int size, outbuf_size, i, outpic_size, w, h;
    FILE *file;
    const char *videofile_name = "test_video_cpp.avi";
    AVFrame *picture, *outpic;
    uint8_t *outbuf, *picture_buf, *outpic_buf;

    av_register_all();

    pCodec = avcodec_find_encoder(CODEC_ID_MJPEG);
    if (!pCodec)
    {
       cout << "Codec not found\n\n";
       return 1;
    }

    pCodecCtx = avcodec_alloc_context3(pCodec);
    picture = avcodec_alloc_frame();
    outpic = avcodec_alloc_frame();

    pCodecCtx->codec_id = CODEC_ID_MJPEG;
    pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;
    pCodecCtx->pix_fmt = out_pix_fmt;
    pCodecCtx->bit_rate = 400000;
    pCodecCtx->width = 1688;            
    pCodecCtx->height = 728;
    pCodecCtx->time_base.num = 1;          
    pCodecCtx->time_base.den = 1;       //fps
    pCodecCtx->max_b_frames = 0;

    outbuf_size = 500000;
    outbuf = new uint8_t[outbuf_size];

    if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0)     //open codec
    {
       cout << "Could not open codec\n";
       exit(1);
    }

    file = fopen(videofile_name, "wb");                 //open file
    if (!file)
    {
       cout << "Could not open " << videofile_name << endl;
       exit(1);
    }

    outpic_size = avpicture_get_size(out_pix_fmt, pCodecCtx->width, pCodecCtx->height);
    outpic_buf = new uint8_t[outpic_size];
    cout << "Outpic size was setted to: " << outpic_size << endl;

    size = pCodecCtx->width * pCodecCtx->height;
    picture_buf = new uint8_t[size * 3];


    for (i = 1; i < 5; i++)
    {  
       fflush(stdout);

       stringstream ss;
       ss << i;
       filename = name + ss.str() + ext;
       path = dir + filename;

       dib = FreeImage_Load(FIF_JPEG, path.c_str(), 0);

       picture_buf = FreeImage_GetBits(dib);

               h = FreeImage_GetHeight(dib);
       w = FreeImage_GetWidth(dib);

       avpicture_fill((AVPicture*)picture, picture_buf, in_pix_fmt, w, h);
       avpicture_fill((AVPicture*)outpic, outpic_buf, out_pix_fmt, pCodecCtx->width, pCodecCtx->height);

       struct SwsContext* fooContext = sws_getContext(w, h, in_pix_fmt, pCodecCtx->width, pCodecCtx->height, out_pix_fmt, SWS_BICUBIC, NULL, NULL, NULL);

       sws_scale(fooContext, picture->data, picture->linesize, 0, pCodecCtx->height, outpic->data, outpic->linesize);

       //encode single frame
       out_size = avcodec_encode_video(pCodecCtx, outpic_buf, outpic_size, outpic);
       cout << "encoding frame " << i << "(size=" << out_size << ")\n";
       fwrite(outbuf, 1, out_size, file);

    }

    //encode delayed frames
    for ( ; out_size; i++)
    {
       fflush(stdout);
       out_size = avcodec_encode_video(pCodecCtx, outbuf, outbuf_size, NULL);
       cout << "write frame " << i << "(size=" << out_size << ")\n";
       fwrite(outbuf, 1, out_size, file);
    }

    outbuf[0] = 0x00;
    outbuf[1] = 0x00;
    outbuf[2] = 0x01;
    outbuf[3] = 0xb7;
    fwrite(outbuf, 1, 4, file);

    fclose(file);
    delete outbuf;
    avcodec_close(pCodecCtx);
    av_free(pCodecCtx);
    avpicture_free((AVPicture*)picture);
    avpicture_free((AVPicture*)outpic);
    delete picture_buf;
    delete outpic_buf;
  • FFMPEG subtitle : mov_text removal

    27 mars 2014, par user3461178

    I have problems with subtitles. My video playout can not play them. So I have been trying to remove it.

    C:\Users\Jakub\Desktop\eclipse\workspace\tvpohoda_archiv>"c:\\lib/ffmpeg/bin/ffm
    peg.exe" -i "videa/1050028-CITRON_-_Uz_zavrate_ridnou_c.m4v"  -sn -c:a copy -c:v
    copy  "videa/1050028-CITRON_-_Uz_zavrate_ridnou_c2.mov"
    ffmpeg version N-57650-gcb52d6d Copyright (c) 2000-2013 the FFmpeg developers
     built on Oct 30 2013 20:35:46 with gcc 4.8.2 (GCC)
     configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
    isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
    le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
    e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
    ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
    ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
    eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
    cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
    ack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
     libavutil      52. 48.100 / 52. 48.100
     libavcodec     55. 39.100 / 55. 39.100
     libavformat    55. 19.104 / 55. 19.104
     libavdevice    55.  5.100 / 55.  5.100
     libavfilter     3. 90.100 /  3. 90.100
     libswscale      2.  5.101 /  2.  5.101
     libswresample   0. 17.104 /  0. 17.104
     libpostproc    52.  3.100 / 52.  3.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'videa/1050028-CITRON_-_Uz_zavrate_ridno
    u_c.m4v':
     Metadata:
       major_brand     : M4V
       minor_version   : 512
       compatible_brands: isomiso2avc1
       encoder         : Lavf55.19.104
     Duration: 00:04:56.49, start: 0.021333, bitrate: 7239 kb/s
       Chapter #0.0: start 0.000000, end 296.400000
       Metadata:
         title           : Chapter 1
       Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x576 [
    SAR 212:225 DAR 53:45], 6997 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
       Metadata:
         handler_name    : VideoHandler
       Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 24
    0 kb/s (default)
       Metadata:
         handler_name    : SoundHandler
       Stream #0:2(eng): Subtitle: mov_text (text / 0x74786574)
       Metadata:
         handler_name    : SubtitleHandler
    File 'videa/1050028-CITRON_-_Uz_zavrate_ridnou_c2.mov' already exists. Overwrite
    ? [y/N] y
    Output #0, mov, to 'videa/1050028-CITRON_-_Uz_zavrate_ridnou_c2.mov':
     Metadata:
       major_brand     : M4V
       minor_version   : 512
       compatible_brands: isomiso2avc1
       encoder         : Lavf55.19.104
       Chapter #0.0: start 0.021000, end 296.421000
       Metadata:
         title           : Chapter 1
       Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 720x576 [SAR 212
    :225 DAR 53:45], q=2-31, 6997 kb/s, 25 fps, 12800 tbn, 12800 tbc (default)
       Metadata:
         handler_name    : VideoHandler
       Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, 240 kb/s
    (default)
       Metadata:
         handler_name    : SoundHandler
    Stream mapping:
     Stream #0:0 -> #0:0 (copy)
     Stream #0:1 -> #0:1 (copy)
    Press [q] to stop, [?] for help
    frame= 7408 fps=0.0 q=-1.0 Lsize=  262031kB time=00:04:56.49 bitrate=7239.9kbits
    /s
    video:253116kB audio:8700kB subtitle:0 global headers:0kB muxing overhead 0.0820
    40%

    Or :

    C:\Users\Jakub\Desktop\eclipse\workspace\tvpohoda_archiv>"c:\\lib/ffmpeg/bin/ffm
    peg.exe" -i "videa/1050028-CITRON_-_Uz_zavrate_ridnou_c.m4v"  -map 0:0 -map 0:1
    -c:a copy -c:v copy  "videa/1050028-CITRON_-_Uz_zavrate_ridnou_c2.mov"
    ffmpeg version N-57650-gcb52d6d Copyright (c) 2000-2013 the FFmpeg developers
     built on Oct 30 2013 20:35:46 with gcc 4.8.2 (GCC)
     configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
    isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
    le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
    e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
    ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
    ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
    eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
    cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
    ack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
     libavutil      52. 48.100 / 52. 48.100
     libavcodec     55. 39.100 / 55. 39.100
     libavformat    55. 19.104 / 55. 19.104
     libavdevice    55.  5.100 / 55.  5.100
     libavfilter     3. 90.100 /  3. 90.100
     libswscale      2.  5.101 /  2.  5.101
     libswresample   0. 17.104 /  0. 17.104
     libpostproc    52.  3.100 / 52.  3.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'videa/1050028-CITRON_-_Uz_zavrate_ridno
    u_c.m4v':
     Metadata:
       major_brand     : M4V
       minor_version   : 512
       compatible_brands: isomiso2avc1
       encoder         : Lavf55.19.104
     Duration: 00:04:56.49, start: 0.021333, bitrate: 7239 kb/s
       Chapter #0.0: start 0.000000, end 296.400000
       Metadata:
         title           : Chapter 1
       Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x576 [
    SAR 212:225 DAR 53:45], 6997 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
       Metadata:
         handler_name    : VideoHandler
       Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 24
    0 kb/s (default)
       Metadata:
         handler_name    : SoundHandler
       Stream #0:2(eng): Subtitle: mov_text (text / 0x74786574)
       Metadata:
         handler_name    : SubtitleHandler
    Output #0, mov, to 'videa/1050028-CITRON_-_Uz_zavrate_ridnou_c2.mov':
     Metadata:
       major_brand     : M4V
       minor_version   : 512
       compatible_brands: isomiso2avc1
       encoder         : Lavf55.19.104
       Chapter #0.0: start 0.021000, end 296.421000
       Metadata:
         title           : Chapter 1
       Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 720x576 [SAR 212
    :225 DAR 53:45], q=2-31, 6997 kb/s, 25 fps, 12800 tbn, 12800 tbc (default)
       Metadata:
         handler_name    : VideoHandler
       Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, 240 kb/s
    (default)
       Metadata:
         handler_name    : SoundHandler
    Stream mapping:
     Stream #0:0 -> #0:0 (copy)
     Stream #0:1 -> #0:1 (copy)
    Press [q] to stop, [?] for help
    frame= 2702 fps=0.0 q=-1.0 size=   95498kB time=00:01:48.03 bitrate=7241.6kbits/
    frame= 4436 fps=4435 q=-1.0 size=  157319kB time=00:02:57.38 bitrate=7265.2kbits
    frame= 6296 fps=4196 q=-1.0 size=  223194kB time=00:04:11.77 bitrate=7262.0kbits
    frame= 7408 fps=4121 q=-1.0 Lsize=  262031kB time=00:04:56.49 bitrate=7239.9kbit
    s/s
    video:253116kB audio:8700kB subtitle:0 global headers:0kB muxing overhead 0.0820
    40%

    But it did not worked, subtitles have stayed there.

    i am normally starting this ffmpeg from java but this files are from command line

    Please can you help me ?

  • Android h264 decode non-existing PPS 0 referenced

    22 janvier 2014, par nmxprime

    In Android JNI, using ffmpeg with libx264 use below codes to encode and decode raw rgb data !. I should use swscale to convert rgb565 to yuv420p as required by H.264. But not clear about this conversion.Please help, where i am wrong, with regard the log i get !

    Code for Encoding

    codecinit()- called once(JNI wrapper function)

    int Java_com_my_package_codecinit (JNIEnv *env, jobject thiz) {
    avcodec_register_all();
    codec = avcodec_find_encoder(AV_CODEC_ID_H264);//AV_CODEC_ID_MPEG1VIDEO);
    if(codec->id == AV_CODEC_ID_H264)
       __android_log_write(ANDROID_LOG_ERROR, "set","h264_encoder");

    if (!codec) {
       fprintf(stderr, "codec not found\n");
       __android_log_write(ANDROID_LOG_ERROR, "codec", "not found");

    }
       __android_log_write(ANDROID_LOG_ERROR, "codec", "alloc-contest3");
    c= avcodec_alloc_context3(codec);
    if(c == NULL)
       __android_log_write(ANDROID_LOG_ERROR, "avcodec","context-null");

    picture= av_frame_alloc();

    if(picture == NULL)
       __android_log_write(ANDROID_LOG_ERROR, "picture","context-null");

    c->bit_rate = 400000;
    c->height = 800;
    c->time_base= (AVRational){1,25};
    c->gop_size = 10;
    c->max_b_frames=1;
    c->pix_fmt = AV_PIX_FMT_YUV420P;
    outbuf_size = 768000;
    c->width = 480;

    size = (c->width * c->height);

    if (avcodec_open2(c, codec,NULL) < 0) {

    __android_log_write(ANDROID_LOG_ERROR, "codec", "could not open");


    }

    ret = av_image_alloc(picture->data, picture->linesize, c->width, c->height,
                        c->pix_fmt, 32);
    if (ret < 0) {
           __android_log_write(ANDROID_LOG_ERROR, "image","alloc-failed");
       fprintf(stderr, "could not alloc raw picture buffer\n");

    }

    picture->format = c->pix_fmt;
    picture->width  = c->width;
    picture->height = c->height;
    return 0;

    }

    encodeframe()-called in a while loop

    int Java_com_my_package_encodeframe (JNIEnv *env, jobject thiz,jbyteArray buffer) {
    jbyte *temp= (*env)->GetByteArrayElements(env, buffer, 0);
    Output = (char *)temp;
    const uint8_t * const inData[1] = { Output };
    const int inLinesize[1] = { 2*c->width };

    //swscale should implement here

       av_init_packet(&pkt);
       pkt.data = NULL;    // packet data will be allocated by the encoder
       pkt.size = 0;

       fflush(stdout);
    picture->data[0] = Output;
    ret = avcodec_encode_video2(c, &pkt, picture,&got_output);

       fprintf(stderr,"ret = %d, got-out = %d \n",ret,got_output);
        if (ret < 0) {
                   __android_log_write(ANDROID_LOG_ERROR, "error","encoding");
           if(got_output > 0)
           __android_log_write(ANDROID_LOG_ERROR, "got_output","is non-zero");

       }

       if (got_output) {
           fprintf(stderr,"encoding frame %3d (size=%5d): (ret=%d)\n", 1, pkt.size,ret);
           fprintf(stderr,"before caling decode");
           decode_inline(&pkt); //function that decodes right after the encode
           fprintf(stderr,"after caling decode");


           av_free_packet(&pkt);
       }


    fprintf(stderr,"y val: %d \n",y);


    (*env)->ReleaseByteArrayElements(env, buffer, Output, 0);
    return ((ret));
    }

    decode_inline() function

    decode_inline(AVPacket *avpkt){
    AVCodec *codec;
    AVCodecContext *c = NULL;
    int frame, got_picture, len = -1,temp=0;

    AVFrame *rawFrame, *rgbFrame;
    uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
    char buf[1024];
    char rawBuf[768000],rgbBuf[768000];

    struct SwsContext *sws_ctx;

    memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
    avcodec_register_all();

    c= avcodec_alloc_context3(codec);
    if(c == NULL)
       __android_log_write(ANDROID_LOG_ERROR, "avcodec","context-null");

    codec = avcodec_find_decoder(AV_CODEC_ID_H264);
    if (!codec) {
       fprintf(stderr, "codec not found\n");
       fprintf(stderr, "codec = %p \n", codec);
       }
    c->pix_fmt = AV_PIX_FMT_YUV420P;
    c->width = 480;
    c->height = 800;

    rawFrame = av_frame_alloc();
    rgbFrame = av_frame_alloc();

    if (avcodec_open2(c, codec, NULL) < 0) {
       fprintf(stderr, "could not open codec\n");
       exit(1);
       }
    sws_ctx = sws_getContext(c->width, c->height,/*PIX_FMT_RGB565BE*/
               PIX_FMT_YUV420P, c->width, c->height, AV_PIX_FMT_RGB565/*PIX_FMT_YUV420P*/,
               SWS_BILINEAR, NULL, NULL, NULL);


    frame = 0;

    unsigned short *decodedpixels = &rawBuf;
    rawFrame->data[0] = &rawBuf;
    rgbFrame->data[0] = &rgbBuf;

    fprintf(stderr,"size of avpkt %d \n",avpkt->size);
    temp = avpkt->size;
    while (temp > 0) {
           len = avcodec_decode_video2(c, rawFrame, &got_picture, avpkt);

           if (len < 0) {
               fprintf(stderr, "Error while decoding frame %d\n", frame);
               exit(1);
               }
           temp -= len;
           avpkt->data += len;

           if (got_picture) {
               printf("saving frame %3d\n", frame);
               fflush(stdout);
           //TODO  
           //memcpy(decodedpixels,rawFrame->data[0],rawFrame->linesize[0]);
           //  decodedpixels +=rawFrame->linesize[0];

               frame++;
               }

           }

    avcodec_close(c);
    av_free(c);
    //free(rawBuf);
    //free(rgbBuf);
    av_frame_free(&rawFrame);
    av_frame_free(&rgbFrame);

    }

    The log i get

    For the decode_inline() function :


    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] non-existing PPS 0 referenced
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] decode_slice_header error
    01-02 14:50:50.160: I/stderr(3407): [h264 @ 0x8db540] Invalid mix of idr and non-idr slices
    01-02 14:50:50.160: I/stderr(3407): Error while decoding frame 0

    Edit : Changing GOP value :

    If i change c->gop_size = 3; as expected it emits one I frame every three frames. The non-existing PPS 0 referenced message is not there for in every third execution, but all other have this message