Recherche avancée

Médias (2)

Mot : - Tags -/doc2img

Autres articles (22)

  • La sauvegarde automatique de canaux SPIP

    1er avril 2010, par

    Dans le cadre de la mise en place d’une plateforme ouverte, il est important pour les hébergeurs de pouvoir disposer de sauvegardes assez régulières pour parer à tout problème éventuel.
    Pour réaliser cette tâche on se base sur deux plugins SPIP : Saveauto qui permet une sauvegarde régulière de la base de donnée sous la forme d’un dump mysql (utilisable dans phpmyadmin) mes_fichiers_2 qui permet de réaliser une archive au format zip des données importantes du site (les documents, les éléments (...)

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

  • Automated installation script of MediaSPIP

    25 avril 2011, par

    To overcome the difficulties mainly due to the installation of server side software dependencies, an "all-in-one" installation script written in bash was created to facilitate this step on a server with a compatible Linux distribution.
    You must have access to your server via SSH and a root account to use it, which will install the dependencies. Contact your provider if you do not have that.
    The documentation of the use of this installation script is available here.
    The code of this (...)

Sur d’autres sites (3581)

  • FFmpeg : undefined references to av_frame_alloc()

    6 août 2014, par dontrythisathome

    I want to get into FFmpeg developing and i started following these samples tutorial here : here

    I started with the first tutorial - tutorial01.c - but i run into this problem ’undefined references to av_frame_alloc()’.

    I’m on Ubuntu 12.04 LTS.

    This is my program :

    /*
    * File:   main.c
    * Author: dontrythisathome
    *
    * Created on 3 giugno 2014, 23.02
    */

    #include
    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavformat></libavformat>avformat.h>
    #include <libavutil></libavutil>frame.h>
    #include <libswscale></libswscale>swscale.h>
    /*
    *
    */
    void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame)
       {
           FILE   *pFile;
           char  szFilename[32];
           int       y;

           //Apre il file
           sprintf(szFilename, "frame%d.ppm", iFrame);
           pFile=fopen(szFilename, "wb");
           if(pFile==NULL)
           {return; }

           //Scrive l'intestazione del file ( Larghezza x Altezza su video)
           fprintf(pFile, "P6\n%d %d\n255\n", width, height);

           //Scrive i data pixel
           for(y=0; ydata[0]+y*pFrame->linesize[0], 1, width*3, pFile);
           }

           //Chiude il file
           fclose(pFile);
         }
    /*
    *
    */
    /*Main Function*/
    int main(int argc, char *argv[])
    {
       AVFormatContext *pFormatCtx;
       int                                     i, videoStreamIdx;
       AVCodecContext   *pCodecCtx;
       AVCodec                      *pCodec;
       AVFrame                      *pFrame;
       AVFrame                      *pFrameRGB;
       AVPacket                     packet;
       int                                     frameFinished;
       int                                     numBytes;
       uint8_t                           *buffer;
       static struct SwsContext  *img_convert_ctx;

       if(argc &lt; 2){
           printf("Inserisci un file video\n");
           return -1;
       }

       //Registra tutti i formati e i codec
       av_register_all();

       //Apre il file video
       if(avformat_open_input(&amp;pFormatCtx, argv[1], NULL, NULL) != 0)
       {return -1;} //Impossibile aprire il file

       //Recupera le informazioni dello stream
       if(avformat_find_stream_info(pFormatCtx, NULL) &lt; 0)
       {return -1;} // Couldn't find stream information

       //Versa le informazioni del file sullo standard error
       av_dump_format(pFormatCtx, 0, argv[1], 0);

       //Trova il primo stream video
       videoStreamIdx=-1;
       for(i=0; inb_streams; i++)
       {
           if(pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
           { videoStreamIdx=i;
               break;}
       }

       if(videoStreamIdx==-1)
           return -1; // Impossibile trovare lo stream video

       // Punta al contenuto del codec per lo stream video
       pCodecCtx = pFormatCtx->streams[videoStreamIdx]->codec;

       // Trova il decoder per lo stream video
       pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
       if(pCodec==NULL)
       {
           fprintf(stderr, "Codec Non Supportato!\n");
           return -1; //Impossibile trovare il codec
       }

       //Apre il codec
       if(avcodec_open2(pCodecCtx, pCodec, NULL) &lt; 0)
       {return -1;} //Impossibile aprire il codec

       //Alloca il frame video
       pFrame = av_frame_alloc();

       //Alloca una struct AVFrame
       pFrameRGB = av_frame_alloc();
       if(pFrameRGB==NULL)
       {return -1;}

       //Determina la grandezza necessaria per il buffer e lo alloca
       numBytes = avpicture_get_size(PIX_FMT_RGB24,
                                                                               pCodecCtx->width,
                                                                               pCodecCtx->height);

       buffer = (uint8_t *) av_malloc(numBytes*sizeof(uint8_t));

       //Assegna le parti appropriate del buffer sulla superficie dell'immagine in pFrameRGB
       //Tenere presente che pFrameRGB è un AVFrame, ma AVFrame è una superset di AVPicture
       avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);

       int w = pCodecCtx->width;
       int h = pCodecCtx->height;
       img_convert_ctx = sws_getContext(w, h, pCodecCtx->pix_fmt,
                                                                                          w, h, PIX_FMT_RGB24,
                                                                                           SWS_LANCZOS, NULL, NULL, NULL);

       //Legge i frame e salva i primi 5 frame su disco
      i=0;
      while((av_read_frame(pFormatCtx, &amp;packet)>=0) &amp;&amp; (i&lt;5))
      {
          //Questo è il packet dello stream video?
          if(packet.stream_index==videoStreamIdx)
          {
              //Decodifica il frame video
              avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished, &amp;packet);

              //Si è riusiciti ad ottenere il frame video?
              if(frameFinished)
              {
                  i++;
                  sws_scale(img_convert_ctx, (const uint8_t * const *)pFrame->data,
                                           pFrame->linesize, 0, pCodecCtx->height,
                                           pFrameRGB->data, pFrameRGB->linesize);
                  SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, i);
              }
          }

          //Libera il pacchetto che era allocato da av_read_frame
          av_free_packet(&amp;packet);
      }

      //Libera l'immagine RGB
      av_free(buffer);
      av_free(pFrameRGB);

      //Libera il frame YUV
      av_free(pFrame);

      //Chiude il codec
      avcodec_close(pCodecCtx);

      //Chiude il file video
      avformat_close_input(&amp;pFormatCtx);

      /*FINE PROGRAMMA*/

       return 0;
    }

    This is the build output :

    "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
    make[1]: ingresso nella directory "/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid"
    "/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/simplemediaplayerforandroid
    make[2]: ingresso nella directory "/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid"
    mkdir -p dist/Debug/GNU-Linux-x86
    gcc     -o dist/Debug/GNU-Linux-x86/simplemediaplayerforandroid build/Debug/GNU-Linux-x86/main.o -L/usr/lib/x86_64-linux-gnu -lavformat -lavcodec -lavutil -lswscale -lz -lbz2
    build/Debug/GNU-Linux-x86/main.o: In function `main':
    /home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid/main.c:105: undefined reference to `av_frame_alloc'
    /home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid/main.c:108: undefined reference to `av_frame_alloc'
    collect2: ld returned 1 exit status
    make[2]: *** [dist/Debug/GNU-Linux-x86/simplemediaplayerforandroid] Errore 1
    make[2]: uscita dalla directory "/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid"
    make[1]: *** [.build-conf] Errore 2
    make[1]: uscita dalla directory "/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid"
    make: *** [.build-impl] Errore 2

    BUILD FAILED (exit value 2, total time: 143ms)

    I also linked the correct library path and headers path because there is no error with that.

    But when i try to build the program from the terminal with these commands :

    gcc -o prog1 /home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid/main.c -lavformat -lavcodec -lavutil -lswscale -lz -lbz2

    And the output is different :

    /home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid/main.c:11:29: fatal error: libavutil/frame.h: File o directory non esistente
    compilation terminated.

    The output says that there is no file or directory existing.
    What is the problem ?

  • Problem opening xvid264 with avcodec_alloc_context(NULL)

    12 juillet 2024, par user3763774

    I want to multiplex audio and video together using the ffmpeg encoding library with xvid264rgb codec. I can open the codec when I create the context specifying that codec, but not if I use NULL for the argument with allocate context. My understanding is I need to use NULL so I can open the audio codec as well.

    &#xA;

    In the example, the first open works with codec indicated in the allocate context. The second doesn't.

    &#xA;

    #include &#xA;#include &#xA;#include &#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavutil></libavutil>opt.h>&#xA;#define WIDTH 400&#xA;#define HEIGHT 300&#xA;&#xA;const AVCodec *videocodec;&#xA;&#xA;bool init_video_encoder(AVCodecContext *c, int width, int height) {&#xA;    int ret;&#xA;    &#xA;    const AVRational tb_rat = {1, 30};&#xA;    const AVRational fr_rat = {30, 1};&#xA;&#xA;    fprintf(stderr, "init video encoder\n");&#xA;    // video&#xA;    //fprintf(stderr, "speed= %d \n", videocodec->speed);&#xA;    c->bit_rate = 400000;&#xA;    c->width = width;&#xA;    c->height = height;&#xA;    c->time_base = tb_rat;&#xA;    c->framerate = fr_rat;&#xA;    c->gop_size = 10;&#xA;    c->max_b_frames = 1;&#xA;    c->pix_fmt = AV_PIX_FMT_RGB24;&#xA;    if( videocodec->id == AV_CODEC_ID_H264 ) &#xA;        av_opt_set(c->priv_data, "preset", "slow", 0);&#xA;        &#xA;    ret = avcodec_open2(c, videocodec, NULL);&#xA;    if( ret &lt; 0 ) {&#xA;        fprintf(stderr, "failure to open codec: %s\n", av_err2str(ret));&#xA;        return false;&#xA;    }&#xA;    //avcodec_free_context(&amp;c);&#xA;    return true;&#xA;}&#xA;&#xA;int main(int argc, char **argv) {&#xA;&#xA;    AVCodecContext *context = NULL;&#xA;&#xA;    videocodec = avcodec_find_encoder_by_name("libx264rgb");&#xA;    if( videocodec == NULL ) {&#xA;        fprintf(stderr, "video encoder &#x27;libx264rgb&#x27; not found");&#xA;        exit;&#xA;    }&#xA;&#xA;    context = avcodec_alloc_context3(videocodec);&#xA;    if( context == NULL ) {&#xA;        fprintf(stderr, "could not allocate context with codec");&#xA;        return false;&#xA;    }&#xA;    if( init_video_encoder( context, WIDTH, HEIGHT ) ) &#xA;        fprintf(stderr, " success initializing video encoder case one\n");&#xA;    else&#xA;        fprintf(stderr, " failure to initialize video encoder case one\n");&#xA;    avcodec_close( context );&#xA;&#xA;    context = avcodec_alloc_context3(NULL);&#xA;    if( context == NULL ) {&#xA;        fprintf(stderr, "could not allocate context without codec");&#xA;        return false;&#xA;    }&#xA;    if( init_video_encoder( context, WIDTH, HEIGHT ) ) &#xA;        fprintf(stderr, " success initializing video encoder case two\n");&#xA;    else&#xA;        fprintf(stderr, " failure to initialize video encoder case two\n");&#xA;    avcodec_close( context );&#xA;}&#xA;

    &#xA;

    Here is the error message :

    &#xA;

    broken ffmpeg default settings detected&#xA;use an encoding preset (e.g. -vpre medium)&#xA;preset usage: -vpre <speed> -vpre <profile>&#xA;speed presets are listed in x264 --help&#xA;profile is optional; x264 defaults to high&#xA;failure to open codec: Generic error in an external library&#xA;failure to initialize video encoder case two&#xA;</profile></speed>

    &#xA;

    Is this the right approach to use ? How do I set the encoding preset ? The code appears already to do that.

    &#xA;

  • Transcoding Videos Using FastAPI and ffmpeg

    15 janvier 2024, par Sanji Vinsmoke

    I created an API using Fast API where I upload one or more videos, may specify the resolution of transcoding, and the output is transcoded video from 240p upto the resolution I specified. Available resolutions are - 240p, 360p, 480p, 720p, 1080p. I used ffmpeg for the transcoding job.

    &#xA;

    The problem that is bugging me since yesterday is that, after deploying to the s3 bucket and adding the url for the index.m3u8 file in any hls player, the video is blank. Only the audio and streaming are working. I have tried tweaking with the parameters in the ffmpeg parameters, the error is still there. I tried manually transcoding a video file locally, even that video's index.m3u8 file is blank in live version. I added the relevant codes for this project. I implemented each feature one by one, but I simply cannot find the reason why the video is totally blank on live.

    &#xA;

    def transcode_video(input_path, output_folder, res, video_id, video_resolution, progress_bar=None):&#xA;    # Transcode the video into .m3u8 format with segment format&#xA;    output_path = os.path.join(output_folder, f"{res}_{video_id}.m3u8")&#xA;&#xA;    # Use subprocess for command execution&#xA;    chunk_size = 1 # Specify the desired chunk size in seconds&#xA;&#xA;    transcode_command = [&#xA;        "ffmpeg", "-i", input_path, "-vf", f"scale={res}:&#x27;trunc(ow/a/2)*2&#x27;", "-c:a", "aac", "-strict", "-2",&#xA;        "-f", "segment", "-segment_time", str(chunk_size), "-segment_list", output_path, "-segment_format", "ts",&#xA;        f"{output_path.replace(&#x27;.m3u8&#x27;, &#x27;_%03d.ts&#x27;)}"&#xA;    ]&#xA;&#xA;    try:&#xA;        subprocess.run(transcode_command, check=True, capture_output=True)&#xA;    except subprocess.CalledProcessError as e:&#xA;        print(f"Error during transcoding: {e}")&#xA;        print(f"FFmpeg error output: {e.stderr}")&#xA;        # Continue with the next video even if an error occurs&#xA;        return False&#xA;&#xA;    # Update the progress bar&#xA;    if progress_bar:&#xA;        progress_bar.update(1)&#xA;    return True&#xA;&#xA;&#xA;def get_bandwidth(resolution):&#xA;    # Define a simple function to calculate bandwidth based on resolution&#xA;    resolutions_and_bandwidths = {&#xA;        240: 400000,&#xA;        360: 850000,&#xA;        480: 1400000,&#xA;        720: 2500000,&#xA;        1080: 4500000,&#xA;    }&#xA;    &#xA;    return resolutions_and_bandwidths.get(resolution, 0)&#xA;def create_index_m3u8(video_id, resolutions_to_transcode):&#xA;    # Write the index.m3u8 file&#xA;    index_m3u8_path = os.path.join(OUTPUT_FOLDER, f"index_{video_id}.m3u8")&#xA;    with open(index_m3u8_path, "w") as index_file:&#xA;        index_file.write("#EXTM3U\n")&#xA;        index_file.write("#EXT-X-VERSION:3\n")&#xA;&#xA;        for res in resolutions_to_transcode:&#xA;            aspect_ratio = 16 / 9&#xA;            folder_name = f"{res}p_{video_id}"&#xA;            resolution_file_name = f"{res}_{video_id}.m3u8"&#xA;            index_file.write(&#xA;                f"#EXT-X-STREAM-INF:BANDWIDTH={get_bandwidth(res)},RESOLUTION={int(res * aspect_ratio)}x{res}\n{folder_name}/{resolution_file_name}\n"&#xA;            )&#xA;

    &#xA;

    I tried reducing or increasing chunk size, adding codecs, setting up dimensions. Where am I doing wrong ?

    &#xA;

    My python version is 3.8.18, ffmpeg version-4.4.4, ffmpeg-python version-0.2.0

    &#xA;