Recherche avancée

Médias (91)

Autres articles (99)

  • Script d’installation automatique de MediaSPIP

    25 avril 2011, par

    Afin de palier aux difficultés d’installation dues principalement aux dépendances logicielles coté serveur, un script d’installation "tout en un" en bash a été créé afin de faciliter cette étape sur un serveur doté d’une distribution Linux compatible.
    Vous devez bénéficier d’un accès SSH à votre serveur et d’un compte "root" afin de l’utiliser, ce qui permettra d’installer les dépendances. Contactez votre hébergeur si vous ne disposez pas de cela.
    La documentation de l’utilisation du script d’installation (...)

  • La gestion des forums

    3 novembre 2011, par

    Si les forums sont activés sur le site, les administrateurs ont la possibilité de les gérer depuis l’interface d’administration ou depuis l’article même dans le bloc de modification de l’article qui se trouve dans la navigation de la page.
    Accès à l’interface de modération des messages
    Lorsqu’il est identifié sur le site, l’administrateur peut procéder de deux manières pour gérer les forums.
    S’il souhaite modifier (modérer, déclarer comme SPAM un message) les forums d’un article particulier, il a à sa (...)

  • Les autorisations surchargées par les plugins

    27 avril 2010, par

    Mediaspip core
    autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs

Sur d’autres sites (7711)

  • Losing quality when encoding with ffmpeg

    22 mai 2016, par lupod

    I am using the c libraries of ffmpeg to read frames from a video and create an output file that is supposed to be identical to the input.
    However, somewhere during this process some quality gets lost and the result is "less sharp". My guess is that the problem is the encoding and that the frames are too compressed (also because the size of the file decreases quite significantly). Is there some parameter in the encoder that allows me to control the quality of the result ? I found that AVCodecContext has a compression_level member, but changing it that does not seem to have any effect.

    I post here part of my code in case it could help. I would say that something must be changed in the init function of OutputVideoBuilder when I set the codec. The AVCodecContext that is passed to the method is the same of InputVideoHandler.
    Here are the two main classes that I created to wrap the ffmpeg functionalities :

    // This class opens the video files and sets the decoder
    class InputVideoHandler {
    public:
     InputVideoHandler(char* name);
     ~InputVideoHandler();
     AVCodecContext* getCodecContext();
     bool readFrame(AVFrame* frame, int* success);

    private:
     InputVideoHandler();
     void init(char* name);
     AVFormatContext* formatCtx;
     AVCodec* codec;
     AVCodecContext* codecCtx;
     AVPacket packet;
     int streamIndex;
    };

    void InputVideoHandler::init(char* name) {
     streamIndex = -1;
     int numStreams;

     if (avformat_open_input(&formatCtx, name, NULL, NULL) != 0)
       throw std::exception("Invalid input file name.");

     if (avformat_find_stream_info(formatCtx, NULL)<0)
       throw std::exception("Could not find stream information.");

     numStreams = formatCtx->nb_streams;

     if (numStreams < 0)
       throw std::exception("No streams in input video file.");

     for (int i = 0; i < numStreams; i++) {
       if (formatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
         streamIndex = i;
         break;
       }
     }

     if (streamIndex < 0)
       throw std::exception("No video stream in input video file.");

     // find decoder using id
     codec = avcodec_find_decoder(formatCtx->streams[streamIndex]->codec->codec_id);
     if (codec == nullptr)
       throw std::exception("Could not find suitable decoder for input file.");

     // copy context from input stream
     codecCtx = avcodec_alloc_context3(codec);
     if (avcodec_copy_context(codecCtx, formatCtx->streams[streamIndex]->codec) != 0)
       throw std::exception("Could not copy codec context from input stream.");

     if (avcodec_open2(codecCtx, codec, NULL) < 0)
       throw std::exception("Could not open decoder.");
    }

    // frame must be initialized with av_frame_alloc() before!
    // Returns true if there are other frames, false if not.
    // success == 1 if frame is valid, 0 if not.
    bool InputVideoHandler::readFrame(AVFrame* frame, int* success) {
     *success = 0;
     if (av_read_frame(formatCtx, &packet) < 0)
       return false;
     if (packet.stream_index == streamIndex) {
       avcodec_decode_video2(codecCtx, frame, success, &packet);
     }
     av_free_packet(&packet);
     return true;
    }

    // This class opens the output and write frames to it
    class OutputVideoBuilder{
    public:
     OutputVideoBuilder(char* name, AVCodecContext* inputCtx);
     ~OutputVideoBuilder();
     void writeFrame(AVFrame* frame);
     void writeVideo();

    private:
     OutputVideoBuilder();
     void init(char* name, AVCodecContext* inputCtx);
     void logMsg(AVPacket* packet, AVRational* tb);
     AVFormatContext* formatCtx;
     AVCodec* codec;
     AVCodecContext* codecCtx;
     AVStream* stream;
    };

    void OutputVideoBuilder::init(char* name, AVCodecContext* inputCtx) {
     if (avformat_alloc_output_context2(&formatCtx, NULL, NULL, name) < 0)
       throw std::exception("Could not determine file extension from provided name.");

     codec = avcodec_find_encoder(inputCtx->codec_id);
     if (codec == nullptr) {
       throw std::exception("Could not find suitable encoder.");
     }

     codecCtx = avcodec_alloc_context3(codec);
     if (avcodec_copy_context(codecCtx, inputCtx) < 0)
       throw std::exception("Could not copy output codec context from input");

     codecCtx->time_base = inputCtx->time_base;
     codecCtx->compression_level = 0;

     if (avcodec_open2(codecCtx, codec, NULL) < 0)
       throw std::exception("Could not open encoder.");

     stream = avformat_new_stream(formatCtx, codec);
     if (stream == nullptr) {
       throw std::exception("Could not allocate stream.");
     }

     stream->id = formatCtx->nb_streams - 1;
     stream->codec = codecCtx;
     stream->time_base = codecCtx->time_base;



     av_dump_format(formatCtx, 0, name, 1);
     if (!(formatCtx->oformat->flags & AVFMT_NOFILE)) {
       if (avio_open(&formatCtx->pb, name, AVIO_FLAG_WRITE) < 0) {
         throw std::exception("Could not open output file.");
       }
     }

     if (avformat_write_header(formatCtx, NULL) < 0) {
       throw std::exception("Error occurred when opening output file.");
     }

    }

    void OutputVideoBuilder::writeFrame(AVFrame* frame) {
     AVPacket packet = { 0 };
     int success;
     av_init_packet(&packet);

     if (avcodec_encode_video2(codecCtx, &packet, frame, &success))
       throw std::exception("Error encoding frames");

     if (success) {
       av_packet_rescale_ts(&packet, codecCtx->time_base, stream->time_base);
       packet.stream_index = stream->index;
       logMsg(&packet,&stream->time_base);
       av_interleaved_write_frame(formatCtx, &packet);
     }
     av_free_packet(&packet);
    }

    This is the part of the main function that reads and write frames :

    while (inputHandler->readFrame(frame,&gotFrame)) {

       if (gotFrame) {
         try {
           outputBuilder->writeFrame(frame);
         }
         catch (std::exception e) {
           std::cout << e.what() << std::endl;
           return -1;
         }
       }
     }
  • OpenShift — installing ffmpeg

    2 juillet 2016, par aweeeezy

    I’m new to deploying web apps — I just started looking into hosting plans yesterday morning when I settled on OpenShift. I have my app running, but it depends on node-youtube-dl which returns this error when trying to download a video from a link :

    Error: Command failed: WARNING: m_djk1RQ2Ew: writing DASH m4a. Only some players support this container. Install ffmpeg or avconv to fix this automatically.
    ERROR: ffprobe or avprobe not found. Please install one.

    So I searched around for awhile and kept returning to the same list instructions for how to install ffmpeg on OpenShift :

    cd $OPENSHIFT_DATA_DIR
    mkdir bin
    wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
    wget http://ffmpeg.org/releases/ffmpeg-2.0.1.tar.gz

    tar -xvf yasm-1.2.0.tar.gz
    cd yasm-1.2.0
    ./configure --prefix=$OPENSHIFT_DATA_DIR/bin --bindir=$OPENSHIFT_DATA_DIR/bin
    make
    make install
    export PATH=$OPENSHIFT_DATA_DIR/bin:$PATH

    cd $OPENSHIFT_DATA_DIR
    tar -xvf ffmpeg-2.0.1.tar.gz
    cd ffmpeg-2.0.1
    ./configure --prefix=$OPENSHIFT_DATA_DIR/bin --bindir=$OPENSHIFT_DATA_DIR/bin
    make
    make install

    Now my ~/app-root/data has ffprobe in it as well as some other codec related things, but node-youtube-dl still returns the same error saying I don’t have the necessary codecs installed. Here’s a listing of the contents of my data directory on OpenShift :

    -rwxr-xr-x.  1  11024048 Jul  2 01:51 ffmpeg
    -rwxr-xr-x.  1  10967408 Jul  2 01:51 ffprobe
    -rwxr-xr-x.  1  10611184 Jul  2 01:51 ffserver
    drwx------. 10      4096 Jul  2 01:51 include
    drwx------.  3      4096 Jul  2 01:51 lib
    drwx------.  4        29 Jul  2 01:51 share
    -rwxr-xr-x.  1   2116650 Jul  2 01:15 vsyasm
    -rwxr-xr-x.  1   2115479 Jul  2 01:15 yasm
    -rwxr-xr-x.  1   2102821 Jul  2 01:15 ytasm

    I really want OpenShift to work because it’s the last step to finishing off this one app before I move onto new projects — I don’t want to switch to paid hosting that will allow me to install stuff because I won’t be ready to determine an appropriate plan until a few months from now. That leaves me with trying to get ffmpeg to compile properly on OpenShift...so either a) I’m ignorant and it has long since been determined to be impossible by the OpenShift community or b) I’m ignorant and there’s a simple thing I’m doing wrong when building my codec libraries.

    Anybody out there know what’s wrong or had success installing these codecs before ? I’d greatly appreciate some guidance !

  • FFMPEG, leaking memory

    8 juin 2016, par Nyaruko

    I use the following code to open a MP4 file. Each time the MP4 file is opened successfully by calling QVideoDecoder::openFile(QString filename).
    The initCode is called at the beginning of the program.

    However, each time I run the openFile(QString filename) function on the same file. There are some memory leak. What is wrong with my code ?

    void QVideoDecoder::InitVars()
    {
       //Input
       //-------------------
       ok = false;
       pFormatCtx = 0;
       pCodecCtx = 0;
       pCodec = 0;
       pFrame = 0;
       pFrameRGB = 0;
       buffer = 0;
       img_convert_ctx = 0;
       th = 0;
    }

    void QVideoDecoder::close()
    {
      // Free the RGB image
      if(buffer)
         delete [] buffer;

      // Free the YUV frame
      if(pFrame)
         av_free(pFrame);

      // Free the RGB frame
      if(pFrameRGB)
         av_free(pFrameRGB);

      // Close the codec
      if(pCodecCtx)
         avcodec_close(pCodecCtx);

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

      // Close the timeout handler
      if (th)
          delete th;

      InitVars();
    }

    bool QVideoDecoder::initCodec()
    {

      ffmpeg::avcodec_register_all();
      ffmpeg::av_register_all();
      ffmpeg::avdevice_register_all();
      ffmpeg::avformat_network_init();

      printf("License: %s\n",ffmpeg::avformat_license());
      printf("AVCodec version %d\n",ffmpeg::avformat_version());
      printf("AVFormat configuration: %s\n",ffmpeg::avformat_configuration());

      return true;
    }

    bool QVideoDecoder::openFile(QString filename)
    {
       // Close the last video
       //----------------------------------------------
       close();

       // Initialize the params
       // ---------------------------------------------
       ffmpeg::AVInputFormat *iformat = NULL;
       ffmpeg::AVDictionary *opts = NULL;          
       ffmpeg::av_dict_set(&opts, "rtsp_transport", "tcp", NULL);
       ffmpeg::av_dict_set(&opts, "rtbufsize", "102400", NULL);
       ffmpeg::av_dict_set(&opts, "allowed_media_types", "video", NULL);


       //set the timeout handler for pFormatCtx
       //----------------------------------------------
       pFormatCtx = ffmpeg::avformat_alloc_context();
       th = new timeout_handler(3000000);
       pFormatCtx->interrupt_callback.opaque = (void*)th;
       pFormatCtx->interrupt_callback.callback = &timeout_handler::check_interrupt;

       // Open video file
       //---------------------------------------------
       th->reset(3000000);
       avformat_open_input(&pFormatCtx, filename.toStdString().c_str(), iformat, &opts) != 0)
       av_dict_free(&opts);

       // Retrieve stream information
       //---------------------------------------------
       th->reset(3000000);
       avformat_find_stream_info(pFormatCtx, NULL);

       // Dump information about file onto standard error
       //---------------------------------------------
       av_dump_format(pFormatCtx, 0, filename.toStdString().c_str(), false);

       // Find the first video stream
       //---------------------------------------------
       for (unsigned i = 0; i < pFormatCtx->nb_streams; i++)
       {
           if (pFormatCtx->streams[i]->codec->codec_type == ffmpeg::AVMEDIA_TYPE_VIDEO)
           {
               videoStream = i;
               break;
           }
       }

       // 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);

       // Set thread type to 0 seems decrease the amount of delay
       //--------------------------------------------
       pCodecCtx->thread_type = 0;
    // Open codec
    //--------------------------------------------
    avcodec_open2(pCodecCtx, pCodec, NULL);

    // Allocate video frame
    //--------------------------------------------
    pFrame = ffmpeg::avcodec_alloc_frame();

    // Allocate an AVFrame structure
    //--------------------------------------------
    pFrameRGB = ffmpeg::avcodec_alloc_frame();

    // Determine required buffer size and allocate buffer
    //--------------------------------------------
    numBytes = ffmpeg::avpicture_get_size(ffmpeg::PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
    buffer = new uint8_t[numBytes];

    // Assign appropriate parts of buffer to image planes in pFrameRGB
    //--------------------------------------------
    avpicture_fill((ffmpeg::AVPicture *)pFrameRGB, buffer, ffmpeg::PIX_FMT_RGB24,
       pCodecCtx->width, pCodecCtx->height);

    return true;
    }