Recherche avancée

Médias (91)

Autres articles (10)

  • Encoding and processing into web-friendly formats

    13 avril 2011, par

    MediaSPIP automatically converts uploaded files to internet-compatible formats.
    Video files are encoded in MP4, Ogv and WebM (supported by HTML5) and MP4 (supported by Flash).
    Audio files are encoded in MP3 and Ogg (supported by HTML5) and MP3 (supported by Flash).
    Where possible, text is analyzed in order to retrieve the data needed for search engine detection, and then exported as a series of image files.
    All uploaded files are stored online in their original format, so you can (...)

  • Contribute to documentation

    13 avril 2011

    Documentation is vital to the development of improved technical capabilities.
    MediaSPIP welcomes documentation by users as well as developers - including : critique of existing features and functions articles contributed by developers, administrators, content producers and editors screenshots to illustrate the above translations of existing documentation into other languages
    To contribute, register to the project users’ mailing (...)

  • Other interesting software

    13 avril 2011, par

    We don’t claim to be the only ones doing what we do ... and especially not to assert claims to be the best either ... What we do, we just try to do it well and getting better ...
    The following list represents softwares that tend to be more or less as MediaSPIP or that MediaSPIP tries more or less to do the same, whatever ...
    We don’t know them, we didn’t try them, but you can take a peek.
    Videopress
    Website : http://videopress.com/
    License : GNU/GPL v2
    Source code : (...)

Sur d’autres sites (3322)

  • Anomalie #4198 : Le W3C ne valide pas les atttribut width et height qui ne sont pas des entiers.

    21 mai 2019, par b b

    Ok vu, je pense qu’on doit pouvoir fixer ça dans _image_tag_changer_taille() avec le patch suivant :

    1. <span class="CodeRay"><span class="line comment">diff --git a/ecrire/inc/filtres_images_lib_mini.php b/ecrire/inc/filtres_images_lib_mini.php</span>
    2. <span class="line comment">index d93acc1..37e5c72 100644</span>
    3. <span class="line head"><span class="head">--- </span><span class="filename">a/ecrire/inc/filtres_images_lib_mini.php</span></span>
    4. <span class="line head"><span class="head">+++ </span><span class="filename">b/ecrire/inc/filtres_images_lib_mini.php</span></span>
    5. <span class="change"><span class="change">@@</span> -861,8 +861,8 <span class="change">@@</span></span> <span class="keyword">function</span> <span class="function">_image_tag_changer_taille</span>(<span class="local-variable">$tag</span>, <span class="local-variable">$width</span>, <span class="local-variable">$height</span>, <span class="local-variable">$style</span> = <span class="predefined-constant">false</span>) {
    6.      <span class="comment">// ca accelere le rendu du navigateur</span>
    7.      <span class="comment">// ca permet aux navigateurs de reserver la bonne taille </span>
    8.      <span class="comment">// quand on a desactive l'affichage des images.</span>
    9. <span class="line delete"><span class="delete">-</span>    <span class="local-variable">$tag</span> = inserer_attribut(<span class="local-variable">$tag</span>, <span class="string"><span class="delimiter">'</span><span class="content">width</span><span class="delimiter">'</span></span>, <span class="eyecatcher"><span class="local-variable">$width</span></span>);</span>
    10. <span class="line delete"><span class="delete">-</span>    <span class="local-variable">$tag</span> = inserer_attribut(<span class="local-variable">$tag</span>, <span class="string"><span class="delimiter">'</span><span class="content">height</span><span class="delimiter">'</span></span>, <span class="eyecatcher"><span class="local-variable">$height</span></span>);</span>
    11. <span class="line insert"><span class="insert">+</span>    <span class="local-variable">$tag</span> = inserer_attribut(<span class="local-variable">$tag</span>, <span class="string"><span class="delimiter">'</span><span class="content">width</span><span class="delimiter">'</span></span>, <span class="eyecatcher"><span class="predefined">round</span>(<span class="local-variable">$width</span>)</span>);</span>
    12. <span class="line insert"><span class="insert">+</span>    <span class="local-variable">$tag</span> = inserer_attribut(<span class="local-variable">$tag</span>, <span class="string"><span class="delimiter">'</span><span class="content">height</span><span class="delimiter">'</span></span>, <span class="eyecatcher"><span class="predefined">round</span>(<span class="local-variable">$height</span>)</span>);</span>
    13.  
    14.      <span class="comment">// attributs deprecies. Transformer en CSS</span>
    15.      <span class="keyword">if</span> (<span class="local-variable">$espace</span> = extraire_attribut(<span class="local-variable">$tag</span>, <span class="string"><span class="delimiter">'</span><span class="content">hspace</span><span class="delimiter">'</span></span>)) {
    16.  
    17. </span>

    Télécharger

    Attendons d’autres avis avant de l’appliquer.

  • PHP FFmpeg video aspect ratio problem [SOLVED]

    29 août 2011, par Herr Kaleun

    i compiled the new version of FFMPEG and the padding commands have been deprecated.
    As i try to get familiar with the new -vf pad= commands, i want to ask, how can i
    convert a video without changing it's aspect ratio.

    I've checked numerous solutions from stackoverflow, nothing seemed to work.
    Can someone, please post a working PHP example or cmd line. I would be VERY happy.

    Please note that the videos in question, could be 4:3 and also be 16:9

    Let's say, i convert a 16:9 video to 640x480 format. It will need some bars at
    the top and at the bottom. That is what i want to do.

    Thanks

    EDIT :
    I solved the problem on my own. The FFmpeg documentation is a little bit weird so
    you have to experiment yourself a little bit.
    The padding formula is like :

       $pad_horizontal = $target_width     + $pad_left + $pad_right;
       $pad_vertical   = $target_height;
       // blah
       $command .= " -vf pad=$pad_horizontal:$pad_vertical:". $pad_left .":". $pad_top  .":black";

    Pay special attention at the $pad_vertical part since the paddings there are better
    not added so that the padding calculation of ffmpeg is not broken.

    Here is the full source code to the demo

    &lt;?

       /***********************************************************************************
       get_dimensions()

       Takes in a set of video dimensions - original and target - and returns the optimal conversion
       dimensions.  It will always return the smaller of the original or target dimensions.
       For example: original dimensions of 320x240 and target dimensions of 640x480.
       The result will be 320x240 because converting to 640x480 would be a waste of disk
       space, processing, and bandwidth (assuming these videos are to be downloaded).

       @param $original_width:     The actual width of the original video file which is to be converted.
       @param $original_height:    The actual height of the original video file which is to be converted.
       @param $target_width:       The width of the video file which we will be converting to.
       @param $target_height:      The height of the video file which we will be converting to.
       @param $force_aspect:       Boolean value of whether or not to force conversion to the target&#39;s
                             aspect ratio using padding (so the video isn&#39;t stretched).  If false, the
                             conversion dimensions will retain the aspect ratio of the original.
                             Optional parameter.  Defaults to true.
       @return: An array containing the size and padding information to be used for conversion.
                   Format:
                   Array
                   (
                       [width] => int
                       [height] => int
                       [padtop] => int // top padding (if applicable)
                       [padbottom] => int // bottom padding (if applicable)
                       [padleft] => int // left padding (if applicable)
                       [padright] => int // right padding (if applicable)
                   )
       ***********************************************************************************/
       function get_dimensions($original_width,$original_height,$target_width,$target_height,$force_aspect)
       {
           if(!isset($force_aspect))
           {
               $force_aspect = true;
           }
           // Array to be returned by this function
           $target = array();
           $target[&#39;padleft&#39;] = 0;
           $target[&#39;padright&#39;] = 0;
           $target[&#39;padbottom&#39;] = 0;
           $target[&#39;padtop&#39;] = 0;



           // Target aspect ratio (width / height)
           $aspect = $target_width / $target_height;
           // Target reciprocal aspect ratio (height / width)
           $raspect = $target_height / $target_width;

           if($original_width/$original_height !== $aspect)
           {
               // Aspect ratio is different
               if($original_width/$original_height > $aspect)
               {
                   // Width is the greater of the two dimensions relative to the target dimensions
                   if($original_width &lt; $target_width)
                   {
                       // Original video is smaller.  Scale down dimensions for conversion
                       $target_width = $original_width;
                       $target_height = round($raspect * $target_width);
                   }
                   // Calculate height from width
                   $original_height = round($original_height / $original_width * $target_width);
                   $original_width = $target_width;
                   if($force_aspect)
                   {
                       // Pad top and bottom
                       $dif = round(($target_height - $original_height) / 2);
                       $target[&#39;padtop&#39;] = $dif;
                       $target[&#39;padbottom&#39;] = $dif;
                   }
               }
               else
               {
                   // Height is the greater of the two dimensions relative to the target dimensions
                   if($original_height &lt; $target_height)
                   {
                       // Original video is smaller.  Scale down dimensions for conversion
                       $target_height = $original_height;
                       $target_width = round($aspect * $target_height);
                   }
                   //Calculate width from height
                   $original_width = round($original_width / $original_height * $target_height);
                   $original_height = $target_height;
                   if($force_aspect)
                   {
                       // Pad left and right
                       $dif = round(($target_width - $original_width) / 2);
                       $target[&#39;padleft&#39;] = $dif;
                       $target[&#39;padright&#39;] = $dif;
                   }
               }
           }
           else
           {
               // The aspect ratio is the same
               if($original_width !== $target_width)
               {
                   if($original_width &lt; $target_width)
                   {
                       // The original video is smaller.  Use its resolution for conversion
                       $target_width = $original_width;
                       $target_height = $original_height;
                   }
                   else
                   {
                       // The original video is larger,  Use the target dimensions for conversion
                       $original_width = $target_width;
                       $original_height = $target_height;
                   }
               }
           }
           if($force_aspect)
           {
               // Use the target_ vars because they contain dimensions relative to the target aspect ratio
               $target[&#39;width&#39;] = $target_width;
               $target[&#39;height&#39;] = $target_height;
           }
           else
           {
               // Use the original_ vars because they contain dimensions relative to the original&#39;s aspect ratio
               $target[&#39;width&#39;] = $original_width;
               $target[&#39;height&#39;] = $original_height;
           }
           return $target;
       }

       function get_vid_dim($file)
       {
           $command = &#39;/usr/bin/ffmpeg -i &#39; . escapeshellarg($file) . &#39; 2>&amp;1&#39;;
           $dimensions = array();
           exec($command,$output,$status);
           if (!preg_match(&#39;/Stream #(?:[0-9\.]+)(?:.*)\: Video: (?P<videocodec>.*) (?P<width>[0-9]*)x(?P<height>[0-9]*)/&#39;,implode("\n",$output),$matches))
           {
               preg_match(&#39;/Could not find codec parameters \(Video: (?P<videocodec>.*) (?P<width>[0-9]*)x(?P<height>[0-9]*)\)/&#39;,implode("\n",$output),$matches);
           }
           if(!empty($matches[&#39;width&#39;]) &amp;&amp; !empty($matches[&#39;height&#39;]))
           {
               $dimensions[&#39;width&#39;] = $matches[&#39;width&#39;];
               $dimensions[&#39;height&#39;] = $matches[&#39;height&#39;];
           }
           return $dimensions;
       }


       $command    = &#39;/usr/bin/ffmpeg -i &#39; . $src . &#39; -ab 96k -b 700k -ar 44100 -f flv -s &#39; . &#39;640x480 -acodec mp3 &#39;. $video_output_dir . $video_filename . &#39; 2>&amp;1&#39;;


       define( &#39;VIDEO_WIDTH&#39;,      &#39;640&#39; );
       define( &#39;VIDEO_HEIGHT&#39;,     &#39;480&#39; );

       $src_1              = getcwd() .&#39;/&#39;. &#39;test_video1.mpeg&#39;;
       $video_filename1    = &#39;video1.flv&#39;;

       $src_2              = getcwd() .&#39;/&#39;. &#39;test_video2.mp4&#39;;
       $video_filename2    = &#39;video2.flv&#39;;

       $src_3              = getcwd() .&#39;/&#39;. &#39;test_video3.mp4&#39;;
       $video_filename3    = &#39;video3.flv&#39;;

       convert_video( $src_1, $video_filename1 );
       convert_video( $src_2, $video_filename2 );
       convert_video( $src_3, $video_filename3 );

       function convert_video( $src = &#39;&#39;, $video_filename = &#39;&#39; )
       {

           $video_output_dir   = getcwd() .&#39;/&#39;;

           @unlink ( $video_output_dir . $video_filename );

           $original   = get_vid_dim($src);
           $target     = get_dimensions( $original[&#39;width&#39;], $original[&#39;height&#39;], VIDEO_WIDTH, VIDEO_HEIGHT, TRUE );

           echo &#39;<pre>&#39;;
           print_r( $original );
           echo &#39;</pre>&#39;;
           echo &#39;<pre>&#39;;
           print_r( $target );
           echo &#39;</pre>&#39;;



           $target_width   = $target[&#39;width&#39;];
           $target_height  = $target[&#39;height&#39;];

           $pad_left       = $target[&#39;padleft&#39;];
           $pad_right      = $target[&#39;padright&#39;];
           $pad_bottom     = $target[&#39;padbottom&#39;];
           $pad_top        = $target[&#39;padtop&#39;];

           $pad_horizontal = $target_width     + $pad_left + $pad_right;
           $pad_vertical   = $target_height; //    + $pad_top + $pad_bottom;


           $command = &#39;/usr/bin/ffmpeg -i &#39; . $src;

           // $command .= " -s {$target_width}x{$target_height} ";

           $command .= " -vf pad=$pad_horizontal:$pad_vertical:". $pad_left .":". $pad_top  .":black";

           $command .= &#39; -ab 96k -b 700k -ar 44100&#39;;
           $command .= &#39; -f flv &#39;;
           $command .= &#39; -qscale 4&#39;;

           $command .= &#39; -ss 30&#39;;
           $command .= &#39; -t 5&#39;;

           $command .= &#39; -ac 2 -ab 128k -qscale 5 &#39;;
           $command .= &#39; &#39; . $video_output_dir . $video_filename;


           exec( $command, $output, $status );

           echo &#39;<pre>&#39;;
           print_r( $command );
           echo &#39;</pre>&#39;;

           if ( $status == 0 )
           {
               echo &#39;<br />Convert OK. <br />&#39;;
           }
           else
           {
               echo &#39;<pre>&#39;;
               print_r( $output );
               echo &#39;</pre>&#39;;
           }

           echo &#39;<br />&#39;;
           echo &#39;<br />&#39;;

       }





    ?>
    </height></width></videocodec></height></width></videocodec>

    Thank you and have fun :)

  • Python cv2 script that scans a giant image to a video. Why do I need pad two extra lines

    27 avril 2022, par Mahrarena

    I wrote a script that scans a giant image to make a video. Normally I just post my scripts straight to my Code Review account, but this script is ugly, needs to be refactored, implements only horizontal scrolling and most importantly I just fixed a bug but I don't completely understand why it works.

    &#xA;

    Example :

    &#xA;

    Original image (Google Drive)

    &#xA;

    Video Output (Google Drive)

    &#xA;

    As you can see from the video, everything is working properly except the fact that I don't know how it works.

    &#xA;

    Full working code

    &#xA;


    &#xA;
    import cv2&#xA;import numpy as np&#xA;import random&#xA;import rpack&#xA;from fractions import Fraction&#xA;from math import prod&#xA;&#xA;def resize_guide(image_size, target_area):&#xA;    aspect_ratio = Fraction(*image_size).limit_denominator()&#xA;    horizontal = aspect_ratio.numerator&#xA;    vertical = aspect_ratio.denominator&#xA;    unit_length = (target_area/(horizontal*vertical))**.5&#xA;    return (int(horizontal*unit_length), int(vertical*unit_length))&#xA;&#xA;fourcc = cv2.VideoWriter_fourcc(*&#x27;mp4v&#x27;)&#xA;FRAME = np.zeros((1080, 1920, 3), dtype=np.uint8)&#xA;&#xA;def new_frame():&#xA;    return np.ndarray.copy(FRAME)&#xA;&#xA;def center(image):&#xA;    frame = new_frame()&#xA;    h, w = image.shape[:2]&#xA;    yoff = round((1080-h)/2)&#xA;    xoff = round((1920-w)/2)&#xA;    frame[yoff:yoff&#x2B;h, xoff:xoff&#x2B;w] = image&#xA;    return frame&#xA;&#xA;def image_scanning(file, fps=60, pan_increment=64, horizontal_increment=8):&#xA;    image = cv2.imread(file)&#xA;    height, width = image.shape[:2]&#xA;    assert width*height >= 1920*1080&#xA;    video_writer = cv2.VideoWriter(file&#x2B;&#x27;.mp4&#x27;, fourcc, fps, (1920, 1080))&#xA;    fit_height = True&#xA;    if height &lt; 1080:&#xA;        width = width*1080/height&#xA;        image = cv2.resize(image, (width, 1080), interpolation = cv2.INTER_AREA)&#xA;    aspect_ratio = width / height&#xA;    zooming_needed = False&#xA;    if 4/9 &lt;= aspect_ratio &lt;= 16/9:&#xA;        new_width = round(width*1080/height)&#xA;        fit = cv2.resize(image, (new_width, 1080), interpolation = cv2.INTER_AREA)&#xA;        zooming_needed = True&#xA;    &#xA;    elif 16/9 &lt; aspect_ratio &lt;= 32/9:&#xA;        new_height = round(height*1920/width)&#xA;        fit = cv2.resize(image, (1920, new_height), interpolation = cv2.INTER_AREA)&#xA;        fit_height = False&#xA;        zooming_needed = True&#xA;    &#xA;    centered = center(fit)&#xA;    for i in range(fps):&#xA;        video_writer.write(centered)&#xA;    if fit_height:&#xA;        xoff = round((1920 - new_width)/2)&#xA;        while xoff:&#xA;            if xoff - pan_increment >= 0:&#xA;                xoff -= pan_increment&#xA;            else:&#xA;                xoff = 0&#xA;            frame = new_frame()&#xA;            frame[0:1080, xoff:xoff&#x2B;new_width] = fit&#xA;            video_writer.write(frame)&#xA;    else:&#xA;        yoff = round((1080 - new_height)/2)&#xA;        while yoff:&#xA;            if yoff - pan_increment >= 0:&#xA;                yoff -= pan_increment&#xA;            else:&#xA;                yoff = 0&#xA;            frame = new_frame()&#xA;            frame[yoff:yoff&#x2B;new_height, 0:1920] = fit&#xA;            video_writer.write(frame)&#xA;    &#xA;    if zooming_needed:&#xA;        if fit_height:&#xA;            width_1, height_1 = new_width, 1080&#xA;        else:&#xA;            width_1, height_1 = 1920, new_height&#xA;        new_area = width_1 * height_1&#xA;        original_area = width * height&#xA;        area_diff = original_area - new_area&#xA;        unit_diff = area_diff / fps&#xA;        for i in range(1, fps&#x2B;1):&#xA;            zoomed = cv2.resize(image, resize_guide((width_1, height_1), new_area&#x2B;unit_diff*i), interpolation=cv2.INTER_AREA)&#xA;            zheight, zwidth = zoomed.shape[:2]&#xA;            zheight = min(zheight, 1080)&#xA;            zwidth = min(zwidth, 1920)&#xA;            frame = new_frame()&#xA;            frame[0:zheight, 0:zwidth] = zoomed[0:zheight, 0:zwidth]&#xA;            video_writer.write(frame)&#xA;    &#xA;    if (width - 1920) % horizontal_increment:&#xA;        new_width = ((width - 1920) // horizontal_increment &#x2B; 1) * horizontal_increment &#x2B; 1920&#xA;        frame = np.zeros([height, new_width, 3], dtype=np.uint8)&#xA;        frame[0:height, 0:width] = image&#xA;        width = new_width&#xA;        image = frame&#xA;    &#xA;    if height % 1080:&#xA;        new_height = (height // 1080 &#x2B; 2) * 1080&#xA;        frame = np.zeros([new_height, width, 3], dtype=np.uint8)&#xA;        frame[0:height, 0:width] = image&#xA;        height = new_height - 1080&#xA;        image = frame&#xA;    &#xA;    y, x = 0, 0&#xA;    for y in range(0, height, 1080):&#xA;        for x in range(0, width-1920, horizontal_increment):&#xA;            frame = image[y:y&#x2B;1080, x:x&#x2B;1920]&#xA;            video_writer.write(frame)&#xA;        x = width - 1920&#xA;        frame = image[y:y&#x2B;1080, x:x&#x2B;1920]&#xA;        for i in range(round(fps/3)):&#xA;            video_writer.write(frame)&#xA;    cv2.destroyAllWindows()&#xA;    video_writer.release()&#xA;    del video_writer&#xA;

    &#xA;

    I don't know why I need to pad two extra lines instead of one, meaning if I change this :

    &#xA;

        if height % 1080:&#xA;        new_height = (height // 1080 &#x2B; 2) * 1080&#xA;        frame = np.zeros([new_height, width, 3], dtype=np.uint8)&#xA;        frame[0:height, 0:width] = image&#xA;        height = new_height - 1080&#xA;        image = frame&#xA;

    &#xA;

    To this :

    &#xA;

        if height % 1080:&#xA;        new_height = (height // 1080 &#x2B; 1) * 1080&#xA;        frame = np.zeros([new_height, width, 3], dtype=np.uint8)&#xA;        frame[0:height, 0:width] = image&#xA;        height = new_height&#xA;        image = frame&#xA;

    &#xA;

    The program raises exceptions :

    &#xA;

    OpenCV: FFMPEG: tag 0x34363268/&#x27;h264&#x27; is not supported with codec id 27 and format &#x27;mp4 / MP4 (MPEG-4 Part 14)&#x27;&#xA;OpenCV: FFMPEG: fallback to use tag 0x31637661/&#x27;avc1&#x27;&#xA;---------------------------------------------------------------------------&#xA;error                                     Traceback (most recent call last)&#xA; in <module>&#xA;----> 1 image_scanning("D:/collages/91f53ebcea2a.png")&#xA;&#xA; in image_scanning(file, fps, pan_increment, horizontal_increment, fast_decrement)&#xA;    122                     x &#x2B;= horizontal_increment&#xA;    123                     frame = image[y:y&#x2B;1080, x:x&#x2B;1920]&#xA;--> 124                     video_writer.write(frame)&#xA;    125     cv2.destroyAllWindows()&#xA;    126     video_writer.release()&#xA;&#xA;error: Unknown C&#x2B;&#x2B; exception from OpenCV code&#xA;</module>

    &#xA;

    I guess it was caused by indexing error because the last line would not have enough pixels so padding the height of the image to a multiple of 1080 should work.

    &#xA;

    But that's not the case, I need to pad two lines, why is that ? I really don't understand why it is working.

    &#xA;


    &#xA;

    No, I really wrote all of it, I understand all the principles, the ideas are all mine, but there is one small problem in implementation. I don't know why I need extra pixels in the bottom to make it work, because if I don't pad the height to a multiple of 1080, I can't get the bottom line, the lowest potion of height % 1080 would be lost.

    &#xA;

    If I tried to get the lowest part, the program will raise exceptions even if I pad the height to a multiple of 1080, I think it is related to indexing but I don't fully understand it, turns out I need to pad the height and add extra pixels, even 1 pixel would work.

    &#xA;

    I don't know why it raises exceptions and how add extra pixels got rid of the exception, but I understand everything else perfectly clear, after all I wrote it.

    &#xA;

    There's a bug in my program, I don't know what caused it, and I want you to help me debugging, and that's the entire point of the question !

    &#xA;