Recherche avancée

Médias (1)

Mot : - Tags -/biographie

Autres articles (81)

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

  • Multilang : améliorer l’interface pour les blocs multilingues

    18 février 2011, par

    Multilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
    Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela.

Sur d’autres sites (10235)

  • Ffmpeg decoder yuv420p

    4 décembre 2015, par user2466514

    I work on a video player yuv420p with ffmpeg but it’s not working and i can’t find out why. I spend the whole week on it...

    So i have a test which just decode some frame and read it, but the output always differ, and it’s really weird.

    I use a video (mp4 yuv420p) which color one black pixel in more each frame :

    For the video, put http://sendvid.com/b1sgf8r1 on a website like http://www.telechargerunevideo.com/en/

    VideoContext is just a little struct :

    struct  VideoContext {

    unsigned int      currentFrame;
    std::size_t       size;
    int               width;
    int               height;
    bool              pause;
    AVFormatContext*  formatCtx;
    AVCodecContext*   codecCtxOrig;
    AVCodecContext*   codecCtx;
    int               streamIndex;
    };

    So i have a function to count the number of black pixels :

    std::size_t  checkFrameNb(const AVFrame* frame) {

       std::size_t  nb = 0;

       for (int y = 0; y < frame->height; ++y) {
         for (int x = 0 ; x < frame->width; ++x) {

           if (frame->data[0][(y * frame->linesize[0]) + x] == BLACK_FRAME.y
               && frame->data[1][(y / 2 * frame->linesize[1]) + x / 2] == BLACK_FRAME.u
               && frame->data[2][(y / 2 * frame->linesize[2]) + x / 2] == BLACK_FRAME.v)
             ++nb;
         }
       }
       return nb;
     }

    And this is how i decode one frame :

    const AVFrame*  VideoDecoder::nextFrame(entities::VideoContext& context) {

     int frameFinished;
     AVPacket packet;

     // Allocate video frame
     AVFrame*  frame = av_frame_alloc();
     if(frame == nullptr)
       throw;

     // Initialize frame->linesize
     avpicture_fill((AVPicture*)frame, nullptr, AV_PIX_FMT_YUV420P, context.width, context.height);

     while(av_read_frame(context.formatCtx, &packet) >= 0) {

       // Is this a packet from the video stream?
       if(packet.stream_index == context.streamIndex) {
         // Decode video frame
         avcodec_decode_video2(context.codecCtx, frame, &frameFinished, &packet);

         // Did we get a video frame?
         if(frameFinished) {

           // Free the packet that was allocated by av_read_frame
           av_free_packet(&packet);
           ++context.currentFrame;
           return frame;
         }
       }
     }

     // Free the packet that was allocated by av_read_frame
     av_free_packet(&packet);
     throw core::GlobalException("nextFrame", "Frame decode failed");
    }

    There is already something wrong ?

    Maybe the context initialization will be useful :

    entities::VideoContext  VideoLoader::loadVideoContext(const char* file,
                                                         const int width,
                                                         const int height) {

     entities::VideoContext  context;

     // Register all formats and codecs
     av_register_all();

     context.formatCtx = avformat_alloc_context();


     // Open video file
     if(avformat_open_input(&context.formatCtx, file, nullptr, 0) != 0)
       throw; // Couldn't open file

     // Retrieve stream information
     if(avformat_find_stream_info(context.formatCtx, nullptr) > 0)
       throw; // Couldn't find stream information

     // Dump information about file onto standard error
     //av_dump_format(m_formatCtx, 0, file, 1);


     // Find the first video stream because we don't need more
     for(unsigned int i = 0; i < context.formatCtx->nb_streams; ++i)
       if(context.formatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
         context.streamIndex = i;
         context.codecCtx = context.formatCtx->streams[i]->codec;
         break;
       }
     if(context.codecCtx == nullptr)
       throw; // Didn't find a video stream


     // Find the decoder for the video stream
     AVCodec*  codec = avcodec_find_decoder(context.codecCtx->codec_id);
     if(codec == nullptr)
       throw; // Codec not found
     // Copy context
     if ((context.codecCtxOrig = avcodec_alloc_context3(codec)) == nullptr)
       throw;
     if(avcodec_copy_context(context.codecCtxOrig, context.codecCtx) != 0)
       throw; // Error copying codec context
     // Open codec
     if(avcodec_open2(context.codecCtx, codec, nullptr) < 0)
       throw; // Could not open codec

     context.currentFrame = 0;
     decoder::VideoDecoder::setVideoSize(context);
     context.pause = false;
     context.width = width;
     context.height = height;

     return std::move(context);
    }

    I know it’s not a little piece of code, if you have any idea too make an exemple more brief, go on.

    And if someone have an idea about this issue, there is my output :

    9 - 10 - 12 - 4 - 10 - 14 - 11 - 8 - 9 - 10

    But i want :

    1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10

    PS :
    get fps and video size are copy paste code of opencv

  • Merging audio(aac) and video (h.264 in mp4 container) into a mp4 container using Xuggler

    26 août 2016, par Handroid

    Here is the code I am using

       String filenamevideo = videoFilePath;(video.mp4)

       String filenameaudio = audioAACFilePath; (audio.aac)



       IMediaWriter mWriter = ToolFactory.makeWriter(videoWithAudioFilePath); // output
       // file

       IContainer containerVideo = IContainer.make();
       IContainer containerAudio = IContainer.make();

       if (containerVideo.open(filenamevideo, IContainer.Type.READ, null) < 0)
           throw new IllegalArgumentException("Cant find " + filenamevideo);

       if (containerAudio.open(filenameaudio, IContainer.Type.READ, null) < 0)
           throw new IllegalArgumentException("Cant find " + filenameaudio);

       int numStreamVideo = containerVideo.getNumStreams();
       int numStreamAudio = containerAudio.getNumStreams();    

       int videostreamt = -1; // this is the video stream id
       int audiostreamt = -1;

       IStreamCoder videocoder = null;

       for (int i = 0; i < numStreamVideo; i++) {
           IStream stream = containerVideo.getStream(i);
           IStreamCoder code = stream.getStreamCoder();

           if (code.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
               videostreamt = i;
               videocoder = code;
               break;
           }

       }

       for (int i = 0; i < numStreamAudio; i++) {
           IStream stream = containerAudio.getStream(i);
           IStreamCoder code = stream.getStreamCoder();

           if (code.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) {
               audiostreamt = i;
               break;
           }

       }

       if (videostreamt == -1)
           throw new RuntimeException("No video steam found");
       if (audiostreamt == -1)
           throw new RuntimeException("No audio steam found");

       if (videocoder.open() < 0)
           throw new RuntimeException("Cant open video coder");
       IPacket packetvideo = IPacket.make();

       IStreamCoder audioCoder = containerAudio.getStream(audiostreamt).getStreamCoder();

       if (audioCoder.open() < 0)
           throw new RuntimeException("Cant open audio coder");

       mWriter.addAudioStream(0, 0, ICodec.ID.CODEC_ID_AAC, audioCoder.getChannels(),audioCoder.getSampleRate());

       mWriter.addVideoStream(1, 0, ICodec.ID.CODEC_ID_H264, videocoder.getWidth(), videocoder.getHeight());


       IPacket packetaudio = IPacket.make();

       while (containerVideo.readNextPacket(packetvideo) >= 0 || containerAudio.readNextPacket(packetaudio) >= 0) {

           if (packetvideo.getStreamIndex() == videostreamt) {

               // video packet
               IVideoPicture picture = IVideoPicture.make(videocoder.getPixelType(), videocoder.getWidth(),
                       videocoder.getHeight());
               int offset = 0;
               while (offset < packetvideo.getSize()) {
                   int bytesDecoded = videocoder.decodeVideo(picture, packetvideo, offset);
                   if (bytesDecoded < 0)
                       throw new RuntimeException("bytesDecoded not working");
                   offset += bytesDecoded;
                   if (picture.isComplete()) {
                       // System.out.println(picture.getPixelType());
                       mWriter.encodeVideo(1, picture);
                   }
               }
           }

           if (packetaudio.getStreamIndex() == audiostreamt) {
               // audio packet
               IAudioSamples samples = IAudioSamples.make(512, audioCoder.getChannels(), IAudioSamples.Format.FMT_S32);
               int offset = 0;
               while (offset < packetaudio.getSize()) {
                   int bytesDecodedaudio = audioCoder.decodeAudio(samples, packetaudio, offset);
                   if (bytesDecodedaudio < 0)
                       throw new RuntimeException("could not detect audio");
                   offset += bytesDecodedaudio;
                   if (samples.isComplete()) {
                       mWriter.encodeAudio(0, samples);
                   }
               }

           }          
       }

    The output file (mp4) is generating , but unable to play it using (vlc) and in JavaFX scene media.

    Please help me with the inputs on the above code I’m using it in a correct way (Or) help me with the possible solution for merging audio(aac) and video(h264) to mp4 container.

    Thank in advance.

  • cv2.VideoCapture on python

    27 décembre 2015, par pandasarebest

    I am running the following code :

    import numpy as np
    import cv2
    import os

    count = 0

    cap = cv2.VideoCapture("/home/simon/PROJECT/real_data/00000020.mp4")

    while not cap.isOpened():
       cap = cv2.VideoCapture("./00000020.mp4")
       cv2.waitKey(1000)
       print "Wait for the header"

    pos_frame = cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)
    while True:
       flag, frame = cap.read()
       if flag:
           # The frame is ready and already captured
           cv2.imshow('video', frame)
           pos_frame = cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)
           print str(pos_frame)+" frames"
       else:
           # The next frame is not ready, so we try to read it again
           cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, pos_frame-1)
           print "frame is not ready"
           # It is better to wait for a while for the next frame to be ready
           cv2.waitKey(1000)

       if cv2.waitKey(10) & 0xFF == 27:
           break
       if cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES) ==       cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT):
       # If the number of captured frames is equal to the total number of frames,
       # we stop
       break


    if ret == True:
       frame = cv2.VideoCapture.grab()
       frame = 'frame%d' % count

       cv2.imwrite('frame%d.png', frame)

       count += 1
    else:
       print 'stopped at' + count
       break

    And whenever I run it, it loops on the while not loop, printing "wait for header".
    There is never an error code or anything like that either.

    I have tried to run it as a more simple piece of code, where it doesnt have all these checks, and again that doesn’t throw any errors.

    I am attempting to run this code to open a video, and then save the frames as png files throughout the video.

    Does anyone spot any particular problems with the code ?
    Or alternatively does anyone know a piece of code that would do what i want more efficiently, as I have trawled through google searches and stack overflow a lot recently and haven’t found anything

    Thanks in advance
    Panda