Recherche avancée

Médias (0)

Mot : - Tags -/gis

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

Autres articles (60)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • Creating farms of unique websites

    13 avril 2011, par

    MediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
    This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)

  • 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

Sur d’autres sites (11089)

  • Slicing an AVI file

    7 novembre 2014, par Peter Lur

    I am trying to upload only a certain part of an AVI file on the server without having to upload the whole file first.

    If I set the slice to the beginning (byte : 0), I can read the resulting file no problem even if I slice it in any size. However if the slice start anywhere but not at byte 0, the file become unreadable. I guess this has something to do with the avi header/index being messed up. I was wondering maybe I could use ffmpeg to move the header or something ?

    HTML Source

       
           
           <code class="echappe-js">&lt;script type=&quot;text/javascript&quot;&gt;<br />
    <br />
               window.BlobBuilder = window.MozBlobBuilder || window.WebKitBlobBuilder || window.BlobBuilder;<br />
    <br />
               function sendRequest() {<br />
                   var blob = document.getElementById('fileToUpload').files[0];<br />
    <br />
    <br />
                   //Slicing parameters<br />
    <br />
    <br />
                   //#1: Starting at byte:0 = WORKING WELL<br />
                   var start = 0;<br />
                   var end = 1048576;  // 1MB chunk sizes.<br />
    <br />
    <br />
                   //#2: Slicing the video file somewhere else (FAIL)<br />
    <br />
                   /*<br />
                   var start = 1048576*3;<br />
                   var end = 1048576*4;<br />
                   */<br />
    <br />
    <br />
                   var chunk = blob.slice(start, end, 'video/avi');<br />
                   uploadFile(chunk);<br />
    <br />
               }<br />
    <br />
               function fileSelected() {<br />
                   var file = document.getElementById('fileToUpload').files[0];<br />
                   if (file) {<br />
                       var fileSize = 0;<br />
                       if (file.size &gt; 1024 * 1024)<br />
                           fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';<br />
                       else<br />
                           fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';<br />
    <br />
                       document.getElementById('fileName').innerHTML = 'Name: ' + file.name;<br />
                       document.getElementById('fileSize').innerHTML = 'Size: ' + fileSize;<br />
                       document.getElementById('fileType').innerHTML = 'Type: ' + file.type;<br />
                   }<br />
               }<br />
    <br />
               function uploadFile(blobFile) {<br />
                   //var file = document.getElementById('fileToUpload').files[0];  <br />
                   var fd = new FormData();<br />
                   fd.append(&quot;fileToUpload&quot;, blobFile);<br />
    <br />
                   var xhr = new XMLHttpRequest();<br />
                   xhr.upload.addEventListener(&quot;progress&quot;, uploadProgress, false);<br />
                   xhr.addEventListener(&quot;load&quot;, uploadComplete, false);<br />
                   xhr.addEventListener(&quot;error&quot;, uploadFailed, false);<br />
                   xhr.addEventListener(&quot;abort&quot;, uploadCanceled, false);<br />
                   xhr.open(&quot;POST&quot;, &quot;upload.php&quot;);<br />
                   xhr.onload = function(e) {<br />
                     //alert(&quot;loaded!&quot;);<br />
                     };<br />
    <br />
                   xhr.send(fd);<br />
                   //alert(&quot;oen over&quot;);<br />
               }<br />
    <br />
               function uploadProgress(evt) {<br />
                   if (evt.lengthComputable) {<br />
                       var percentComplete = Math.round(evt.loaded * 100 / evt.total);<br />
                       document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%';<br />
                   }<br />
                   else {<br />
                       document.getElementById('progressNumber').innerHTML = 'unable to compute';<br />
                   }<br />
               }<br />
    <br />
               function uploadComplete(evt) {<br />
                   /* This event is raised when the server send back a response */<br />
                   //alert(evt.target.responseText);<br />
               }<br />
    <br />
               function uploadFailed(evt) {<br />
                   alert(&quot;There was an error attempting to upload the file.&quot;);<br />
               }<br />
    <br />
               function uploadCanceled(evt) {<br />
                   xhr.abort();<br />
                   xhr = null;<br />
                   //alert(&quot;The upload has been canceled by the user or the browser dropped the connection.&quot;);<br />
               }<br />
           &lt;/script&gt;

    PHP Source (upload.php)

    &lt;?php

    $tmp_name = $_FILES['fileToUpload']['tmp_name'];
    $size = $_FILES['fileToUpload']['size'];
    $name = $_FILES['fileToUpload']['name'];

    $target_file = basename($name);

    $complete = "complete.avi";
    $com = fopen($complete, "ab");

    // Open temp file
    $out = fopen($target_file, "wb");

    if ( $out ) {
       // Read binary input stream and append it to temp file
       $in = fopen($tmp_name, "rb");
       if ( $in ) {
           while ( $buff = fread( $in, 1048576 ) ) {
               fwrite($out, $buff);
               fwrite($com, $buff);
           }  
       }
       fclose($in);
       fclose($out);
    }
    fclose($com);

    ?>
  • How to reduce size of moov atom of H.264 movies to improve streaming start for smartphones ?

    12 mars 2023, par Andrey Lebedev

    We run a video service streaming movies to smartphones (iOS&Android).&#xA;We are encoding in H.264+AAC and using the mp4 container.&#xA;We have a problem that long movies (60 minutes+) take a very long time to&#xA;start playing and have tracked this down to the large size of moov&#xA;atom for these movies.&#xA;For 110 minute movies the atom is as large as 4.2Mb which obviously takes a long&#xA;time to download to a smart-phone over 3G !

    &#xA;&#xA;

    Is there anyway to make the moov atom smaller ? We can reduce it bit&#xA;by dropping the audio sampling rate, but obviously anything below 22kHz&#xA;would not really be acceptable.

    &#xA;&#xA;

    We are using ffmpeg as the encoder, and MP4Box to move the metadata&#xA;to the front of the file. Is there any way to get it to make&#xA;a smaller moov ? Any other encoders out there which make a smaller moov ?

    &#xA;&#xA;

    For example...

    &#xA;&#xA;

    Big size (280 Mb, 1h 49min) streamable mp4 (h.264, AAC) file have a big header size (4.2 Mb). File was encoded by two pass ffmpeg and MP4Box for replacing metadata into beginning of the file :

    &#xA;&#xA;

    /usr/bin/ffmpeg -i /var/lib/encoder/incoming/2388 -aspect 320:210 -threads 8 -vcodec libx264 -profile baseline -level 13 -flags &#x2B;loop&#x2B;mv4 -cmp 256 -partitions &#x2B;parti4x4&#x2B;parti8x8&#x2B;partp4x4&#x2B;partp8x8&#x2B;partb8x8 -me_method hex -subq 7 -trellis 1 -refs 5 -bf 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -b:v 270k -maxrate 270k -bufsize 270k -g 30 -passlogfile /tmp/mediaservice/3100/video-IPH.ffmpeg -an -f rawvideo -pass 1 -y /dev/null&#xA;&#xA;/usr/bin/ffmpeg -i /var/lib/encoder/incoming/2388 -aspect 320:210 -threads 8 -vcodec libx264 -profile baseline -level 13 -flags &#x2B;loop&#x2B;mv4 -cmp 256 -partitions &#x2B;parti4x4&#x2B;parti8x8&#x2B;partp4x4&#x2B;partp8x8&#x2B;partb8x8 -me_method hex -subq 7 -trellis 1 -refs 5 -bf 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -b:v 270k -maxrate 270k -bufsize 270k -g 30 -passlogfile /tmp/mediaservice/3100/video-IPH.ffmpeg -acodec libfaac -ac 2 -b:a 32k -ar 44100 -f mp4 -pass 2 -y /var/lib/encoder/encoded/3100/video-IPH.mp4&#xA;&#xA;/usr/bin/MP4Box -quiet -tmp /tmp/mediaservice/3100/ -inter 500 /var/lib/encoder/encoded/3100/video-IPH.mp4&#xA;

    &#xA;&#xA;

    Media info (audio sample rate = 44100) :

    &#xA;&#xA;

    General&#xA;Count                                    : 278&#xA;Count of stream of this kind             : 1&#xA;Kind of stream                           : General&#xA;Kind of stream                           : General&#xA;Stream identifier                        : 0&#xA;Count of video streams                   : 1&#xA;Count of audio streams                   : 1&#xA;Video_Format_List                        : AVC&#xA;Video_Format_WithHint_List               : AVC&#xA;Codecs Video                             : AVC&#xA;Audio_Format_List                        : AAC&#xA;Audio_Format_WithHint_List               : AAC&#xA;Audio codecs                             : AAC LC&#xA;Complete name                            : 1348645218_970458_2465.iph.mp4&#xA;File name                                : 1348645218_970458_2465.iph.mp4&#xA;File extension                           : mp4&#xA;Format                                   : MPEG-4&#xA;Format                                   : MPEG-4&#xA;Format/Extensions usually used           : mp4 m4v m4a m4b m4p 3gpp 3gp 3gpp2 3g2 k3g jpm jpx mqv ismv isma f4v&#xA;Commercial name                          : MPEG-4&#xA;Format profile                           : Base Media&#xA;Internet media type                      : video/mp4&#xA;Codec ID                                 : isom&#xA;Codec ID/Url                             : http://www.apple.com/quicktime/download/standalone.html&#xA;Codec                                    : MPEG-4&#xA;Codec                                    : MPEG-4&#xA;Codec/Extensions usually used            : mp4 m4v m4a m4b m4p 3gpp 3gp 3gpp2 3g2 k3g jpm jpx mqv ismv isma f4v&#xA;File size                                : 272703970&#xA;File size                                : 260 MiB&#xA;File size                                : 260 MiB&#xA;File size                                : 260 MiB&#xA;File size                                : 260 MiB&#xA;File size                                : 260.1 MiB&#xA;Duration                                 : 6556027&#xA;Duration                                 : 1h 49mn&#xA;Duration                                 : 1h 49mn 16s 27ms&#xA;Duration                                 : 1h 49mn&#xA;Duration                                 : 01:49:16.027&#xA;Overall bit rate                         : 332767&#xA;Overall bit rate                         : 333 Kbps&#xA;Stream size                              : 4230761&#xA;Stream size                              : 4.03 MiB (2%)&#xA;Stream size                              : 4 MiB&#xA;Stream size                              : 4.0 MiB&#xA;Stream size                              : 4.03 MiB&#xA;Stream size                              : 4.035 MiB&#xA;Stream size                              : 4.03 MiB (2%)&#xA;Proportion of this stream                : 0.01551&#xA;HeaderSize                               : 4230683&#xA;DataSize                                 : 268473217&#xA;FooterSize                               : 70&#xA;IsStreamable                             : Yes&#xA;File last modification date              : UTC 2012-09-26 12:38:19&#xA;File last modification date (local)      : 2012-09-26 21:38:19&#xA;Writing application                      : Lavf54.6.100&#xA;&#xA;Video&#xA;Count                                    : 201&#xA;Count of stream of this kind             : 1&#xA;Kind of stream                           : Video&#xA;Kind of stream                           : Video&#xA;Stream identifier                        : 0&#xA;ID                                       : 1&#xA;ID                                       : 1&#xA;Format                                   : AVC&#xA;Format/Info                              : Advanced Video Codec&#xA;Format/Url                               : http://developers.videolan.org/x264.html&#xA;Commercial name                          : AVC&#xA;Format profile                           : Baseline@L1.3&#xA;Format settings                          : 5 Ref Frames&#xA;Format settings, CABAC                   : No&#xA;Format settings, CABAC                   : No&#xA;Format settings, ReFrames                : 5&#xA;Format settings, ReFrames                : 5 frames&#xA;Format settings, GOP                     : M=1, N=30&#xA;Internet media type                      : video/H264&#xA;Codec ID                                 : avc1&#xA;Codec ID/Info                            : Advanced Video Coding&#xA;Codec ID/Url                             : http://www.apple.com/quicktime/download/standalone.html&#xA;Codec                                    : AVC&#xA;Codec                                    : AVC&#xA;Codec/Family                             : AVC&#xA;Codec/Info                               : Advanced Video Codec&#xA;Codec/Url                                : http://developers.videolan.org/x264.html&#xA;Codec/CC                                 : avc1&#xA;Codec profile                            : Baseline@L1.3&#xA;Codec settings                           : 5 Ref Frames&#xA;Codec settings, CABAC                    : No&#xA;Codec_Settings_RefFrames                 : 5&#xA;Duration                                 : 6556017&#xA;Duration                                 : 01:49:16.017&#xA;Bit rate                                 : 270000&#xA;Bit rate                                 : 270 Kbps&#xA;Width                                    : 480&#xA;Width                                    : 480 pixels&#xA;Height                                   : 270&#xA;Height                                   : 270 pixels&#xA;Pixel aspect ratio                       : 1.000&#xA;Display aspect ratio                     : 1.778&#xA;Display aspect ratio                     : 16:9&#xA;Rotation                                 : 0.000&#xA;Frame rate mode                          : CFR&#xA;Frame rate mode                          : Constant&#xA;FrameRate_Mode_Original                  : VFR&#xA;Frame rate                               : 29.970&#xA;Frame rate                               : 29.970 fps&#xA;Frame count                              : 196484&#xA;Resolution                               : 8&#xA;Resolution                               : 8 bits&#xA;Colorimetry                              : 4:2:0&#xA;Color space                              : YUV&#xA;Chroma subsampling                       : 4:2:0&#xA;Bit depth                                : 8&#xA;Bit depth                                : 8 bits&#xA;Scan type                                : Progressive&#xA;Scan type                                : Progressive&#xA;Interlacement                            : PPF&#xA;Interlacement                            : Progressive&#xA;Bits/(Pixel*Frame)                       : 0.070&#xA;Stream size                              : 220159060&#xA;Stream size                              : 210 MiB (81%)&#xA;Stream size                              : 210 MiB&#xA;Stream size                              : 210 MiB&#xA;Stream size                              : 210 MiB&#xA;Stream size                              : 210.0 MiB&#xA;Stream size                              : 210 MiB (81%)&#xA;Proportion of this stream                : 0.80732&#xA;Writing library                          : x264 - core 125&#xA;Writing library                          : x264 core 125&#xA;Writing library/Name                     : x264&#xA;Writing library/Version                  : core 125&#xA;Encoding settings                        : cabac=0 / ref=5 / deblock=1:0:0 / analyse=0x1:0x131 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=8 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=0 / weightp=0 / keyint=30 / keyint_min=16 / scenecut=40 / intra_refresh=0 / rc_lookahead=30 / rc=2pass / mbtree=1 / bitrate=270 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / vbv_maxrate=270 / vbv_bufsize=270 / nal_hrd=none / ip_ratio=1.40 / aq=1:1.00&#xA;Tagged date                              : UTC 2012-09-25 07:21:37&#xA;&#xA;Audio&#xA;Count                                    : 169&#xA;Count of stream of this kind             : 1&#xA;Kind of stream                           : Audio&#xA;Kind of stream                           : Audio&#xA;Stream identifier                        : 0&#xA;ID                                       : 2&#xA;ID                                       : 2&#xA;Format                                   : AAC&#xA;Format/Info                              : Advanced Audio Codec&#xA;Commercial name                          : AAC&#xA;Format profile                           : LC&#xA;Codec ID                                 : 40&#xA;Codec                                    : AAC LC&#xA;Codec                                    : AAC LC&#xA;Codec/Family                             : AAC&#xA;Codec/CC                                 : 40&#xA;Duration                                 : 6556027&#xA;Duration                                 : 1h 49mn&#xA;Duration                                 : 1h 49mn 16s 27ms&#xA;Duration                                 : 1h 49mn&#xA;Duration                                 : 01:49:16.027&#xA;Bit rate mode                            : VBR&#xA;Bit rate mode                            : Variable&#xA;Bit rate                                 : 58955&#xA;Bit rate                                 : 59.0 Kbps&#xA;Maximum bit rate                         : 270000&#xA;Maximum bit rate                         : 270 Kbps&#xA;Channel(s)                               : 2&#xA;Channel(s)                               : 2 channels&#xA;Channel positions                        : Front: L R&#xA;Channel positions                        : 2/0/0&#xA;Sampling rate                            : 44100&#xA;Sampling rate                            : 44.1 KHz&#xA;Samples count                            : 289120791&#xA;Compression mode                         : Lossy&#xA;Compression mode                         : Lossy&#xA;Stream size                              : 48314149&#xA;Stream size                              : 46.1 MiB (18%)&#xA;Stream size                              : 46 MiB&#xA;Stream size                              : 46 MiB&#xA;Stream size                              : 46.1 MiB&#xA;Stream size                              : 46.08 MiB&#xA;Stream size                              : 46.1 MiB (18%)&#xA;Proportion of this stream                : 0.17717&#xA;Tagged date                              : UTC 2012-09-25 07:21:37&#xA;

    &#xA;&#xA;

    Moov atom info (/moov/trak[0] - video, /moov/trak[1] - audio) sample rate 44100 :&#xA;(look stsz and stts nodes in trak)

    &#xA;&#xA;

    Atom ftyp @ 0 of size: 32, ends @ 32&#xA;Atom moov @ 32 of size: 4230651, ends @ 4230683&#xA;     Atom mvhd @ 40 of size: 108, ends @ 148&#xA;     Atom trak @ 148 of size: 868970, ends @ 869118&#xA;         Atom tkhd @ 156 of size: 92, ends @ 248&#xA;         Atom edts @ 248 of size: 36, ends @ 284&#xA;             Atom elst @ 256 of size: 28, ends @ 284&#xA;         Atom mdia @ 284 of size: 868834, ends @ 869118&#xA;             Atom mdhd @ 292 of size: 32, ends @ 324&#xA;             Atom hdlr @ 324 of size: 45, ends @ 369&#xA;             Atom minf @ 369 of size: 868749, ends @ 869118&#xA;                 Atom vmhd @ 377 of size: 20, ends @ 397&#xA;                 Atom dinf @ 397 of size: 36, ends @ 433&#xA;                     Atom dref @ 405 of size: 28, ends @ 433&#xA;                 Atom stbl @ 433 of size: 868685, ends @ 869118&#xA;                     Atom stsd @ 441 of size: 149, ends @ 590&#xA;                         Atom avc1 @ 457 of size: 133, ends @ 590&#xA;                             Atom avcC @ 543 of size: 47, ends @ 590&#xA;                     Atom stts @ 590 of size: 24, ends @ 614&#xA;                     Atom stss @ 614 of size: 26340, ends @ 26954&#xA;                     Atom stsc @ 26954 of size: 52, ends @ 27006&#xA;                     Atom stsz @ 27006 of size: 785956, ends @ 812962&#xA;                     Atom stco @ 812962 of size: 56156, ends @ 869118&#xA;     Atom trak @ 869118 of size: 3361468, ends @ 4230586&#xA;         Atom tkhd @ 869126 of size: 92, ends @ 869218&#xA;         Atom edts @ 869218 of size: 36, ends @ 869254&#xA;             Atom elst @ 869226 of size: 28, ends @ 869254&#xA;         Atom mdia @ 869254 of size: 3361332, ends @ 4230586&#xA;             Atom mdhd @ 869262 of size: 32, ends @ 869294&#xA;             Atom hdlr @ 869294 of size: 45, ends @ 869339&#xA;             Atom minf @ 869339 of size: 3361247, ends @ 4230586&#xA;                 Atom smhd @ 869347 of size: 16, ends @ 869363&#xA;                 Atom dinf @ 869363 of size: 36, ends @ 869399&#xA;                     Atom dref @ 869371 of size: 28, ends @ 869399&#xA;                 Atom stbl @ 869399 of size: 3361187, ends @ 4230586&#xA;                     Atom stsd @ 869407 of size: 91, ends @ 869498&#xA;                         Atom mp4a @ 869423 of size: 75, ends @ 869498&#xA;                             Atom esds @ 869459 of size: 39, ends @ 869498&#xA;                     **Atom stts @ 869498 of size: 2135816, ends @ 3005314**&#xA;                     Atom stsc @ 3005314 of size: 39712, ends @ 3045026&#xA;                     **Atom stsz @ 3045026 of size: 1129400, ends @ 4174426**&#xA;                     Atom stco @ 4174426 of size: 56160, ends @ 4230586&#xA;     Atom udta @ 4230586 of size: 97, ends @ 4230683&#xA;         Atom meta @ 4230594 of size: 89, ends @ 4230683&#xA;             Atom hdlr @ 4230606 of size: 33, ends @ 4230639&#xA;             Atom ilst @ 4230639 of size: 44, ends @ 4230683&#xA;                 Atom &#xA9;too @ 4230647 of size: 36, ends @ 4230683&#xA;                     Atom data @ 4230655 of size: 28, ends @ 4230683&#xA;Atom mdat @ 4230683 of size: 268473217, ends @ 272703900&#xA;Atom free @ 272703900 of size: 8, ends @ 272703908&#xA;Atom free @ 272703908 of size: 62, ends @ 272703970&#xA;------------------------------------------------------&#xA;Total size: 272703970 bytes; 50 atoms total. AtomicParsley version: 0.9.0 (utf8)&#xA;Media data: 268473217 bytes; 4230753 bytes all other atoms (1.551% atom overhead).&#xA;Total free atom space: 70 bytes; 0.000% waste. Padding available: 0 bytes.&#xA;------------------------------------------------------&#xA;

    &#xA;&#xA;

    After reencoding this movie with audio sample rate 11025 header size much less :

    &#xA;&#xA;

    Media info (audio sample rate = 11025) : (crop duplicate info)

    &#xA;&#xA;

    General&#xA;***&#xA;HeaderSize                               : 1276359&#xA;&#xA;Video&#xA;***&#xA;&#xA;Audio&#xA;Count                                    : 169&#xA;Count of stream of this kind             : 1&#xA;Kind of stream                           : Audio&#xA;Kind of stream                           : Audio&#xA;Stream identifier                        : 0&#xA;ID                                       : 2&#xA;ID                                       : 2&#xA;Format                                   : AAC&#xA;Format/Info                              : Advanced Audio Codec&#xA;Commercial name                          : AAC&#xA;Format profile                           : LC&#xA;Codec ID                                 : 40&#xA;Codec                                    : AAC LC&#xA;Codec                                    : AAC LC&#xA;Codec/Family                             : AAC&#xA;Codec/CC                                 : 40&#xA;Duration                                 : 6556132&#xA;Duration                                 : 1h 49mn&#xA;Duration                                 : 1h 49mn 16s 132ms&#xA;Duration                                 : 1h 49mn&#xA;Duration                                 : 01:49:16.132&#xA;Bit rate mode                            : VBR&#xA;Bit rate mode                            : Variable&#xA;Bit rate                                 : 37991&#xA;Bit rate                                 : 38.0 Kbps&#xA;Maximum bit rate                         : 128000&#xA;Maximum bit rate                         : 128 Kbps&#xA;Channel(s)                               : 2&#xA;Channel(s)                               : 2 channels&#xA;Channel positions                        : Front: L R&#xA;Channel positions                        : 2/0/0&#xA;Sampling rate                            : 11025&#xA;Sampling rate                            : 11.025 KHz&#xA;Samples count                            : 72281355&#xA;Compression mode                         : Lossy&#xA;Compression mode                         : Lossy&#xA;Stream size                              : 31134257&#xA;Stream size                              : 29.7 MiB (12%)&#xA;Stream size                              : 30 MiB&#xA;Stream size                              : 30 MiB&#xA;Stream size                              : 29.7 MiB&#xA;Stream size                              : 29.69 MiB&#xA;Stream size                              : 29.7 MiB (12%)&#xA;Proportion of this stream                : 0.12327&#xA;Tagged date                              : UTC 2012-09-25 13:20:28&#xA;

    &#xA;&#xA;

    Moov atom info (/moov/trak[0] - video, /moov/trak[1] - audio) sample rate 11025 :

    &#xA;&#xA;

    Atom ftyp @ 0 of size: 32, ends @ 32&#xA;Atom moov @ 32 of size: 1276327, ends @ 1276359&#xA;     Atom mvhd @ 40 of size: 108, ends @ 148&#xA;     Atom trak @ 148 of size: 821662, ends @ 821810&#xA;         Atom tkhd @ 156 of size: 92, ends @ 248&#xA;         Atom edts @ 248 of size: 36, ends @ 284&#xA;             Atom elst @ 256 of size: 28, ends @ 284&#xA;         Atom mdia @ 284 of size: 821526, ends @ 821810&#xA;             Atom mdhd @ 292 of size: 32, ends @ 324&#xA;             Atom hdlr @ 324 of size: 45, ends @ 369&#xA;             Atom minf @ 369 of size: 821441, ends @ 821810&#xA;                 Atom vmhd @ 377 of size: 20, ends @ 397&#xA;                 Atom dinf @ 397 of size: 36, ends @ 433&#xA;                     Atom dref @ 405 of size: 28, ends @ 433&#xA;                 Atom stbl @ 433 of size: 821377, ends @ 821810&#xA;                     Atom stsd @ 441 of size: 149, ends @ 590&#xA;                         Atom avc1 @ 457 of size: 133, ends @ 590&#xA;                             Atom avcC @ 543 of size: 47, ends @ 590&#xA;                     Atom stts @ 590 of size: 24, ends @ 614&#xA;                     Atom stss @ 614 of size: 26340, ends @ 26954&#xA;                     Atom stsc @ 26954 of size: 52, ends @ 27006&#xA;                     Atom stsz @ 27006 of size: 785956, ends @ 812962&#xA;                     Atom stco @ 812962 of size: 8848, ends @ 821810&#xA;     Atom trak @ 821810 of size: 454452, ends @ 1276262&#xA;         Atom tkhd @ 821818 of size: 92, ends @ 821910&#xA;         Atom edts @ 821910 of size: 36, ends @ 821946&#xA;             Atom elst @ 821918 of size: 28, ends @ 821946&#xA;         Atom mdia @ 821946 of size: 454316, ends @ 1276262&#xA;             Atom mdhd @ 821954 of size: 32, ends @ 821986&#xA;             Atom hdlr @ 821986 of size: 45, ends @ 822031&#xA;             Atom minf @ 822031 of size: 454231, ends @ 1276262&#xA;                 Atom smhd @ 822039 of size: 16, ends @ 822055&#xA;                 Atom dinf @ 822055 of size: 36, ends @ 822091&#xA;                     Atom dref @ 822063 of size: 28, ends @ 822091&#xA;                 Atom stbl @ 822091 of size: 454171, ends @ 1276262&#xA;                     Atom stsd @ 822099 of size: 91, ends @ 822190&#xA;                         Atom mp4a @ 822115 of size: 75, ends @ 822190&#xA;                             Atom esds @ 822151 of size: 39, ends @ 822190&#xA;                     Atom stts @ 822190 of size: 161368, ends @ 983558&#xA;                     Atom stsc @ 983558 of size: 1480, ends @ 985038&#xA;                     Atom stsz @ 985038 of size: 282372, ends @ 1267410&#xA;                     Atom stco @ 1267410 of size: 8852, ends @ 1276262&#xA;     Atom udta @ 1276262 of size: 97, ends @ 1276359&#xA;         Atom meta @ 1276270 of size: 89, ends @ 1276359&#xA;             Atom hdlr @ 1276282 of size: 33, ends @ 1276315&#xA;             Atom ilst @ 1276315 of size: 44, ends @ 1276359&#xA;                 Atom &#xA9;too @ 1276323 of size: 36, ends @ 1276359&#xA;                     Atom data @ 1276331 of size: 28, ends @ 1276359&#xA;Atom mdat @ 1276359 of size: 251293325, ends @ 252569684&#xA;Atom free @ 252569684 of size: 8, ends @ 252569692&#xA;Atom free @ 252569692 of size: 62, ends @ 252569754&#xA;------------------------------------------------------&#xA;Total size: 252569754 bytes; 50 atoms total. AtomicParsley version: 0.9.0 (utf8)&#xA;Media data: 251293325 bytes; 1276429 bytes all other atoms (0.505% atom overhead).&#xA;Total free atom space: 70 bytes; 0.000% waste. Padding available: 0 bytes.&#xA;------------------------------------------------------&#xA;

    &#xA;&#xA;

    On slow connection this movie start playing after 30-40 seconds until header info (4.2 Mb) downloading. I need that movie start playing fast as it possible. And i have next questions :

    &#xA;&#xA;

      &#xA;
    1. How reduce size of movie header ?

    2. &#xA;

    3. How reduce size of&#xA;/moov[0]/trak[1]/mdia[0]/minf[0]/stbl[0] and why it so big when&#xA;sample rate 44100 ?

    4. &#xA;

    &#xA;

  • Parallelize Youtube video frame download using yt-dlp and cv2

    4 mars 2023, par zulle99

    My task is to download multiple sequences of successive low resolution frames of Youtube videos.

    &#xA;

    I summarize the main parts of the process :

    &#xA;

      &#xA;
    • Each bag of shots have a dimension of half a second (depending on the current fps)
    • &#xA;

    • In order to grab useful frames I've decided to remove the initial and final 10% of each video since it is common to have an intro and outro. Moreover
    • &#xA;

    • I've made an array of pair of initial and final frame to distribute the load on multiple processes using ProcessPoolExecutor(max_workers=multiprocessing.cpu_count())
    • &#xA;

    • In case of failure/exception I completly remove the relative directory
    • &#xA;

    &#xA;

    The point is that it do not scale up, since while running I noticesd that all CPUs had always a load lower that the 20% more or less. In addition since with these shots I have to run multiple CNNs, to prevent overfitting it is suggested to have a big dataset and not a bounch of shots.

    &#xA;

    Here it is the code :

    &#xA;

    import yt_dlp&#xA;import os&#xA;from tqdm import tqdm&#xA;import cv2&#xA;import shutil&#xA;import time&#xA;import random&#xA;from concurrent.futures import ProcessPoolExecutor&#xA;import multiprocessing&#xA;import pandas as pd&#xA;import numpy as np&#xA;from pathlib import Path&#xA;import zipfile&#xA;&#xA;&#xA;# PARAMETERS&#xA;percentage_train_test = 50&#xA;percentage_bag_shots = 20&#xA;percentage_to_ignore = 10&#xA;&#xA;zip_f_name = f&#x27;VideoClassificationDataset_{percentage_train_test}_{percentage_bag_shots}_{percentage_to_ignore}&#x27;&#xA;dataset_path = Path(&#x27;/content/VideoClassificationDataset&#x27;)&#xA;&#xA;# DOWNOAD ZIP FILES&#xA;!wget --no-verbose https://github.com/gtoderici/sports-1m-dataset/archive/refs/heads/master.zip&#xA;&#xA;# EXTRACT AND DELETE THEM&#xA;!unzip -qq -o &#x27;/content/master.zip&#x27; &#xA;!rm &#x27;/content/master.zip&#x27;&#xA;&#xA;DATA = {&#x27;train_partition.txt&#x27;: {},&#xA;        &#x27;test_partition.txt&#x27;: {}}&#xA;&#xA;LABELS = []&#xA;&#xA;train_dict = {}&#xA;test_dict = {}&#xA;&#xA;path = &#x27;/content/sports-1m-dataset-master/original&#x27;&#xA;&#xA;for f in os.listdir(path):&#xA;  with open(path &#x2B; &#x27;/&#x27; &#x2B; f) as f_txt:&#xA;    lines = f_txt.readlines()&#xA;    for line in lines:&#xA;      splitted_line = line.split(&#x27; &#x27;)&#xA;      label_indices = splitted_line[1].rstrip(&#x27;\n&#x27;).split(&#x27;,&#x27;) &#xA;      DATA[f][splitted_line[0]] = list(map(int, label_indices))&#xA;&#xA;with open(&#x27;/content/sports-1m-dataset-master/labels.txt&#x27;) as f_labels:&#xA;  LABELS = f_labels.read().splitlines()&#xA;&#xA;&#xA;TRAIN = DATA[&#x27;train_partition.txt&#x27;]&#xA;TEST = DATA[&#x27;test_partition.txt&#x27;]&#xA;print(&#x27;Original Train Test length: &#x27;, len(TRAIN), len(TEST))&#xA;&#xA;# sample a subset percentage_train_test&#xA;TRAIN = dict(random.sample(TRAIN.items(), (len(TRAIN)*percentage_train_test)//100))&#xA;TEST = dict(random.sample(TEST.items(), (len(TEST)*percentage_train_test)//100))&#xA;&#xA;print(f&#x27;Sampled {percentage_train_test} Percentage  Train Test length: &#x27;, len(TRAIN), len(TEST))&#xA;&#xA;&#xA;if not os.path.exists(dataset_path): os.makedirs(dataset_path)&#xA;if not os.path.exists(f&#x27;{dataset_path}/train&#x27;): os.makedirs(f&#x27;{dataset_path}/train&#x27;)&#xA;if not os.path.exists(f&#x27;{dataset_path}/test&#x27;): os.makedirs(f&#x27;{dataset_path}/test&#x27;)&#xA;

    &#xA;

    Function to extract a sequence of continuous frames :

    &#xA;

    def extract_frames(directory, url, idx_bag, start_frame, end_frame):&#xA;  capture = cv2.VideoCapture(url)&#xA;  count = start_frame&#xA;&#xA;  capture.set(cv2.CAP_PROP_POS_FRAMES, count)&#xA;  os.makedirs(f&#x27;{directory}/bag_of_shots{str(idx_bag)}&#x27;)&#xA;&#xA;  while count &lt; end_frame:&#xA;&#xA;    ret, frame = capture.read()&#xA;&#xA;    if not ret: &#xA;      shutil.rmtree(f&#x27;{directory}/bag_of_shots{str(idx_bag)}&#x27;)&#xA;      return False&#xA;&#xA;    filename = f&#x27;{directory}/bag_of_shots{str(idx_bag)}/shot{str(count - start_frame)}.png&#x27;&#xA;&#xA;    cv2.imwrite(filename, frame)&#xA;    count &#x2B;= 1&#xA;&#xA;  capture.release()&#xA;  return True&#xA;

    &#xA;

    Function to spread the load along multiple processors :

    &#xA;

    def video_to_frames(video_url, labels_list, directory, dic, percentage_of_bags):&#xA;  url_id = video_url.split(&#x27;=&#x27;)[1]&#xA;  path_until_url_id = f&#x27;{dataset_path}/{directory}/{url_id}&#x27;&#xA;  try:   &#xA;&#xA;    ydl_opts = {&#xA;        &#x27;ignoreerrors&#x27;: True,&#xA;        &#x27;quiet&#x27;: True,&#xA;        &#x27;nowarnings&#x27;: True,&#xA;        &#x27;simulate&#x27;: True,&#xA;        &#x27;ignorenoformatserror&#x27;: True,&#xA;        &#x27;verbose&#x27;:False,&#xA;        &#x27;cookies&#x27;: &#x27;/content/all_cookies.txt&#x27;,&#xA;        #https://stackoverflow.com/questions/63329412/how-can-i-solve-this-youtube-dl-429&#xA;    }&#xA;    ydl = yt_dlp.YoutubeDL(ydl_opts)&#xA;    info_dict = ydl.extract_info(video_url, download=False)&#xA;&#xA;    if(info_dict is not None and  info_dict[&#x27;fps&#x27;] >= 20):&#xA;      # I must have a least 20 frames per seconds since I take half of second bag of shots for every video&#xA;&#xA;      formats = info_dict.get(&#x27;formats&#x27;, None)&#xA;&#xA;      # excluding the initial and final 10% of each video to avoid noise&#xA;      video_length = info_dict[&#x27;duration&#x27;] * info_dict[&#x27;fps&#x27;]&#xA;&#xA;      shots = info_dict[&#x27;fps&#x27;] // 2&#xA;&#xA;      to_ignore = (video_length * percentage_to_ignore) // 100&#xA;      new_len = video_length - (to_ignore * 2)&#xA;      tot_stored_bags = ((new_len // shots) * percentage_of_bags) // 100   # ((total_possbile_bags // shots) * percentage_of_bags) // 100&#xA;      if tot_stored_bags == 0: tot_stored_bags = 1 # minimum 1 bag of shots&#xA;&#xA;      skip_rate_between_bags = (new_len - (tot_stored_bags * shots)) // (tot_stored_bags-1) if tot_stored_bags > 1 else 0&#xA;&#xA;      chunks = [[to_ignore&#x2B;(bag*(skip_rate_between_bags&#x2B;shots)), to_ignore&#x2B;(bag*(skip_rate_between_bags&#x2B;shots))&#x2B;shots] for bag in range(tot_stored_bags)]&#xA;      # sequence of [[start_frame, end_frame], [start_frame, end_frame], [start_frame, end_frame], ...]&#xA;&#xA;&#xA;      # ----------- For the moment I download only shots form video that has 144p resolution -----------&#xA;&#xA;      res = {&#xA;          &#x27;160&#x27;: &#x27;144p&#x27;,&#xA;          &#x27;133&#x27;: &#x27;240p&#x27;,&#xA;          &#x27;134&#x27;: &#x27;360p&#x27;,&#xA;          &#x27;135&#x27;: &#x27;360p&#x27;,&#xA;          &#x27;136&#x27;: &#x27;720p&#x27;&#xA;      }&#xA;&#xA;      format_id = {}&#xA;      for f in formats: format_id[f[&#x27;format_id&#x27;]] = f&#xA;      #for res in resolution_id:&#xA;      if list(res.keys())[0] in list(format_id.keys()):&#xA;          video = format_id[list(res.keys())[0]]&#xA;          url = video.get(&#x27;url&#x27;, None)&#xA;          if(video.get(&#x27;url&#x27;, None) != video.get(&#x27;manifest_url&#x27;, None)):&#xA;&#xA;            if not os.path.exists(path_until_url_id): os.makedirs(path_until_url_id)&#xA;&#xA;            with ProcessPoolExecutor(max_workers=multiprocessing.cpu_count()) as executor:&#xA;              for idx_bag, f in enumerate(chunks): &#xA;                res = executor.submit(&#xA;                  extract_frames, directory = path_until_url_id, url = url, idx_bag = idx_bag, start_frame = f[0], end_frame = f[1])&#xA;                &#xA;                if res.result() is True: &#xA;                  l = np.zeros(len(LABELS), dtype=int) &#xA;                  for label in labels_list: l[label] = 1&#xA;                  l = np.append(l, [shots]) # appending the number of shots taken in the list before adding it on the dictionary&#xA;&#xA;                  dic[f&#x27;{directory}/{url_id}/bag_of_shots{str(idx_bag)}&#x27;] = l.tolist()&#xA;&#xA;&#xA;  except Exception as e:&#xA;    shutil.rmtree(path_until_url_id)&#xA;    pass&#xA;

    &#xA;

    Download of TRAIN bag of shots :

    &#xA;

    start_time = time.time()&#xA;pbar = tqdm(enumerate(TRAIN.items()), total = len(TRAIN.items()), leave=False)&#xA;&#xA;for _, (url, labels_list) in pbar: video_to_frames(&#xA;  video_url = url, labels_list = labels_list, directory = &#x27;train&#x27;, dic = train_dict, percentage_of_bags = percentage_bag_shots)&#xA;&#xA;print("--- %s seconds ---" % (time.time() - start_time))&#xA;

    &#xA;

    Download of TEST bag of shots :

    &#xA;

    start_time = time.time()&#xA;pbar = tqdm(enumerate(TEST.items()), total = len(TEST.items()), leave=False)&#xA;&#xA;for _, (url, labels_list) in pbar: video_to_frames(&#xA;  video_url = url, labels_list = labels_list, directory = &#x27;test&#x27;, dic = test_dict, percentage_of_bags = percentage_bag_shots)&#xA;&#xA;print("--- %s seconds ---" % (time.time() - start_time))&#xA;

    &#xA;

    Save the .csv files

    &#xA;

    train_df = pd.DataFrame.from_dict(train_dict, orient=&#x27;index&#x27;, dtype=int).reset_index(level=0)&#xA;train_df = train_df.rename(columns={train_df.columns[-1]: &#x27;shots&#x27;})&#xA;train_df.to_csv(&#x27;/content/VideoClassificationDataset/train.csv&#x27;, index=True)&#xA;&#xA;test_df = pd.DataFrame.from_dict(test_dict, orient=&#x27;index&#x27;, dtype=int).reset_index(level=0)&#xA;test_df = test_df.rename(columns={test_df.columns[-1]: &#x27;shots&#x27;})&#xA;test_df.to_csv(&#x27;/content/VideoClassificationDataset/test.csv&#x27;, index=True)&#xA;

    &#xA;