Recherche avancée

Médias (9)

Mot : - Tags -/soundtrack

Autres articles (111)

  • Installation en mode ferme

    4 février 2011, par

    Le mode ferme permet d’héberger plusieurs sites de type MediaSPIP en n’installant qu’une seule fois son noyau fonctionnel.
    C’est la méthode que nous utilisons sur cette même plateforme.
    L’utilisation en mode ferme nécessite de connaïtre un peu le mécanisme de SPIP contrairement à la version standalone qui ne nécessite pas réellement de connaissances spécifique puisque l’espace privé habituel de SPIP n’est plus utilisé.
    Dans un premier temps, vous devez avoir installé les mêmes fichiers que l’installation (...)

  • Les formats acceptés

    28 janvier 2010, par

    Les commandes suivantes permettent d’avoir des informations sur les formats et codecs gérés par l’installation local de ffmpeg :
    ffmpeg -codecs ffmpeg -formats
    Les format videos acceptés en entrée
    Cette liste est non exhaustive, elle met en exergue les principaux formats utilisés : h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 m4v : raw MPEG-4 video format flv : Flash Video (FLV) / Sorenson Spark / Sorenson H.263 Theora wmv :
    Les formats vidéos de sortie possibles
    Dans un premier temps on (...)

  • Configuration spécifique d’Apache

    4 février 2011, par

    Modules spécifiques
    Pour la configuration d’Apache, il est conseillé d’activer certains modules non spécifiques à MediaSPIP, mais permettant d’améliorer les performances : mod_deflate et mod_headers pour compresser automatiquement via Apache les pages. Cf ce tutoriel ; mode_expires pour gérer correctement l’expiration des hits. Cf ce tutoriel ;
    Il est également conseillé d’ajouter la prise en charge par apache du mime-type pour les fichiers WebM comme indiqué dans ce tutoriel.
    Création d’un (...)

Sur d’autres sites (6292)

  • ffmpeg extract segment from video on-the-fly

    29 novembre 2022, par brunoais

    Context

    


    I want to make a service that hosts mp4 files but also provides video streaming.

    


    The server side is made of 2 "small" edge servers with capacity to cache about 0.1% of the content and one main server with a fraction of the bandwidth of the edge servers but much more robust storage.

    


    Recent status

    


    With the help of the ffmpeg manual,
    
Recently, when a segment is requested by an edge server, I run this command in ffmpeg

    


    ffmpeg -i in.mp4 -f hls -hls_list_size 0 -hls_playlist 1 -hls_time 60 -strftime 1  -hls_flags independent_segments+second_level_segment_index+second_level_segment_duration -hls_base_url '/path/to/file/' -hls_segment_filename 'name_%%03d.ts'  -c copy -copyts -hls_segment_type fmp4 out.m3u8


    


    Then obtain the requested segment (plus 3 subsequent ones) then delete everything.

    


    Current status

    


    Currently, I tried to get some level of optimization using -to :

    


    ffmpeg -i in.mp4 -to  -f hls -hls_list_size 0 -hls_playlist 1 -hls_time 60 -strftime 1  -hls_flags independent_segments+second_level_segment_index+second_level_segment_duration -hls_base_url '/path/to/file/' -hls_segment_filename 'name_%%03d.ts'  -c copy -copyts -hls_segment_type fmp4 out.m3u8


    


    Then sending the requested segments to the edge that requested them, then delete the result.
Do note that /path/to/file/ is a tmpfs with quite modest capacity (files can't stay there for too long).

    


    The current setback

    


    The main issue I get with the current process is that it takes a long time to obtain the last segments (2-4s).
That creates a bottleneck in how long segments take to be served. I can increase the buffer from 3 videos to 5 (or even more) but that doesn't solve the actual problem and, instead, will bring more strain on other areas.

    


    Cutting is not reliable

    


    There doesn't seem to exist an option to select what segments to generate using ffmpeg.

    


    Using cutting argument for start time (-ss) has shown to usually work but regularely causes the first keyframe used to be wrong. However, I believe I have all segment files in variable length and cut at the keyframe of the original file.

    


    Help needed

    


    How to extract an arbitrary segment of an mp4, described in the m3u8 file (which was done in a previous extraction) ?

    


    I have full control over ffmpeg and I can automate edits to the m3u8 file after generating them, as required. However, I need to understand and see how can this be solved.

    


  • Turn off sw_scale conversion to planar YUV 32 byte alignment requirements

    8 novembre 2022, par flansel

    I am experiencing artifacts on the right edge of scaled and converted images when converting into planar YUV pixel formats with sw_scale. I am reasonably sure (although I can not find it anywhere in the documentation) that this is because sw_scale is using an optimization for 32 byte aligned lines, in the destination. However I would like to turn this off because I am using sw_scale for image composition, so even though the destination lines may be 32 byte aligned, the output image may not be.

    


    Example.

    


    Full output frame is 1280x720 yuv422p10le. (this is 32 byte aligned)
However into the top left corner I am scaling an image with an outwidth of 1280 / 3 = 426.
426 in this format is not 32 byte aligned, but I believe sw_scale sees that the output linesize is 32 byte aligned and overwrites the width of 426 putting garbage in the next 22 bytes of data thinking this is simply padding when in my case this is displayable area.

    


    This is why I need to actually disable this optimization or somehow trick sw_scale into believing it does not apply while keeping intact the way the program works, which is otherwise fine.

    


    I have tried adding extra padding to the destination lines so they are no longer 32 byte aligned,
this did not help as far as I can tell.

    


    Edit with code Example. Rendering omitted for ease of use.
Also here is a similar issue, unfortunately as I stated there fix will not work for my use case. https://github.com/obsproject/obs-studio/pull/2836

    


    Use the commented line of code to swap between a output width which is and isnt 32 byte aligned.

    


    #include "libswscale/swscale.h"
#include "libavutil/imgutils.h"
#include "libavutil/pixelutils.h"
#include "libavutil/pixfmt.h"
#include "libavutil/pixdesc.h"
#include 
#include 
#include 

int main(int argc, char **argv) {

/// Set up a 1280x720 window, and an item with 1/3 width and height of the window.
int window_width, window_height, item_width, item_height;
window_width = 1280;
window_height = 720;
item_width = (window_width / 3);
item_height = (window_height / 3);

int item_out_width = item_width;
/// This line sets the item width to be 32 byte aligned uncomment to see uncorrupted results
/// Note %16 because outformat is 2 bytes per component
//item_out_width -= (item_width % 16);

enum AVPixelFormat outformat = AV_PIX_FMT_YUV422P10LE;
enum AVPixelFormat informat = AV_PIX_FMT_UYVY422;
int window_lines[4] = {0};
av_image_fill_linesizes(window_lines, outformat, window_width);

uint8_t *window_planes[4] = {0};
window_planes[0] = calloc(1, window_lines[0] * window_height);
window_planes[1] = calloc(1, window_lines[1] * window_height);
window_planes[2] = calloc(1, window_lines[2] * window_height); /// Fill the window with all 0s, this is green in yuv.


int item_lines[4] = {0};
av_image_fill_linesizes(item_lines, informat, item_width);

uint8_t *item_planes[4] = {0};
item_planes[0] = malloc(item_lines[0] * item_height);
memset(item_planes[0], 100, item_lines[0] * item_height);

struct SwsContext *ctx;
ctx = sws_getContext(item_width, item_height, informat,
               item_out_width, item_height, outformat, SWS_FAST_BILINEAR, NULL, NULL, NULL);

/// Check a block in the normal region
printf("Pre scale normal region %d %d %d\n", (int)((uint16_t*)window_planes[0])[0], (int)((uint16_t*)window_planes[1])[0],
       (int)((uint16_t*)window_planes[2])[0]);

/// Check a block in the corrupted region (should be all zeros) These values should be out of the converted region
int corrupt_offset_y = (item_out_width + 3) * 2; ///(item_width + 3) * 2 bytes per component Y PLANE
int corrupt_offset_uv = (item_out_width + 3); ///(item_width + 3) * (2 bytes per component rshift 1 for horiz scaling) U and V PLANES

printf("Pre scale corrupted region %d %d %d\n", (int)(*((uint16_t*)(window_planes[0] + corrupt_offset_y))),
       (int)(*((uint16_t*)(window_planes[1] + corrupt_offset_uv))), (int)(*((uint16_t*)(window_planes[2] + corrupt_offset_uv))));
sws_scale(ctx, (const uint8_t**)item_planes, item_lines, 0, item_height,window_planes, window_lines);

/// Preform same tests after scaling
printf("Post scale normal region %d %d %d\n", (int)((uint16_t*)window_planes[0])[0], (int)((uint16_t*)window_planes[1])[0],
       (int)((uint16_t*)window_planes[2])[0]);
printf("Post scale corrupted region %d %d %d\n", (int)(*((uint16_t*)(window_planes[0] + corrupt_offset_y))),
       (int)(*((uint16_t*)(window_planes[1] + corrupt_offset_uv))), (int)(*((uint16_t*)(window_planes[2] + corrupt_offset_uv))));

return 0;


    


    }

    


    Example Output:

//No alignment
Pre scale normal region 0 0 0
Pre scale corrupted region 0 0 0
Post scale normal region 400 400 400
Post scale corrupted region 512 36865 36865

//With alignment
Pre scale normal region 0 0 0
Pre scale corrupted region 0 0 0
Post scale normal region 400 400 400
Post scale corrupted region 0 0 0


    


  • JSmpeg is not playing audio from websocket stream

    5 juin 2023, par Nik

    I am trying to stream RTSP to web browser using ffmpeg through web socket relay written in node js taken from https://github.com/phoboslab/jsmpeg , and on the browser i am using JSMpeg to display the RTSP stream, the video is playing fine, but audio is not playing,

    


    The ffmpeg command :

    


    ffmpeg -rtsp_transport tcp -i rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4 
       -f mpegts -c:v mpeg1video -c:a mp2 http://127.0.0.1:8081/stream_from_ffmpeg/


    


    The node js web socket relay :

    


    // Use the websocket-relay to serve a raw MPEG-TS over WebSockets. You can use&#xA;// ffmpeg to feed the relay. ffmpeg -> websocket-relay -> browser&#xA;// Example:&#xA;// node websocket-relay yoursecret 8081 8082&#xA;// ffmpeg -i <some input="input"> -f mpegts http://localhost:8081/yoursecret&#xA;&#xA;var fs = require(&#x27;fs&#x27;),&#xA;    http = require(&#x27;http&#x27;),&#xA;    WebSocket = require(&#x27;ws&#x27;);&#xA;&#xA;if (process.argv.length &lt; 3) {&#xA;    console.log(&#xA;        &#x27;Usage: \n&#x27; &#x2B;&#xA;        &#x27;node websocket-relay.js <secret> [ ]&#x27;&#xA;    );&#xA;    process.exit();&#xA;}&#xA;&#xA;var STREAM_SECRET = process.argv[2],&#xA;    STREAM_PORT = process.argv[3] || 8081,&#xA;    WEBSOCKET_PORT = process.argv[4] || 8082,&#xA;    RECORD_STREAM = false;&#xA;&#xA;// Websocket Server&#xA;var socketServer = new WebSocket.Server({port: WEBSOCKET_PORT, perMessageDeflate: false});&#xA;socketServer.connectionCount = 0;&#xA;socketServer.on(&#x27;connection&#x27;, function(socket, upgradeReq) {&#xA;    socketServer.connectionCount&#x2B;&#x2B;;&#xA;    console.log(&#xA;        &#x27;New WebSocket Connection: &#x27;,&#xA;        (upgradeReq || socket.upgradeReq).socket.remoteAddress,&#xA;        (upgradeReq || socket.upgradeReq).headers[&#x27;user-agent&#x27;],&#xA;        &#x27;(&#x27;&#x2B;socketServer.connectionCount&#x2B;&#x27; total)&#x27;&#xA;    );&#xA;    socket.on(&#x27;close&#x27;, function(code, message){&#xA;        socketServer.connectionCount--;&#xA;        console.log(&#xA;            &#x27;Disconnected WebSocket (&#x27;&#x2B;socketServer.connectionCount&#x2B;&#x27; total)&#x27;&#xA;        );&#xA;    });&#xA;});&#xA;socketServer.broadcast = function(data) {&#xA;    socketServer.clients.forEach(function each(client) {&#xA;        if (client.readyState === WebSocket.OPEN) {&#xA;            client.send(data);&#xA;        }&#xA;    });&#xA;};&#xA;&#xA;// HTTP Server to accept incoming MPEG-TS Stream from ffmpeg&#xA;var streamServer = http.createServer( function(request, response) {&#xA;    var params = request.url.substr(1).split(&#x27;/&#x27;);&#xA;&#xA;    if (params[0] !== STREAM_SECRET) {&#xA;        console.log(&#xA;            &#x27;Failed Stream Connection: &#x27;&#x2B; request.socket.remoteAddress &#x2B; &#x27;:&#x27; &#x2B;&#xA;            request.socket.remotePort &#x2B; &#x27; - wrong secret.&#x27;&#xA;        );&#xA;        response.end();&#xA;    }&#xA;&#xA;    response.connection.setTimeout(0);&#xA;    console.log(&#xA;        &#x27;Stream Connected: &#x27; &#x2B;&#xA;        request.socket.remoteAddress &#x2B; &#x27;:&#x27; &#x2B;&#xA;        request.socket.remotePort&#xA;    );&#xA;    request.on(&#x27;data&#x27;, function(data){&#xA;        socketServer.broadcast(data);&#xA;        if (request.socket.recording) {&#xA;            request.socket.recording.write(data);&#xA;        }&#xA;    });&#xA;    request.on(&#x27;end&#x27;,function(){&#xA;        console.log(&#x27;close&#x27;);&#xA;        if (request.socket.recording) {&#xA;            request.socket.recording.close();&#xA;        }&#xA;    });&#xA;&#xA;    // Record the stream to a local file?&#xA;    if (RECORD_STREAM) {&#xA;        var path = &#x27;recordings/&#x27; &#x2B; Date.now() &#x2B; &#x27;.ts&#x27;;&#xA;        request.socket.recording = fs.createWriteStream(path);&#xA;    }&#xA;})&#xA;// Keep the socket open for streaming&#xA;streamServer.headersTimeout = 0;&#xA;streamServer.listen(STREAM_PORT);&#xA;&#xA;console.log(&#x27;Listening for incoming MPEG-TS Stream on http://127.0.0.1:&#x27;&#x2B;STREAM_PORT&#x2B;&#x27;/<secret>&#x27;);&#xA;console.log(&#x27;Awaiting WebSocket connections on ws://127.0.0.1:&#x27;&#x2B;WEBSOCKET_PORT&#x2B;&#x27;/&#x27;);&#xA;</secret></secret></some>

    &#xA;

    The front end code

    &#xA;

    &#xA;&#xA;  &#xA;    &#xA;    &#xA;    &#xA;    <code class="echappe-js">&lt;script src='http://stackoverflow.com/feeds/tag/jsmpeg.min.js'&gt;&lt;/script&gt;&#xA;    &#xA;  &#xA;  &#xA;    &#xA;  &#xA;  &lt;script&gt;&amp;#xA;    let url;&amp;#xA;    let player;&amp;#xA;    let canvas = document.getElementById(&quot;video-canvas&quot;);&amp;#xA;    let ipAddr = &quot;127.0.0.1:8082&quot;;&amp;#xA;    window.onload = async() =&gt; {&amp;#xA;      url = `ws://${ipAddr}`;&amp;#xA;      player = new JSMpeg.Player(url, { canvas: canvas, });&amp;#xA;    };&amp;#xA;&amp;#xA;  &lt;/script&gt;&#xA;&#xA;&#xA;

    &#xA;

    The above code works fine and plays the video, but no audio is playing&#xA;Things I tried :

    &#xA;

    Changed the audio context state inside the player object from suspended to running

    &#xA;

    player.audioOut.context.onstatechange = async () => {&#xA;    console.log("Event triggered by audio");&#xA;&#xA;    if (player.audioOut.context === "suspended") {&#xA;        await player.audioOut.context.resume();&#xA;    }&#xA;}&#xA;

    &#xA;