Recherche avancée

Médias (0)

Mot : - Tags -/upload

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

Autres articles (27)

  • Submit bugs and patches

    13 avril 2011

    Unfortunately a software is never perfect.
    If you think you have found a bug, report it using our ticket system. Please to help us to fix it by providing the following information : the browser you are using, including the exact version as precise an explanation as possible of the problem if possible, the steps taken resulting in the problem a link to the site / page in question
    If you think you have solved the bug, fill in a ticket and attach to it a corrective patch.
    You may also (...)

  • 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

  • MediaSPIP Player : les contrôles

    26 mai 2010, par

    Les contrôles à la souris du lecteur
    En plus des actions au click sur les boutons visibles de l’interface du lecteur, il est également possible d’effectuer d’autres actions grâce à la souris : Click : en cliquant sur la vidéo ou sur le logo du son, celui ci se mettra en lecture ou en pause en fonction de son état actuel ; Molette (roulement) : en plaçant la souris sur l’espace utilisé par le média (hover), la molette de la souris n’exerce plus l’effet habituel de scroll de la page, mais diminue ou (...)

Sur d’autres sites (4278)

  • Working on images asynchronously

    15 décembre 2013, par Mikko Koppanen — Imagick, PHP stuff

    To get my quota on buzzwords for the day we are going to look at using ZeroMQ and Imagick to create a simple asynchronous image processing system. Why asynchronous ? First of all, separating the image handling from a interactive PHP scripts allows us to scale the image processing separately from the web heads. For example we could do the image processing on separate servers, which have SSDs attached and more memory. In this example making the images available to all worker nodes is left to the reader.

    Secondly, separating the image processing from a web script can provide more responsive experience to the user. This doesn’t necessarily mean faster, but let’s say in a multiple image upload scenario this method allows the user to do something else on the site while we process the images in the background. This can be beneficial especially in cases where users upload hundreds of images at a time. To achieve a simple distributed image processing infrastructure we are going to use ZeroMQ for communicating between different components and Imagick to work on the images.

    The first part we are going to create is a simple “Worker” -process skeleton. Naturally for a live environment you would like to have more error handling and possibly use pcntl for process control, but for the sake of brewity the example is barebones :

    1. < ?php
    2.  
    3. define (’THUMBNAIL_ADDR’, ’tcp ://127.0.0.1:5000’) ;
    4. define (’COLLECTOR_ADDR’, ’tcp ://127.0.0.1:5001’) ;
    5.  
    6. class Worker {
    7.  
    8.   private $in ;
    9.   private $out ;
    10.  
    11.   public function __construct ($in_addr, $out_addr)
    12.   {
    13.     $context = new ZMQContext () ;
    14.  
    15.     $this->in = new ZMQSocket ($context, ZMQ: :SOCKET_PULL) ;
    16.     $this->in->bind ($in_addr) ;
    17.  
    18.     $this->out = new ZMQSocket ($context, ZMQ: :SOCKET_PUSH) ;
    19.     $this->out->connect ($out_addr) ;
    20.   }
    21.  
    22.   public function work () {
    23.     while ($command = $this->in->recvMulti ()) {
    24.       if (isset ($this->commands [$command [0]])) {
    25.         echo "Received work" . PHP_EOL ;
    26.  
    27.         $callback = $this->commands [$command [0]] ;
    28.  
    29.         array_shift ($command) ;
    30.         $response = call_user_func_array ($callback, $command) ;
    31.  
    32.         if (is_array ($response))
    33.           $this->out->sendMulti ($response) ;
    34.         else
    35.           $this->out->send ($response) ;
    36.       }
    37.       else {
    38.         error_log ("There is no registered worker for $command [0]") ;
    39.       }
    40.     }
    41.   }
    42.  
    43.   public function register ($command, $callback)
    44.   {
    45.     $this->commands [$command] = $callback ;
    46.   }
    47. }
    48.  ?>

    The Worker class allows us to register commands with callbacks associated with them. In our case the Worker class doesn’t actually care or know about the parameters being passed to the actual callback, it just blindly passes them on. We are using two separate sockets in this example, one for incoming work requests and one for passing the results onwards. This allows us to create a simple pipeline by adding more workers in the mix. For example we could first have a watermark worker, which takes the original image and composites a watermark on it, passes the file onwards to thumbnail worker, which then creates different sizes of thumbnails and passes the final results to event collector.

    The next part we are going to create a is a simple worker script that does the actual thumbnailing of the images :

    1. < ?php
    2. include __DIR__ . ’/common.php’ ;
    3.  
    4. // Create worker class and bind the inbound address to ’THUMBNAIL_ADDR’ and connect outbound to ’COLLECTOR_ADDR’
    5. $worker = new Worker (THUMBNAIL_ADDR, COLLECTOR_ADDR) ;
    6.  
    7. // Register our thumbnail callback, nothing special here
    8. $worker->register (’thumbnail’, function ($filename, $width, $height) {
    9.                   $info = pathinfo ($filename) ;
    10.  
    11.                   $out = sprintf ("%s/%s_%dx%d.%s",
    12.                           $info [’dirname’],
    13.                           $info [’filename’],
    14.                           $width,
    15.                           $height,
    16.                           $info [’extension’]) ;
    17.  
    18.                   $status = 1 ;
    19.                   $message = ’’ ;
    20.  
    21.                   try {
    22.                     $im = new Imagick ($filename) ;
    23.                     $im->thumbnailImage ($width, $height) ;
    24.                     $im->writeImage ($out) ;
    25.                   }
    26.                   catch (Exception $e) {
    27.                     $status = 0 ;
    28.                     $message = $e->getMessage () ;
    29.                   }
    30.  
    31.                   return array (
    32.                         ’status’  => $status,
    33.                         ’filename’ => $filename,
    34.                         ’thumbnail’ => $out,
    35.                         ’message’ => $message,
    36.                     ) ;
    37.                 }) ;
    38.  
    39. // Run the worker, will block
    40. echo "Running thumbnail worker.." . PHP_EOL ;
    41. $worker->work () ;

    As you can see from the code the thumbnail worker registers a callback for ‘thumbnail’ command. The callback does the thumbnailing based on input and returns the status, original filename and the thumbnail filename. We have connected our Workers “outbound” socket to event collector, which will receive the results from the thumbnail worker and do something with them. What the “something” is depends on you. For example you could push the response into a websocket to show immediate feeedback to the user or store the results into a database.

    Our example event collector will just do a var_dump on every event it receives from the thumbnailer :

    1. < ?php
    2. include __DIR__ . ’/common.php’ ;
    3.  
    4. $socket = new ZMQSocket (new ZMQContext (), ZMQ: :SOCKET_PULL) ;
    5. $socket->bind (COLLECTOR_ADDR) ;
    6.  
    7. echo "Waiting for events.." . PHP_EOL ;
    8. while (($message = $socket->recvMulti ())) {
    9.   var_dump ($message) ;
    10. }
    11.  ?>

    The final piece of the puzzle is the client that pumps messages into the pipeline. The client connects to the thumbnail worker, passes on filename and desired dimensions :

    1. < ?php
    2. include __DIR__ . ’/common.php’ ;
    3.  
    4. $socket = new ZMQSocket (new ZMQContext (), ZMQ: :SOCKET_PUSH) ;
    5. $socket->connect (THUMBNAIL_ADDR) ;
    6.  
    7. $socket->sendMulti (
    8.       array (
    9.         ’thumbnail’,
    10.         realpath (’./test.jpg’),
    11.         50,
    12.         50,
    13.       )
    14. ) ;
    15. echo "Sent request" . PHP_EOL ;
    16.  ?>

    After this our processing pipeline will look like this :

    simple-pipeline

    Now, if we notice that thumbnail workers or the event collectors can’t keep up with the rate of images we are pushing through we can start scaling the pipeline by adding more processes on each layer. ZeroMQ PUSH socket will automatically round-robin between all connected nodes, which makes adding more workers and event collectors simple. After adding more workers our pipeline will look like this :

    scaling-pipeline

    Using ZeroMQ also allows us to create more flexible architectures by adding forwarding devices in the middle, adding request-reply workers etc. So, the last thing to do is to run our pipeline and see the results :

    Let’s create our test image first :

    $ convert magick:rose test.jpg
    

    From the command-line run the thumbnail script :

    $ php thumbnail.php 
    Running thumbnail worker..
    

    In a separate terminal window run the event collector :

    $ php collector.php 
    Waiting for events..
    

    And finally run the client to send the thumbnail request :

    $ php client.php 
    Sent request
    $
    

    If everything went according to the plan you should now see the following output in the event collector window :

    array(4) 
      [0]=>
      string(1) "1"
      [1]=>
      string(56) "/test.jpg"
      [2]=>
      string(62) "/test_50x50.jpg"
      [3]=>
      string(0) ""
    
    

    Happy hacking !

  • Is there a set of working P/Invoke declarations for FFMpeg, libavutil, libavformat and libavcodec in .NET ?

    30 août 2011, par casperOne

    I'm currently looking to access libavutil, libavformat and libavcodec (all part of FFMpeg) from .NET.

    Currently, I'm getting the libraries from the automated builds of the shared FFMpeg package performed every night for Windows 32-bit.

    I am also using the code from the ffmpeg-sharp project. In that project, I have removed a number of classes that were not compiling (they are wrapper classes not the P/Invoke declarations).

    The code compiles fine, but I am running into a few issues.

    First, it appears that the build of av*.dll uses the cdecl calling convention, as I was receiving a number of PInvokeStackImbalanceException when trying to call av_open_input_file. This was easy enough to change to get it to work right. The AVFormatContext structure is populated.

    After that, I want to call av_find_stream_info to get information about the streams in the file. However, when calling that with the AVFormatContext retrieved from the call to av_open_input_file, an AccessViolationException is thrown indicating that I am trying to read or write from protected memory.

    Has anyone used P/Invoke to access the libavutil, libavformat and libavcodec dll libraries through P/Invoke and have gotten it to work ?

    I should mention that working with the command-line version of FFMpeg, while a solution, is not a viable solution in this case, access needs to occur through the libraries. The reason for this is that I'd have to thrash the disk way too much to do what I need to do (I have to do a frame-by-frame analysis of some very high definition video) and I want to avoid the disk as much as possible.

  • AWS lambda mp4 thumbnail generator using ffmpeg - incorrect format generated

    10 avril 2021, par sam bhandu

    I am trying to create a thumbnail generator for every mp4 file uploaded to the s3 bucket. I have been following this post published by AWS. The code works fine for the transcoding video file. I changed the code to generate a thumbnail. The code does generate a file but it is an invalid image type.

    &#xA;

    import json&#xA;import os&#xA;import subprocess&#xA;import shlex&#xA;import boto3&#xA;import uuid&#xA;&#xA;S3_DESTINATION_BUCKET = "example-bucket"&#xA;SIGNED_URL_TIMEOUT = 60&#xA;&#xA;def lambda_handler(event, context):&#xA;&#xA;    # s3_source_bucket = event[&#x27;Records&#x27;][0][&#x27;s3&#x27;][&#x27;bucket&#x27;][&#x27;name&#x27;]&#xA;    # s3_source_key = event[&#x27;Records&#x27;][0][&#x27;s3&#x27;][&#x27;object&#x27;][&#x27;key&#x27;]&#xA;    # s3_source_basename = os.path.splitext(os.path.basename(s3_source_key))[0]&#xA;    # s3_destination_filename = s3_source_basename &#x2B; "_cfr.ts"&#xA;    &#xA;    hex_c = uuid.uuid4()&#xA;    s3_destination_filename = &#x27;/{}/{}.{}&#x27;.format(&#x27;tmp&#x27;,hex_c, &#x27;jpg&#x27;)&#xA;    s3_client = boto3.client(&#x27;s3&#x27;)&#xA;    s3_media_url = &#x27;https://s3-us-west-2.amazonaws.com/example-bucket/videos/presentations/testing.mp4&#x27;&#xA;    ffmpeg_cmd = "/opt/bin/ffmpeg -i \"" &#x2B; s3_media_url &#x2B; "\" -ss 00:00:02 -vframes 1  \"" &#x2B; s3_destination_filename &#x2B; "\""&#xA;    # ffmpeg_cmd = "/opt/bin/ffmpeg -i \"" &#x2B; s3_source_signed_url &#x2B; "\" -f mpegts -c:v copy -af aresample=async=1:first_pts=0 -"&#xA;    &#xA;    command1 = shlex.split(ffmpeg_cmd)&#xA;    p1 = subprocess.run(command1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)&#xA;   &#xA;    resp = s3_client.put_object(Body=s3_destination_filename, Bucket=S3_DESTINATION_BUCKET, Key=&#x27;{}{}&#x27;.format(hex_c, &#x27;.jpg&#x27;))&#xA;    return {&#xA;        &#x27;statusCode&#x27;: 200,&#xA;        &#x27;body&#x27;: json.dumps(&#x27;Processing complete successfully&#x27;)&#xA;    }&#xA;

    &#xA;

    Output is as :

    &#xA;

    {&#xA;  "statusCode": 200,&#xA;  "body": "\"Processing complete successfully\""&#xA;}&#xA;&#xA;Function Logs&#xA;START RequestId: b73aaacc-5da5-417a-9f98-5def438dee96 Version: $LATEST&#xA;ffmpeg version 4.1.3-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2019 the FFmpeg developers&#xA;  built with gcc 6.3.0 (Debian 6.3.0-18&#x2B;deb9u1) 20170516&#xA;  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzvbi --enable-libzimg&#xA;  libavutil      56. 22.100 / 56. 22.100&#xA;  libavcodec     58. 35.100 / 58. 35.100&#xA;  libavformat    58. 20.100 / 58. 20.100&#xA;  libavdevice    58.  5.100 / 58.  5.100&#xA;  libavfilter     7. 40.101 /  7. 40.101&#xA;  libswscale      5.  3.100 /  5.  3.100&#xA;  libswresample   3.  3.100 /  3.  3.100&#xA;  libpostproc    55.  3.100 / 55.  3.100&#xA;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;https://s3-us-west-2.amazonaws.com/example-bucket/videos/presentations/testing.mp4&#x27;:&#xA;  Metadata:&#xA;    major_brand     : isom&#xA;    minor_version   : 1&#xA;    compatible_brands: isomavc1mp42&#xA;    creation_time   : 2020-04-17T18:31:33.000000Z&#xA;  Duration: 00:00:33.07, start: 0.000000, bitrate: 90 kb/s&#xA;    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 854x480 [SAR 1:1 DAR 427:240], 23 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc (default)&#xA;    Metadata:&#xA;      creation_time   : 2020-04-17T18:31:29.000000Z&#xA;    Stream #0:1(eng): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 64 kb/s (default)&#xA;    Metadata:&#xA;      creation_time   : 2020-04-17T18:31:29.000000Z&#xA;Stream mapping:&#xA;  Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))&#xA;Press [q] to stop, [?] for help&#xA;[swscaler @ 0x67ddc40] deprecated pixel format used, make sure you did set range correctly&#xA;Output #0, image2, to &#x27;/tmp/4633bb13-4a15-49b7-a445-d910bebaddf6.jpg&#x27;:&#xA;  Metadata:&#xA;    major_brand     : isom&#xA;    minor_version   : 1&#xA;    compatible_brands: isomavc1mp42&#xA;    encoder         : Lavf58.20.100&#xA;    Stream #0:0(und): Video: mjpeg, yuvj420p(pc), 854x480 [SAR 1:1 DAR 427:240], q=2-31, 200 kb/s, 30 fps, 30 tbn, 30 tbc (default)&#xA;    Metadata:&#xA;      creation_time   : 2020-04-17T18:31:29.000000Z&#xA;      encoder         : Lavc58.35.100 mjpeg&#xA;    Side data:&#xA;      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1&#xA;frame=    0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed=   0x    &#xA;frame=    0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed=   0x    &#xA;frame=    0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed=   0x    &#xA;frame=    1 fps=0.4 q=6.3 Lsize=N/A time=00:00:00.03 bitrate=N/A speed=0.0149x    &#xA;video:14kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown&#xA;END RequestId: b73aaacc-5da5-417a-9f98-5def438dee96&#xA;REPORT RequestId: b73aaacc-5da5-417a-9f98-5def438dee96  Duration: 6349.25 ms    Billed Duration: 6350 ms    Memory Size: 155 MB Max Memory Used: 123 MB Init Duration: 368.12 ms&#xA;&#xA;Request ID&#xA;b73aaacc-5da5-417a-9f98-5def438dee96&#xA;

    &#xA;

    An image file is uploaded to the S3 folder, but when I try to open it flags an invalid file format. The file size is only 40.0 Bytes.&#xA;S3 bucket image folder&#xA;invalid file format

    &#xA;