Recherche avancée

Médias (1)

Mot : - Tags -/3GS

Autres articles (68)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

  • Support audio et vidéo HTML5

    10 avril 2011

    MediaSPIP utilise les balises HTML5 video et audio pour la lecture de documents multimedia en profitant des dernières innovations du W3C supportées par les navigateurs modernes.
    Pour les navigateurs plus anciens, le lecteur flash Flowplayer est utilisé.
    Le lecteur HTML5 utilisé a été spécifiquement créé pour MediaSPIP : il est complètement modifiable graphiquement pour correspondre à un thème choisi.
    Ces technologies permettent de distribuer vidéo et son à la fois sur des ordinateurs conventionnels (...)

  • De l’upload à la vidéo finale [version standalone]

    31 janvier 2010, par

    Le chemin d’un document audio ou vidéo dans SPIPMotion est divisé en trois étapes distinctes.
    Upload et récupération d’informations de la vidéo source
    Dans un premier temps, il est nécessaire de créer un article SPIP et de lui joindre le document vidéo "source".
    Au moment où ce document est joint à l’article, deux actions supplémentaires au comportement normal sont exécutées : La récupération des informations techniques des flux audio et video du fichier ; La génération d’une vignette : extraction d’une (...)

Sur d’autres sites (9735)

  • Trying to change extension of filename on an ffmpeg script

    22 janvier 2019, par prat67

    (first time posting a question here)

    So I’m looking to write a ffmmpeg script to automate encoding my files to VP9.
    The problem I’m having is when I try to strip the extension and add a new one.

    For example
    Demo.mp4

    Should change to
    Demo.webm

    I’m running this on a Ubuntu-16.04 (Server Non-GI Version)
    I’ve tried a few different ways to accomplish this (using google and other posts on StackOverflow) but I can’t seem to make it work

    This is the error I keep getting..

    line 31 : Demo.mp4+.vp9 : syntax error : invalid arithmetic operator (error token is ".mp4+.vp9")

    I’ve also commented (in the code below) where the syntax error is pointing to..

    #!/bin/bash

    # Welcome Message

    clear
    printf "====================================\n"
    printf "FFMPEG Encoder\n"
    printf "(Using HDR-4k Profile)\n"
    printf "====================================\n\n"
    printf " Loading Files in Current Directory...\n\n"
    sleep 3s


    # Variables

    i=1
    ext=".webm"
    vadd=4000000
    vsub=2000000


    # Iterate through files in current directory

    for j in *.{mp4,mkv};
    do
    echo "$i.$j"
    file[i]=$j
    i=$(( i + 1 ))
    done


    # Select File & Bitrate

    printf "Enter file number\n"
    read fselect
    printf "${file[$fselect]}: Selected for encoding\n\n"

    printf "Enter Average Bitrate (Eg: 8000000)\n\n"
    read bselect


    # ***THIS IS WHERE THE PROBLEM IS***
    # Prepare output file, strip trailing extension (eg .mkv) and add .webm

    ftemp1="${file[$fselect]}"
    ftemp2="${ftemp1::-4}"
    fout="$(($ftemp2+$ext))"
    printf "Output file will be: $fout"
    printf "Preparing to encode..."
    sleep 5s


    # Encode with User-Defined Parameters

    ffmpeg -y -report -i ${file[$fselect]} -b:v $bselect -speed 4 -pass 1 \
     -pix_fmt yuv420p10le \
     -color_primaries 9 -color_trc 16 -colorspace 9 -color_range 1 \
     -maxrate "$(($bselect+$vadd))" -minrate "$(($bselect-$vsub))" \
     -profile:v 2 -vcodec libvpx-vp9 -f webm /dev/null && \
    ffmpeg -y -report -i ${file[$fselect]} -b:v $bselect -pass 2 \
     -pix_fmt yuv420p10le \
     -color_primaries 9 -color_trc 16 -colorspace 9 -color_range 1 \
     -maxrate "$(($bselect+$vadd))" -minrate "$(($bselect-$vsub))" \
     -profile:v 2 -vcodec libvpx-vp9 \
    $fout

    I’m certain there is a much cleaner way to do this - but I’m not expecting help with that :P

    My suspicion is that I’m trying to add two different types of variables ? But I thought I defined them as strings..I could be wrong

    Please Help... lol

  • Working way to make video from images in C#

    26 octobre 2013, par Jim Mischel

    Does anybody have a known reliable way to create a video from a series of image files ? Before you mod me down for not searching for the answer before posting the question, and before you fire off a simple message like "use FFMPEG," read the rest of this message.

    I'm trying to create a video, it doesn't matter too much what format as long as it's widely supported, from a series of images (.jpg, .bmp, etc.). My platform is Windows Server 2008, 64-bit. If I can make the video from within my C# program, that's great, but I'm not averse to writing a series of image files to a directory and then firing off an external program to make a video from those images.

    The only constraints are : it must work on my Windows Server 2008 system, and be scriptable. That is, no GUI programs that require operator intervention.

    I found a number of similar questions on StackOverflow, and have tried several of the solutions, all with varying degrees of frustration and none with anything like success.

    FFMPEG looks like a great program. Maybe it is, on Linux. The two Windows builds I downloaded are broken. Given this command line :

     ffmpeg -r 1 -f image2 -i jpeg\*.jpg video.avi

    One of the builds reads the images and then crashes due to data execution prevention. The other reads the first file and then spits out an error message that says "cannot find suitable codec for file jpeg/image2.jpg". Helpful, that. In any case, FFMPEG looks like a non-starter under Windows.

    One answer to a previous posting recommended Splicer . It looks like pretty good code. I compiled the samples and tried to run, but got some cryptic error message about a file not found. It looks like a COM class isn't registered. I suppose I need to install something (DirectShow, maybe, although I thought that was already installed ?). Depending on what's required, I might have a difficult time justifying its installation on a server. ("What ? Why do you need that on a server ?")

    Another answer suggested the AviFile library from Code Project. That looks simple enough : a wrapper around the Windows AviFile subsystem. Except that the AVI files the package creates appear to have all of the frames, but only the first frame shows when I play the AVI in Windows Media Player. Well, that and if you try to create a compressed video, the program throws an exception.

    So, I'm left wondering if there is a good, reliable way to do what I want : on a Windows system, create an AVI or other common video file format from a series of images, either through a .NET API or using an external program. Any help ?

  • The C++11 Thread Timer is not working

    26 août 2017, par Gathros

    I’m trying to make a video player using SDL2 and FFmpeg API. The video is being decoded and I can display an image on screen. I can also play audio but I not doing that (I know it works, I’ve tried it).

    My problem is I can’t update the image when it should be. I’m able to get the timestamps and work out the delay then send it to a thread, where it should call an window update when the time has elapsed. But all that happens is the images flash on the screen with no delay. I have even set the delay to 1 second and the images still flash, after there being 1 second of a blank window.

    Here is my code :

    extern "C"{
       //FFmpeg libraries
       #include <libavcodec></libavcodec>avcodec.h>
       #include <libavformat></libavformat>avformat.h>
       #include <libswscale></libswscale>swscale.h>

       //SDL2 libraries
       #include <sdl2></sdl2>SDL.h>
    }
    // compatibility with newer API
    #if LIBAVCODEC_VERSION_INT &lt; AV_VERSION_INT(55,28,1)
    #define av_frame_alloc avcodec_alloc_frame
    #define av_frame_free avcodec_free_frame
    #endif

    //C++ libraries
    #include <cstdio>
    #include <chrono>
    #include <thread>
    #include <atomic>
    #include <mutex>
    #include

    typedef struct PacketQueue {
       AVPacketList                *first_pkt, *last_pkt;
       std::mutex                  mutex;
       std::condition_variable     convar;
    } PacketQueue;

    std::atomic<bool>           quitting, decoded;
    std::atomic        delay;
    Uint32                      Update_Window;

    int packet_queue_put(PacketQueue *q, AVPacket *pkt){
       AVPacketList *pkt1;
       if(av_dup_packet(pkt) &lt; 0){
           return -1;
       }
       pkt1 = (AVPacketList*) av_malloc(sizeof(AVPacketList));
       if(!pkt1){
           return -1;
       }
       pkt1->pkt = *pkt;
       pkt1->next = NULL;

       std::lock_guard lock(q->mutex);

       if (!q->last_pkt){
           q->first_pkt = pkt1;
       }else{
           q->last_pkt->next = pkt1;
       }
       q->last_pkt = pkt1;
       q->convar.notify_all();
       return 0;
    }

    static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block){
       AVPacketList *pkt1;
       int ret;

       std::unique_lock lk(q->mutex);
       while(1){
           if(quitting){
               ret = -1;
               break;
           }

           pkt1 = q->first_pkt;
           if(pkt1){
               q->first_pkt = pkt1->next;
               if(!q->first_pkt){
                   q->last_pkt = NULL;
               }
               *pkt = pkt1->pkt;
               av_free(pkt1);
               ret = 1;
               break;
           }else if(decoded){
               ret = 0;
               quitting = true;
               break;
           }else if(block){
               q->convar.wait_for(lk, std::chrono::microseconds(50));
           }else {
               ret = 0;
               break;
           }
       }
       return ret;
    }

    void UpdateEventQueue(){
       SDL_Event event;
       SDL_zero(event);
       event.type = Update_Window;
       SDL_PushEvent(&amp;event);
    }

    void VideoTimerThreadFunc(){
       UpdateEventQueue();

       while(!quitting){
           if(delay == 0){
               std::this_thread::sleep_for(std::chrono::milliseconds(1));
           }else {
               std::this_thread::sleep_for(std::chrono::microseconds(delay));
               UpdateEventQueue();
           }
       }
    }

    int main(int argc, char *argv[]){
       AVFormatContext*                FormatCtx = nullptr;
       AVCodecContext*                 CodecCtxOrig = nullptr;
       AVCodecContext*                 CodecCtx = nullptr;
       AVCodec*                        Codec = nullptr;
       int                             videoStream;
       AVFrame*                        Frame = nullptr;
       AVPacket                        packet;
       struct SwsContext*              SwsCtx = nullptr;

       PacketQueue                     videoq;
       int                             frameFinished;
       int64_t                         last_pts = 0;
       const AVRational                ms = {1, 1000};

       SDL_Event                       event;
       SDL_Window*                     screen;
       SDL_Renderer*                   renderer;
       SDL_Texture*                    texture;
       std::shared_ptr<uint8>          yPlane, uPlane, vPlane;
       int                             uvPitch;

       if (argc != 2) {
           fprintf(stderr, "Usage: %s <file>\n", argv[0]);
           return -1;
       }

       // Register all formats and codecs
       av_register_all();

       // Initialise SDL2
       if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
           fprintf(stderr, "Couldn't initialise SDL - %s\n", SDL_GetError());
           return -1;
       }

       // Setting things up
       quitting = false;
       decoded = false;
       delay = 0;
       Update_Window = SDL_RegisterEvents(1);
       memset(&amp;videoq, 0, sizeof(PacketQueue));

       // Open video file
       if(avformat_open_input(&amp;FormatCtx, argv[1], NULL, NULL) != 0){
           fprintf(stderr, "Couldn't open file\n");        
           return -1; // Couldn't open file
       }

       // Retrieve stream information
       if(avformat_find_stream_info(FormatCtx, NULL) &lt; 0){
           fprintf(stderr, "Couldn't find stream information\n");

           // Close the video file
           avformat_close_input(&amp;FormatCtx);

           return -1; // Couldn't find stream information
       }

       // Find the video stream
       videoStream = av_find_best_stream(FormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
       if(videoStream &lt; 0){
           fprintf(stderr, "Couldn't find video stream\n");

           // Close the video file
           avformat_close_input(&amp;FormatCtx);

           return -1; // Didn't find a video stream
       }

       // Get a pointer to the codec context for the video stream
       CodecCtxOrig = FormatCtx->streams[videoStream]->codec;

       // Find the decoder for the video stream
       Codec = avcodec_find_decoder(CodecCtxOrig->codec_id);
       if(Codec == NULL){
           fprintf(stderr, "Unsupported codec\n");

           // Close the codec
           avcodec_close(CodecCtxOrig);

           // Close the video file
           avformat_close_input(&amp;FormatCtx);

           return -1; // Codec not found
       }

       // Copy context
       CodecCtx = avcodec_alloc_context3(Codec);
       if(avcodec_copy_context(CodecCtx, CodecCtxOrig) != 0){
           fprintf(stderr, "Couldn't copy codec context");

           // Close the codec
           avcodec_close(CodecCtxOrig);

           // Close the video file
           avformat_close_input(&amp;FormatCtx);

           return -1; // Error copying codec context
       }

       // Open codec
       if(avcodec_open2(CodecCtx, Codec, NULL) &lt; 0){
           fprintf(stderr, "Couldn't open codec\n");

           // Close the codec
           avcodec_close(CodecCtx);
           avcodec_close(CodecCtxOrig);

           // Close the video file
           avformat_close_input(&amp;FormatCtx);
           return -1; // Could not open codec
       }

       // Allocate video frame
       Frame = av_frame_alloc();

       // Make a screen to put our video
       screen = SDL_CreateWindow("Video Player", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, CodecCtx->width, CodecCtx->height, 0);
       if(!screen){
           fprintf(stderr, "SDL: could not create window - exiting\n");
           quitting = true;

           // Clean up SDL2
           SDL_Quit();

           // Free the YUV frame
           av_frame_free(&amp;Frame);

           // Close the codec
           avcodec_close(CodecCtx);
           avcodec_close(CodecCtxOrig);

           // Close the video file
           avformat_close_input(&amp;FormatCtx);

           return -1;
       }

       renderer = SDL_CreateRenderer(screen, -1, 0);
       if(!renderer){
           fprintf(stderr, "SDL: could not create renderer - exiting\n");
           quitting = true;

           // Clean up SDL2
           SDL_DestroyWindow(screen);
           SDL_Quit();

           // Free the YUV frame
           av_frame_free(&amp;Frame);

           // Close the codec
           avcodec_close(CodecCtx);
           avcodec_close(CodecCtxOrig);

           // Close the video file
           avformat_close_input(&amp;FormatCtx);
           return -1;
       }

       // Allocate a place to put our YUV image on that screen
       texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, CodecCtx->width, CodecCtx->height);
       if(!texture){
           fprintf(stderr, "SDL: could not create texture - exiting\n");
           quitting = true;

           // Clean up SDL2
           SDL_DestroyRenderer(renderer);
           SDL_DestroyWindow(screen);
           SDL_Quit();

           // Free the YUV frame
           av_frame_free(&amp;Frame);

           // Close the codec
           avcodec_close(CodecCtx);
           avcodec_close(CodecCtxOrig);

           // Close the video file
           avformat_close_input(&amp;FormatCtx);
           return -1;
       }

       // Initialise SWS context for software scaling
       SwsCtx = sws_getContext(CodecCtx->width, CodecCtx->height, CodecCtx->pix_fmt,
                   CodecCtx->width, CodecCtx->height, PIX_FMT_YUV420P, SWS_BILINEAR, NULL, NULL, NULL);
       if(!SwsCtx){
           fprintf(stderr, "Couldn't create sws context\n");
           quitting = true;

           // Clean up SDL2
           SDL_DestroyTexture(texture);
           SDL_DestroyRenderer(renderer);
           SDL_DestroyWindow(screen);
           SDL_Quit();

           // Free the YUV frame
           av_frame_free(&amp;Frame);

           // Close the codec
           avcodec_close(CodecCtx);
           avcodec_close(CodecCtxOrig);

           // Close the video file
           avformat_close_input(&amp;FormatCtx);
           return -1;
       }

       // set up YV12 pixel array (12 bits per pixel)
       yPlane = std::shared_ptr<uint8>((Uint8 *)::operator new (CodecCtx->width * CodecCtx->height, std::nothrow));
       uPlane = std::shared_ptr<uint8>((Uint8 *)::operator new (CodecCtx->width * CodecCtx->height / 4, std::nothrow));
       vPlane = std::shared_ptr<uint8>((Uint8 *)::operator new (CodecCtx->width * CodecCtx->height / 4, std::nothrow));
       uvPitch = CodecCtx->width / 2;

       if (!yPlane || !uPlane || !vPlane) {
           fprintf(stderr, "Could not allocate pixel buffers - exiting\n");
           quitting = true;

           // Clean up SDL2
           SDL_DestroyTexture(texture);
           SDL_DestroyRenderer(renderer);
           SDL_DestroyWindow(screen);
           SDL_Quit();

           // Free the YUV frame
           av_frame_free(&amp;Frame);

           // Close the codec
           avcodec_close(CodecCtx);
           avcodec_close(CodecCtxOrig);

           // Close the video file
           avformat_close_input(&amp;FormatCtx);
           return -1;
       }

       std::thread VideoTimer (VideoTimerThreadFunc);

       while (!quitting) {
           // Check for more packets
           if(av_read_frame(FormatCtx, &amp;packet) >= 0){
               // Check what stream it belongs to
               if (packet.stream_index == videoStream) {
                   packet_queue_put(&amp;videoq, &amp;packet);
               }else{
                   // Free the packet that was allocated by av_read_frame
                   av_free_packet(&amp;packet);
               }
           }else {
               decoded = true;
           }

           SDL_PollEvent(&amp;event);

           if(event.type == Update_Window){
               // Getting packet
               if(packet_queue_get(&amp;videoq, &amp;packet, 0)){
                   // Decode video frame
                   avcodec_decode_video2(CodecCtx, Frame, &amp;frameFinished, &amp;packet);

                   // Did we get a video frame?
                   if (frameFinished) {
                       AVPicture pict;
                       pict.data[0] = yPlane.get();
                       pict.data[1] = uPlane.get();
                       pict.data[2] = vPlane.get();
                       pict.linesize[0] = CodecCtx->width;
                       pict.linesize[1] = uvPitch;
                       pict.linesize[2] = uvPitch;

                       // Convert the image into YUV format that SDL uses
                       sws_scale(SwsCtx, (uint8_t const * const *) Frame->data, Frame->linesize, 0, CodecCtx->height, pict.data, pict.linesize);

                       SDL_UpdateYUVTexture(texture, NULL, yPlane.get(), CodecCtx->width, uPlane.get(), uvPitch, vPlane.get(), uvPitch);

                       SDL_RenderClear(renderer);
                       SDL_RenderCopy(renderer, texture, NULL, NULL);
                       SDL_RenderPresent(renderer);

                       // Calculating delay
                       delay = av_rescale_q(packet.dts, CodecCtx->time_base, ms) - last_pts;
                       last_pts = av_rescale_q(packet.dts, CodecCtx->time_base, ms);
                   }else{
                       //UpdateEventQueue();
                       delay = 1;
                   }

                   // Free the packet that was allocated by av_read_frame
                   av_free_packet(&amp;packet);

               }else{
                   //UpdateEventQueue();
               }
           }

           switch (event.type) {
               case SDL_QUIT:
                   quitting = true;
                   break;

               default:
                   break;
           }
       }

       VideoTimer.join();

       //SDL2 clean up
       SDL_DestroyTexture(texture);
       SDL_DestroyRenderer(renderer);
       SDL_DestroyWindow(screen);
       SDL_Quit();

       // Free the YUV frame
       av_frame_free(&amp;Frame);

       // Free Sws
       sws_freeContext(SwsCtx);

       // Close the codec
       avcodec_close(CodecCtx);
       avcodec_close(CodecCtxOrig);

       // Close the video file
       avformat_close_input(&amp;FormatCtx);

       return 0;
    }
    </uint8></uint8></uint8></file></uint8></bool></mutex></atomic></thread></chrono></cstdio>