Recherche avancée

Médias (0)

Mot : - Tags -/configuration

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (89)

  • XMP PHP

    13 mai 2011, par

    Dixit Wikipedia, XMP signifie :
    Extensible Metadata Platform ou XMP est un format de métadonnées basé sur XML utilisé dans les applications PDF, de photographie et de graphisme. Il a été lancé par Adobe Systems en avril 2001 en étant intégré à la version 5.0 d’Adobe Acrobat.
    Étant basé sur XML, il gère un ensemble de tags dynamiques pour l’utilisation dans le cadre du Web sémantique.
    XMP permet d’enregistrer sous forme d’un document XML des informations relatives à un fichier : titre, auteur, historique (...)

  • 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

  • Récupération d’informations sur le site maître à l’installation d’une instance

    26 novembre 2010, par

    Utilité
    Sur le site principal, une instance de mutualisation est définie par plusieurs choses : Les données dans la table spip_mutus ; Son logo ; Son auteur principal (id_admin dans la table spip_mutus correspondant à un id_auteur de la table spip_auteurs)qui sera le seul à pouvoir créer définitivement l’instance de mutualisation ;
    Il peut donc être tout à fait judicieux de vouloir récupérer certaines de ces informations afin de compléter l’installation d’une instance pour, par exemple : récupérer le (...)

Sur d’autres sites (6635)

  • even though my code is running without an error, it does not generate plot or video. I have xming runing

    23 octobre 2017, par Amin Abbasi

    This is my first code and I am really new to coding. I am trying to create a video or just plot my code.Eeven though my code is running without an error, I can’t get the video or the plot to generate. I have xming running and I have plotted a sample to make sure it not a computer Issue. I have also tried the following on GitHub but no success :
    https://jakevdp.github.io/blog/2013/05/19/a-javascript-viewer-for-matplotlib-animations/

    # -*- coding: utf-8 -*-
    import numpy as np
    def solver(I, V, f, c, L, dt, cc, T, user_action=None):
       """Solve u_tt=c^2*u_xx + f on (0,L)x(0,T]."""
       Nt = int(round(T/dt))
       t = np.linspace(0, Nt*dt, Nt+1) # Mesh points in time
       dx = dt*c/float(cc)
       Nx = int(round(L/dx))
       x = np.linspace(0, L, Nx+1) # Mesh points in space
       C2 = cc**2 # Help variable in the scheme
       # Make sure dx and dt are compatible with x and t
       dx = x[1] - x[0]
       dt = t[1] - t[0]
       if f is None or f == 0 :
           f = lambda x, t: 0
       if V is None or V == 0:
           V = lambda x: 0
       u       = np.zeros(Nx+1) # Solution array at new time level
       u_n     = np.zeros(Nx+1) # Solution at 1 time level back
       u_nm1   = np.zeros(Nx+1) # Solution at 2 time levels back
       import time; t0 = time.clock() # Measure CPU time
       # Load initial condition into u_n
       for i in range(0,Nx+1):
           u_n[i] = I(x[i])
       if user_action is not None:
           user_action(u_n, x, t, 0)
       # Special formula for first time step
       n = 0
       for i in range(1, Nx):
           u[i] = u_n[i] + dt*V(x[i]) + \
               0.5*C2*(u_n[i-1] - 2*u_n[i] + u_n[i+1]) + \
               0.5*dt**2*f(x[i], t[n])
       u[0] = 0; u[Nx] = 0
       if user_action is not None:
           user_action(u, x, t, 1)
       # Switch variables before next step
       u_nm1[:] = u_n; u_n[:] = u
       for n in range(1, Nt):
           # Update all inner points at time t[n+1]
           for i in range(1, Nx):
               u[i] = - u_nm1[i] + 2*u_n[i] + \
                       C2*(u_n[i-1] - 2*u_n[i] + u_n[i+1]) + \
                       dt**2*f(x[i], t[n])
           # Insert boundary conditions
           u[0] = 0; u[Nx] = 0
           if user_action is not None:
               if user_action(u, x, t, n+1):
                   break
           # Switch variables before next step
           u_nm1[:] = u_n; u_n[:] = u
       cpu_time = time.clock() - t0
       return u, x, t,
    def test_quadratic():
       """Check that u(x,t)=x(L-x)(1+t/2) is exactly reproduced."""
       def u_exact(x, t):
           return x*(L-x)*(1 + 0.5*t)
       def I(x):
           return u_exact(x, 0)
       def V(x):
           return 0.5*u_exact(x, 0)
       def f(x, t):
           return 2*(1 + 0.5*t)*c**2
       L = 2.5
       c = 1.5
       cc = 0.75
       Nx = 6 # Very coarse mesh for this exact test
       dt = cc*(L/Nx)/c
       T = 18
       def assert_no_error(u, x, t, n):
           u_e = u_exact(x, t[n])
           diff = np.abs(u - u_e).max()
           tol = 1E-13
           assert diff < tol
       solver(I, V, f, c, L, dt, cc, T,
               user_action=assert_no_error)
    def viz(
       I, V, f, c, L, dt, C, T,umin, umax, animate=True, tool='matplotlib'):
       """Run solver and visualize u at each time level."""
       def plot_u_st(u, x, t, n):
           """user_action function for solver."""
           plt.plot(x, u, 'r-')
    #                 xlabel='x', ylabel='u',
    #                 axis=[0, L, umin, umax],
    #                 title='t=%f' % t[n], show=True)
           # Let the initial condition stay on the screen for 2
           # seconds, else insert a pause of 0.2 s between each plot
           time.sleep(2) if t[n] == 0 else time.sleep(0.2)
           plt.savefig('frame_%04d.png' % n) # for movie making
       class PlotMatplotlib:
           def __call__(self, u, x, t, n):
               """user_action function for solver."""
               if n == 0:
                   plt.ion()
                   self.lines = plt.plot(x, u, 'r-')
                   plt.xlabel('x'); plt.ylabel('u')
                   plt.axis([0, L, umin, umax])
                   plt.legend(['t=%f' % t[n]], loc='lower left')
               else:
                   self.lines[0].set_ydata(u)
                   plt.legend(['t=%f' % t[n]], loc='lower left')
                   plt.draw()
               time.sleep(2) if t[n] == 0 else time.sleep(0.2)
               plt.savefig('tmp_%04d.png' % n) # for movie making
       if tool == 'matplotlib':
           import matplotlib.pyplot as plt
           plot_u = PlotMatplotlib()
       elif tool == 'scitools':
           import scitools.std as plt # scitools.easyviz interface
           plot_u = plot_u_st
       import time, glob, os
       # Clean up old movie frames
       for filename in glob.glob('tmp_*.png'):
           os.remove(filename)
       # Call solver and do the simulaton
       user_action = plot_u if animate else None
       u, x, t, cpu = solver_function(
           I, V, f, c, L, dt, C, T, user_action)
       # Make video files
       fps = 4 # frames per second
       codec2ext = dict(flv='flv', libx264='mp4', libvpx='webm',
                        libtheora='ogg') # video formats
       filespec = 'tmp_%04d.png'
       movie_program = 'ffmpeg' # or 'avconv'
       for codec in codec2ext:
           ext = codec2ext[codec]
           cmd = '%(movie_program)s -r %(fps)d -i %(filespec)s '\
                 '-vcodec %(codec)s movie.%(ext)s' % vars()
           os.system(cmd)
       if tool == 'scitools':
           # Make an HTML play for showing the animation in a browser
           plt.movie('tmp_*.png', encoder='html', fps=fps,
                     output_file='movie.html')
       return cpu
  • Delphi, TBitmap (rgb) to YCbCr colors format

    18 octobre 2019, par Alexander M.

    have a video encoding example from http://www.delphiffmpeg.com - need to convert a set of TBitmaps to YCbCr (YUV), how should we do it ? the example contains dummy colors :

     (* encode 1 second of video *)
     idx := 1;
     for i := 0 to 25 - 1 do
     begin
       av_init_packet(@pkt);
       pkt.data := nil;    // packet data will be allocated by the encoder
       pkt.size := 0;

       //fflush(stdout);
       (* prepare a dummy image *)
       (* Y *)
       for y := 0 to c.height - 1 do
         for x := 0 to c.width - 1 do
           PByte(@PAnsiChar(frame.data[0])[y * frame.linesize[0] + x])^ := x + y + i * 3;

       (* Cb and Cr *)
       for y := 0 to c.height div 2 - 1 do
         for x := 0 to c.width div 2 - 1 do
         begin
           PByte(@PAnsiChar(frame.data[1])[y * frame.linesize[1] + x])^ := 128 + y + i * 2;
           PByte(@PAnsiChar(frame.data[2])[y * frame.linesize[2] + x])^ := 64 + x + i * 5;
         end;

       frame.pts := i;

       (* encode the image *)
       ret := avcodec_encode_video2(c, @pkt, frame, @got_output);
       if ret < 0 then
       begin
         Writeln(ErrOutput, 'Error encoding frame');
         ExitCode := 1;
         Exit;
       end;

       if got_output <> 0 then
       begin
         Writeln(Format('Write frame %d (size=%d)', [idx, pkt.size]));
         FileWrite(f, pkt.data^, pkt.size);
         av_packet_unref(@pkt);
         Inc(idx);
       end;
     end;

    But we need to convert bitmaps to YCbCr..instead of filling pixels with dummy image. Here is a full source code :

    (*
    * Video encoding example
    *)
    procedure video_encode_example(const filename: string; codec_id: TAVCodecID);
    const
     endcode: array[0..3] of Byte = ( 0, 0, 1, $b7 );
    var
     codec: PAVCodec;
     c: PAVCodecContext;
     idx, i, ret, x, y, got_output: Integer;
     f: THandle;
     frame: PAVFrame;
     pkt: TAVPacket;
    begin
     Writeln(Format('Encode video file %s', [filename]));

     (* find the mpeg1 video encoder *)
     codec := avcodec_find_encoder(codec_id);
     if not Assigned(codec) then
     begin
       Writeln(ErrOutput, 'Codec not found');
       ExitCode := 1;
       Exit;
     end;

     c := avcodec_alloc_context3(codec);
     if not Assigned(c) then
     begin
       Writeln(ErrOutput, 'Could not allocate video codec context');
       ExitCode := 1;
       Exit;
     end;

     (* put sample parameters *)
     c.bit_rate := 400000;
     (* resolution must be a multiple of two *)
     c.width := 352;
     c.height := 288;
     (* frames per second *)
     c.time_base.num := 1;
     c.time_base.den := 25;
     (* emit one intra frame every ten frames
      * check frame pict_type before passing frame
      * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I
      * then gop_size is ignored and the output of encoder
      * will always be I frame irrespective to gop_size
      *)
     c.gop_size := 10;
     c.max_b_frames := 1;
     c.pix_fmt := AV_PIX_FMT_YUV420P;

     if codec_id = AV_CODEC_ID_H264 then
       av_opt_set(c.priv_data, 'preset', 'slow', 0);

     (* open it *)
     if avcodec_open2(c, codec, nil) < 0 then
     begin
       Writeln(ErrOutput, 'Could not open codec');
       ExitCode := 1;
       Exit;
     end;

     f := FileCreate(filename);
     if f = INVALID_HANDLE_VALUE then
     begin
       Writeln(ErrOutput, Format('Could not open %s', [filename]));
       ExitCode := 1;
       Exit;
     end;

     frame := av_frame_alloc();
     if not Assigned(frame) then
     begin
       Writeln(ErrOutput, 'Could not allocate video frame');
       ExitCode := 1;
       Exit;
     end;
     frame.format := Ord(c.pix_fmt);
     frame.width  := c.width;
     frame.height := c.height;

     (* the image can be allocated by any means and av_image_alloc() is
      * just the most convenient way if av_malloc() is to be used *)
     ret := av_image_alloc(@frame.data[0], @frame.linesize[0], c.width, c.height,
                          c.pix_fmt, 32);
     if ret < 0 then
     begin
       Writeln(ErrOutput, 'Could not allocate raw picture buffer');
       ExitCode := 1;
       Exit;
     end;

     (* encode 1 second of video *)
     idx := 1;
     for i := 0 to 25 - 1 do
     begin
       av_init_packet(@pkt);
       pkt.data := nil;    // packet data will be allocated by the encoder
       pkt.size := 0;

       //fflush(stdout);
       (* prepare a dummy image *)
       (* Y *)
       for y := 0 to c.height - 1 do
         for x := 0 to c.width - 1 do
           PByte(@PAnsiChar(frame.data[0])[y * frame.linesize[0] + x])^ := x + y + i * 3;

       (* Cb and Cr *)
       for y := 0 to c.height div 2 - 1 do
         for x := 0 to c.width div 2 - 1 do
         begin
           PByte(@PAnsiChar(frame.data[1])[y * frame.linesize[1] + x])^ := 128 + y + i * 2;
           PByte(@PAnsiChar(frame.data[2])[y * frame.linesize[2] + x])^ := 64 + x + i * 5;
         end;

       frame.pts := i;

       (* encode the image *)
       ret := avcodec_encode_video2(c, @pkt, frame, @got_output);
       if ret < 0 then
       begin
         Writeln(ErrOutput, 'Error encoding frame');
         ExitCode := 1;
         Exit;
       end;

       if got_output <> 0 then
       begin
         Writeln(Format('Write frame %d (size=%d)', [idx, pkt.size]));
         FileWrite(f, pkt.data^, pkt.size);
         av_packet_unref(@pkt);
         Inc(idx);
       end;
     end;

     (* get the delayed frames *)
     repeat
       //fflush(stdout);

       ret := avcodec_encode_video2(c, @pkt, nil, @got_output);
       if ret < 0 then
       begin
         Writeln(ErrOutput, 'Error encoding frame');
         ExitCode := 1;
         Exit;
       end;

       if got_output <> 0 then
       begin
         Writeln(Format('Write frame %d (size=%d)', [idx, pkt.size]));
         FileWrite(f, pkt.data^, pkt.size);
         av_packet_unref(@pkt);
         Inc(idx);
       end;
     until got_output = 0;

     (* add sequence end code to have a real mpeg file *)
     FileWrite(f, endcode[0], SizeOf(endcode));
     FileClose(f);

     avcodec_close(c);
     av_free(c);
     av_freep(@frame.data[0]);
     av_frame_free(@frame);
     Writeln('');
    end;

    yes we know this formula, but what should we do with (* Cb and Cr *) loop that goes up to c.height div 2 - 1 and c.width div 2 - 1 ? all our experiments make correct image geometry but incorrect colors... Here is what we have :

    ( Y )
       for y := 0 to c.height - 1 do
       begin
         Line := image.ScanLine[y];
         for x := 0 to c.width - 1 do
         begin
           Yy := Round(Line[x].R*0.29900 + Line[x].G*0.58700 + Line[x].B*0.11400);
           PByte(@PAnsiChar(frame.data[0])[y * frame.linesize[0] + x])^ := Yy;
         end;
       end;
       ( Cb and Cr )
       for y := 0 to c.height div 2 - 1 do
       begin
         Pixels := image.ScanLine[y];
         for x := 0 to c.width div 2 - 1 do
         begin
           Cb := Round(Line[x].R  -0.16874 - Line[x].G  0.33126 + Line[x].B * 0.50000) + 128;
           Cr := Round(Line[x].R   0.50000 - Line[x].G  0.41869 - Line[x].B * 0.08131) + 64;
           PByte(@PAnsiChar(frame.data[1])[y * frame.linesize[1] + x])^ := Cr;
           PByte(@PAnsiChar(frame.data[2])[y * frame.linesize[2] + x])^ := Cb;
           //PByte(@PAnsiChar(frame.data[1])[y  frame.linesize[1] + x])^ := 128 + y + i  2;
           //PByte(@PAnsiChar(frame.data[2])[y  frame.linesize[2] + x])^ := 64 + x + i  5;
         end;
       end;

    How this should be fixed ?

  • ffmpeg fast seek large MP4 over HTTP

    28 juillet 2024, par Gmanicus

    I'm attempting to download snapshots from a video provided by the U.S House of Representatives :

    


    https://houseliveprod-f9h4cpb9dyb8gegg.a01.azurefd.net/east/2024-04-11T08-55-12_Download/video_3000000_1.mp4


    


    I am using fluent-ffmpeg in Node to execute this command :

    


    ffmpeg('https://houseliveprod-f9h4cpb9dyb8gegg.a01.azurefd.net/east/2024-04-11T08-55-12_Download/video_3000000_1.mp4')
  .inputOption(`-ss 03:33:33`)
  .outputOptions([
     '-vframes 1'
  ])
  .output('test.png')

// Effectively:
// ffmpeg -ss 03:33:33 -i  -y -vframes 1 test.png


    


    My intention is to fast-seek to the desired timestamp and take a snapshot over HTTP. However, when doing so, the performance is not great. A snapshot takes about 10s per 3hrs of video and seems to increase fairly linearly at that rate.

    


    However, when using ffmpeg on the same video locally, it's super fast ! Sub-500ms regardless of the desired timestamp.

    


    Is there some magic that could be done via ffmpeg options or perhaps some sort of technique with manual requests to get a snapshot at the desired segment of video more efficiently ?