Recherche avancée

Médias (1)

Mot : - Tags -/artwork

Autres articles (21)

  • Participer à sa traduction

    10 avril 2011

    Vous pouvez nous aider à améliorer les locutions utilisées dans le logiciel ou à traduire celui-ci dans n’importe qu’elle nouvelle langue permettant sa diffusion à de nouvelles communautés linguistiques.
    Pour ce faire, on utilise l’interface de traduction de SPIP où l’ensemble des modules de langue de MediaSPIP sont à disposition. ll vous suffit de vous inscrire sur la liste de discussion des traducteurs pour demander plus d’informations.
    Actuellement MediaSPIP n’est disponible qu’en français et (...)

  • Supporting all media types

    13 avril 2011, par

    Unlike most software and media-sharing platforms, MediaSPIP aims to manage as many different media types as possible. The following are just a few examples from an ever-expanding list of supported formats : images : png, gif, jpg, bmp and more audio : MP3, Ogg, Wav and more video : AVI, MP4, OGV, mpg, mov, wmv and more text, code and other data : OpenOffice, Microsoft Office (Word, PowerPoint, Excel), web (html, CSS), LaTeX, Google Earth and (...)

  • 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 (...)

Sur d’autres sites (5127)

  • How can I display the video on sdl converted to emscripten ?

    3 février 2021, par pleasehelp

    I am trying to view video in a browser using ffmpeg's decoder.

    


    So, I made the decoder into a js file using emscripten.

    


    By the way, the decoder seems to work, but only the last scene is displayed.

    


    How can a video come out from start to finish ?

    


    Here is my code

    


    &#xA;#include &#xA;#include &#xA;#include &#xA;&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;&#xA;#include <sdl2></sdl2>SDL.h>&#xA;&#xA;#define INBUF_SIZE 128&#xA;&#xA;static void decode(AVCodecContext *dec_ctx, AVFrame *frame, AVPacket *pkt,&#xA;                   const char *filename,&#xA;                   SDL_Window * screen, SDL_Renderer * renderer, SDL_Texture * texture)&#xA;{&#xA;    char buf[1024];&#xA;    int ret;&#xA;&#xA;    ret = avcodec_send_packet(dec_ctx, pkt);&#xA;    if (ret &lt; 0) {&#xA;        fprintf(stderr, "Error sending a packet for decoding\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    while (ret >= 0) {&#xA;        ret = avcodec_receive_frame(dec_ctx, frame);&#xA;        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)&#xA;            return;&#xA;        else if (ret &lt; 0) {&#xA;            fprintf(stderr, "Error during decoding\n");&#xA;            exit(1);&#xA;        }&#xA;&#xA;        printf("saving frame %3d\n", dec_ctx->frame_number);&#xA;        fflush(stdout);&#xA;&#xA;        SDL_Rect rect;&#xA;        rect.x = 0;&#xA;        rect.y = 0;&#xA;        rect.w = dec_ctx->width;&#xA;        rect.h = dec_ctx->height;&#xA;&#xA;        SDL_UpdateYUVTexture(&#xA;            texture,            // the texture to update&#xA;            &amp;rect,              // a pointer to the rectangle of pixels to update, or NULL to update the entire texture&#xA;            frame->data[0],      // the raw pixel data for the Y plane&#xA;            frame->linesize[0],  // the number of bytes between rows of pixel data for the Y plane&#xA;            frame->data[1],      // the raw pixel data for the U plane&#xA;            frame->linesize[1],  // the number of bytes between rows of pixel data for the U plane&#xA;            frame->data[2],      // the raw pixel data for the V plane&#xA;            frame->linesize[2]   // the number of bytes between rows of pixel data for the V plane&#xA;        );&#xA;&#xA;        SDL_RenderClear(renderer);&#xA;&#xA;        SDL_RenderCopy(&#xA;            renderer,   // the rendering context&#xA;            texture,    // the source texture&#xA;            NULL,       // the source SDL_Rect structure or NULL for the entire texture&#xA;            NULL        // the destination SDL_Rect structure or NULL for the entire rendering&#xA;                        // target; the texture will be stretched to fill the given rectangle&#xA;        );&#xA;&#xA;        SDL_RenderPresent(renderer);&#xA;        SDL_UpdateWindowSurface(screen);&#xA;    }&#xA;}&#xA;&#xA;int main(int argc, char **argv)&#xA;{&#xA;    const char *filename, *outfilename;&#xA;    const AVCodec *codec;&#xA;    AVCodecParserContext *parser;&#xA;    AVCodecContext *c= NULL;&#xA;    FILE *f;&#xA;    AVFrame *frame;&#xA;    uint8_t inbuf[INBUF_SIZE &#x2B; AV_INPUT_BUFFER_PADDING_SIZE];&#xA;    uint8_t *data;&#xA;    size_t   data_size;&#xA;    int ret;&#xA;    AVPacket *pkt;&#xA;&#xA;    if (argc &lt;= 2) {&#xA;        fprintf(stderr, "Usage: %s <input file="file" /> <output file="file">\n"&#xA;                "And check your input file is encoded by mpeg1video please.\n", argv[0]);&#xA;        exit(0);&#xA;    }&#xA;    filename    = argv[1];&#xA;    outfilename = argv[2];&#xA;&#xA;    pkt = av_packet_alloc();&#xA;    if (!pkt)&#xA;        exit(1);&#xA;&#xA;    /* set end of buffer to 0 (this ensures that no overreading happens for damaged MPEG streams) */&#xA;    memset(inbuf &#x2B; INBUF_SIZE, 0, AV_INPUT_BUFFER_PADDING_SIZE);&#xA;&#xA;    ret = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER);   // [1]&#xA;    if (ret != 0)&#xA;    {&#xA;        // error while initializing SDL&#xA;        printf("Could not initialize SDL - %s\n.", SDL_GetError());&#xA;&#xA;        // exit with error&#xA;        // return -1;&#xA;    }&#xA;&#xA;    /* find the MPEG-1 video decoder */&#xA;    codec = avcodec_find_decoder(AV_CODEC_ID_H265);&#xA;    if (!codec) {&#xA;        fprintf(stderr, "Codec not found\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    parser = av_parser_init(codec->id);&#xA;    if (!parser) {&#xA;        fprintf(stderr, "parser not found\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    c = avcodec_alloc_context3(codec);&#xA;    if (!c) {&#xA;        fprintf(stderr, "Could not allocate video codec context\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* open it */&#xA;    if (avcodec_open2(c, codec, NULL) &lt; 0) {&#xA;        fprintf(stderr, "Could not open codec\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    f = fopen(filename, "rb");&#xA;    if (!f) {&#xA;        fprintf(stderr, "Could not open %s\n", filename);&#xA;        exit(1);&#xA;    }&#xA;&#xA;    frame = av_frame_alloc();&#xA;    if (!frame) {&#xA;        fprintf(stderr, "Could not allocate video frame\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    // Create a window with the specified position, dimensions, and flags.&#xA;    SDL_Window * screen = SDL_CreateWindow( // [2]&#xA;                            "SDL Video Player",&#xA;                            SDL_WINDOWPOS_UNDEFINED,&#xA;                            SDL_WINDOWPOS_UNDEFINED,&#xA;                            640,&#xA;                            360,&#xA;                            SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI&#xA;    );&#xA;&#xA;    if (!screen)&#xA;    {&#xA;        // could not set video mode&#xA;        printf("SDL: could not set video mode - exiting.\n");&#xA;&#xA;        // exit with Error&#xA;        // return -1;&#xA;    }&#xA;&#xA;    // //&#xA;    // SDL_GL_SetSwapInterval(1);&#xA;&#xA;    // A structure that contains a rendering state.&#xA;    SDL_Renderer * renderer = NULL;&#xA;&#xA;    // Use this function to create a 2D rendering context for a window.&#xA;    renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_ACCELERATED);   // [3]&#xA;&#xA;    // A structure that contains an efficient, driver-specific representation&#xA;    // of pixel data.&#xA;    SDL_Texture * texture = NULL;&#xA;&#xA;    // Use this function to create a texture for a rendering context.&#xA;    texture = SDL_CreateTexture(  // [4]&#xA;                renderer,&#xA;                SDL_PIXELFORMAT_YV12,&#xA;                SDL_TEXTUREACCESS_STREAMING,&#xA;                640,&#xA;                360&#xA;            );&#xA;&#xA;    while (!feof(f)) {&#xA;        /* read raw data from the input file */&#xA;        data_size = fread(inbuf, 1, INBUF_SIZE, f);&#xA;        if (!data_size)&#xA;            break;&#xA;&#xA;        /* use the parser to split the data into frames */&#xA;        data = inbuf;&#xA;        while (data_size > 0) {&#xA;            ret = av_parser_parse2(parser, c, &amp;pkt->data, &amp;pkt->size,&#xA;                                   data, data_size, AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0);&#xA;            if (ret &lt; 0) {&#xA;                fprintf(stderr, "Error while parsing\n");&#xA;                exit(1);&#xA;            }&#xA;            data      &#x2B;= ret;&#xA;            data_size -= ret;&#xA;&#xA;            if (pkt->size)&#xA;                decode(c, frame, pkt, outfilename, screen, renderer, texture);&#xA;        }&#xA;    }&#xA;&#xA;    /* flush the decoder */&#xA;    decode(c, frame, NULL, outfilename, screen, renderer, texture);&#xA;&#xA;    fclose(f);&#xA;&#xA;    av_parser_close(parser);&#xA;    avcodec_free_context(&amp;c);&#xA;    av_frame_free(&amp;frame);&#xA;    av_packet_free(&amp;pkt);&#xA;&#xA;    return 0;&#xA;}&#xA;&#xA;</output>

    &#xA;

    Is it possible to continuously play sdl in a browser ?

    &#xA;

  • ffmpeg capture video and audio produced corrupt output

    18 décembre 2020, par wheelie tips

    I have two separate FFmpeg commands that each works well on its own, one for capturing video and the other for capturing audio from the same device ; the captured audio is :

    &#xA;

    ffmpeg -f alsa -thread_queue_size 16384 -i hw:CARD=C4K,DEV=0 -acodec aac /home/pi/Videos/temp.wav&#xA;

    &#xA;

    and the captured video is :

    &#xA;

    ffmpeg -y -nostdin -f v4l2 -threads auto -input_format yuyv422 -fflags &#x2B;genpts -flags &#x2B;global_header -thread_queue_size 16384 -i /dev/video0 -s 1280x720 -r 25 -vcodec h264_v4l2m2m -num_output_buffers 32 -num_capture_buffers 16 -keyint_min 25 -force_key_frames "expr:gte(t,n_forced*1)" -g 50 -b:v 6M -pix_fmt nv12 -f mpegts -muxdelay 0 -muxpreload 0 -movflags &#x2B;faststart /home/pi/Videos/output.mp4&#xA;

    &#xA;

    I’ve tried to combine the two into one call to produce one video file with the audio channel, but whatever I’ve been attempting, the results output were messed up ; obviously, I’m missing something, for example, my latest attempt prodused a frozen image video with the audio channel :

    &#xA;

    ffmpeg -y -nostdin -f v4l2 -threads auto -input_format yuyv422 -fflags &#x2B;genpts -flags &#x2B;global_header -thread_queue_size 16384 -i /dev/video0 -f alsa -thread_queue_size 16384 -i hw:CARD=C4K,DEV=0 -acodec aac -s 1280x720 -r 25 -vcodec h264_v4l2m2m -num_output_buffers 32 -num_capture_buffers 16 -keyint_min 25 -force_key_frames "expr:gte(t,n_forced*1)" -g 50 -b:v 6M -b:a 128K -pix_fmt nv12 -f mpegts -muxdelay 0 -muxpreload 0 -movflags &#x2B;faststart /home/pi/Videos/output.mp4 -loglevel debug&#xA;

    &#xA;

    the full output of the above command :

    &#xA;

    ffmpeg version ca55240 Copyright (c) 2000-2020 the FFmpeg developers&#xA;  built with gcc 8 (Debian 8.3.0-6)&#xA;  configuration: --prefix=/home/pi/ffmpeg_build --pkg-config-flags=&#x27;pkg-config --static&#x27; --extra-cflags=-I/home/pi/ffmpeg_build/include --extra-ldflags=-L/home/pi/ffmpeg_build/lib --extra-libs=&#x27;-lpthread -lm&#x27; --bindir=/home/pi/bin --enable-gpl --enable-gnutls --disable-libaom --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --disable-libx265 --enable-nonfree --arch=aarch64 --disable-libxml2 --enable-libwebp --enable-libdrm&#xA;  libavutil      56. 51.100 / 56. 51.100&#xA;  libavcodec     58. 91.100 / 58. 91.100&#xA;  libavformat    58. 45.100 / 58. 45.100&#xA;  libavdevice    58. 10.100 / 58. 10.100&#xA;  libavfilter     7. 85.100 /  7. 85.100&#xA;  libswscale      5.  7.100 /  5.  7.100&#xA;  libswresample   3.  7.100 /  3.  7.100&#xA;  libpostproc    55.  7.100 / 55.  7.100&#xA;Splitting the commandline.&#xA;Reading option &#x27;-y&#x27; ... matched as option &#x27;y&#x27; (overwrite output files) with argument &#x27;1&#x27;.&#xA;Reading option &#x27;-nostdin&#x27; ... matched as option &#x27;stdin&#x27; (enable or disable interaction on standard input) with argument 0.&#xA;Reading option &#x27;-f&#x27; ... matched as option &#x27;f&#x27; (force format) with argument &#x27;v4l2&#x27;.&#xA;Reading option &#x27;-threads&#x27; ... matched as AVOption &#x27;threads&#x27; with argument &#x27;auto&#x27;.&#xA;Reading option &#x27;-input_format&#x27; ... matched as AVOption &#x27;input_format&#x27; with argument &#x27;yuyv422&#x27;.&#xA;Reading option &#x27;-fflags&#x27; ... matched as AVOption &#x27;fflags&#x27; with argument &#x27;&#x2B;genpts&#x27;.&#xA;Reading option &#x27;-flags&#x27; ... matched as AVOption &#x27;flags&#x27; with argument &#x27;&#x2B;global_header&#x27;.&#xA;Reading option &#x27;-thread_queue_size&#x27; ... matched as option &#x27;thread_queue_size&#x27; (set the maximum number of queued packets from the demuxer) with argument &#x27;16384&#x27;.&#xA;Reading option &#x27;-i&#x27; ... matched as input url with argument &#x27;/dev/video0&#x27;.&#xA;Reading option &#x27;-f&#x27; ... matched as option &#x27;f&#x27; (force format) with argument &#x27;alsa&#x27;.&#xA;Reading option &#x27;-thread_queue_size&#x27; ... matched as option &#x27;thread_queue_size&#x27; (set the maximum number of queued packets from the demuxer) with argument &#x27;16384&#x27;.&#xA;Reading option &#x27;-i&#x27; ... matched as input url with argument &#x27;hw:CARD=C4K,DEV=0&#x27;.&#xA;Reading option &#x27;-acodec&#x27; ... matched as option &#x27;acodec&#x27; (force audio codec (&#x27;copy&#x27; to copy stream)) with argument &#x27;aac&#x27;.&#xA;Reading option &#x27;-s&#x27; ... matched as option &#x27;s&#x27; (set frame size (WxH or abbreviation)) with argument &#x27;1280x720&#x27;.&#xA;Reading option &#x27;-r&#x27; ... matched as option &#x27;r&#x27; (set frame rate (Hz value, fraction or abbreviation)) with argument &#x27;25&#x27;.&#xA;Reading option &#x27;-vcodec&#x27; ... matched as option &#x27;vcodec&#x27; (force video codec (&#x27;copy&#x27; to copy stream)) with argument &#x27;h264_v4l2m2m&#x27;.&#xA;Reading option &#x27;-num_output_buffers&#x27; ... matched as AVOption &#x27;num_output_buffers&#x27; with argument &#x27;32&#x27;.&#xA;Reading option &#x27;-num_capture_buffers&#x27; ... matched as AVOption &#x27;num_capture_buffers&#x27; with argument &#x27;16&#x27;.&#xA;Reading option &#x27;-keyint_min&#x27; ... matched as AVOption &#x27;keyint_min&#x27; with argument &#x27;25&#x27;.&#xA;Reading option &#x27;-force_key_frames&#x27; ... matched as option &#x27;force_key_frames&#x27; (force key frames at specified timestamps) with argument &#x27;expr:gte(t,n_forced*1)&#x27;.&#xA;Reading option &#x27;-g&#x27; ... matched as AVOption &#x27;g&#x27; with argument &#x27;50&#x27;.&#xA;Reading option &#x27;-b:v&#x27; ... matched as option &#x27;b&#x27; (video bitrate (please use -b:v)) with argument &#x27;6M&#x27;.&#xA;Reading option &#x27;-b:a&#x27; ... matched as option &#x27;b&#x27; (video bitrate (please use -b:v)) with argument &#x27;128K&#x27;.&#xA;Reading option &#x27;-pix_fmt&#x27; ... matched as option &#x27;pix_fmt&#x27; (set pixel format) with argument &#x27;nv12&#x27;.&#xA;Reading option &#x27;-f&#x27; ... matched as option &#x27;f&#x27; (force format) with argument &#x27;mpegts&#x27;.&#xA;Reading option &#x27;-muxdelay&#x27; ... matched as option &#x27;muxdelay&#x27; (set the maximum demux-decode delay) with argument &#x27;0&#x27;.&#xA;Reading option &#x27;-muxpreload&#x27; ... matched as option &#x27;muxpreload&#x27; (set the initial demux-decode delay) with argument &#x27;0&#x27;.&#xA;Reading option &#x27;-movflags&#x27; ... matched as AVOption &#x27;movflags&#x27; with argument &#x27;&#x2B;faststart&#x27;.&#xA;Reading option &#x27;/home/pi/Videos/output.mp4&#x27; ... matched as output url.&#xA;Reading option &#x27;-loglevel&#x27; ... matched as option &#x27;loglevel&#x27; (set logging level) with argument &#x27;debug&#x27;.&#xA;Finished splitting the commandline.&#xA;Parsing a group of options: global .&#xA;Applying option y (overwrite output files) with argument 1.&#xA;Applying option nostdin (enable or disable interaction on standard input) with argument 0.&#xA;Applying option loglevel (set logging level) with argument debug.&#xA;Successfully parsed a group of options.&#xA;Parsing a group of options: input url /dev/video0.&#xA;Applying option f (force format) with argument v4l2.&#xA;Applying option thread_queue_size (set the maximum number of queued packets from the demuxer) with argument 16384.&#xA;Successfully parsed a group of options.&#xA;Opening an input file: /dev/video0.&#xA;[video4linux2,v4l2 @ 0x55a0c86b40] fd:3 capabilities:84a00001&#xA;[video4linux2,v4l2 @ 0x55a0c86b40] Current input_channel: 0, input_name: Input 1, input_std: 0&#xA;[video4linux2,v4l2 @ 0x55a0c86b40] Querying the device for the current frame size&#xA;[video4linux2,v4l2 @ 0x55a0c86b40] Setting frame size to 1920x1080&#xA;[video4linux2,v4l2 @ 0x55a0c86b40] Dequeued v4l2 buffer contains corrupted data (0 bytes).&#xA;[video4linux2,v4l2 @ 0x55a0c86b40] All info found Input #0, video4linux2,v4l2, from &#x27;/dev/video0&#x27;:&#xA;  Duration: N/A, start: 0.000000, bitrate: 1988671 kb/s&#xA;    Stream #0:0, 1, 1/1000000: Video: rawvideo, 1 reference frame (YUY2 / 0x32595559), yuyv422, 1920x1080, 0/1, 1988671 kb/s, 59.94 fps, 59.94 tbr, 1000k tbn, 1000k tbc Successfully opened the file.&#xA;Parsing a group of options: input url hw:CARD=C4K,DEV=0.&#xA;Applying option f (force format) with argument alsa.&#xA;Applying option thread_queue_size (set the maximum number of queued packets from the demuxer) with argument 16384.&#xA;Successfully parsed a group of options.&#xA;Opening an input file: hw:CARD=C4K,DEV=0.&#xA;[alsa @ 0x55a0c89630] All info found&#xA;Guessed Channel Layout for Input Stream #1.0 : stereo Input #1, alsa, from &#x27;hw:CARD=C4K,DEV=0&#x27;:&#xA;  Duration: N/A, start: 1608286705.387903, bitrate: 1536 kb/s&#xA;    Stream #1:0, 1, 1/1000000: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s Successfully opened the file.&#xA;Parsing a group of options: output url /home/pi/Videos/output.mp4.&#xA;Applying option acodec (force audio codec (&#x27;copy&#x27; to copy stream)) with argument aac.&#xA;Applying option s (set frame size (WxH or abbreviation)) with argument 1280x720.&#xA;Applying option r (set frame rate (Hz value, fraction or abbreviation)) with argument 25.&#xA;Applying option vcodec (force video codec (&#x27;copy&#x27; to copy stream)) with argument h264_v4l2m2m.&#xA;Applying option force_key_frames (force key frames at specified timestamps) with argument expr:gte(t,n_forced*1).&#xA;Applying option b:v (video bitrate (please use -b:v)) with argument 6M.&#xA;Applying option b:a (video bitrate (please use -b:v)) with argument 128K.&#xA;Applying option pix_fmt (set pixel format) with argument nv12.&#xA;Applying option f (force format) with argument mpegts.&#xA;Applying option muxdelay (set the maximum demux-decode delay) with argument 0.&#xA;Applying option muxpreload (set the initial demux-decode delay) with argument 0.&#xA;Successfully parsed a group of options.&#xA;Opening an output file: /home/pi/Videos/output.mp4.&#xA;[file @ 0x55a0ca7210] Setting default whitelist &#x27;file,crypto,data&#x27;&#xA;Successfully opened the file.&#xA;Stream mapping:&#xA;  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_v4l2m2m))&#xA;  Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native)) cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;    Last message repeated 3 times&#xA;[video4linux2,v4l2 @ 0x55a0c86b40] Dequeued v4l2 buffer contains corrupted data (0 bytes).&#xA;cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;    Last message repeated 12 times&#xA;[video4linux2,v4l2 @ 0x55a0c86b40] Dequeued v4l2 buffer contains corrupted data (0 bytes).&#xA;cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;[video4linux2,v4l2 @ 0x55a0c86b40] Dequeued v4l2 buffer contains corrupted data (0 bytes).&#xA;cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;[video4linux2,v4l2 @ 0x55a0c86b40] Dequeued v4l2 buffer contains corrupted data (0 bytes).&#xA;cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;[video4linux2,v4l2 @ 0x55a0c86b40] Dequeued v4l2 buffer contains corrupted data (0 bytes).&#xA;    Last message repeated 2 times&#xA;cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;[video4linux2,v4l2 @ 0x55a0c86b40] Dequeued v4l2 buffer contains corrupted data (0 bytes).&#xA;    Last message repeated 23 times&#xA;cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;    Last message repeated 1452 times&#xA;[rawvideo @ 0x55a0c89130] PACKET SIZE: 4147200, STRIDE: 3840 detected 4 logical cores [graph 0 input from stream 0:0 @ 0x55a0ca9080] Setting &#x27;video_size&#x27; to value &#x27;1920x1080&#x27;&#xA;[graph 0 input from stream 0:0 @ 0x55a0ca9080] Setting &#x27;pix_fmt&#x27; to value &#x27;1&#x27;&#xA;[graph 0 input from stream 0:0 @ 0x55a0ca9080] Setting &#x27;time_base&#x27; to value &#x27;1/1000000&#x27;&#xA;[graph 0 input from stream 0:0 @ 0x55a0ca9080] Setting &#x27;pixel_aspect&#x27; to value &#x27;0/1&#x27;&#xA;[graph 0 input from stream 0:0 @ 0x55a0ca9080] Setting &#x27;frame_rate&#x27; to value &#x27;7013/117&#x27;&#xA;[graph 0 input from stream 0:0 @ 0x55a0ca9080] w:1920 h:1080 pixfmt:yuyv422 tb:1/1000000 fr:7013/117 sar:0/1&#xA;[scaler_out_0_0 @ 0x55a0cb0060] Setting &#x27;w&#x27; to value &#x27;1280&#x27;&#xA;[scaler_out_0_0 @ 0x55a0cb0060] Setting &#x27;h&#x27; to value &#x27;720&#x27;&#xA;[scaler_out_0_0 @ 0x55a0cb0060] Setting &#x27;flags&#x27; to value &#x27;bicubic&#x27;&#xA;[scaler_out_0_0 @ 0x55a0cb0060] w:1280 h:720 flags:&#x27;bicubic&#x27; interl:0 [format @ 0x55a0cb05b0] Setting &#x27;pix_fmts&#x27; to value &#x27;nv12&#x27;&#xA;[AVFilterGraph @ 0x55a0ca2730] query_formats: 5 queried, 4 merged, 0 already done, 0 delayed&#xA;[scaler_out_0_0 @ 0x55a0cb0060] w:1920 h:1080 fmt:yuyv422 sar:0/1 -> w:1280 h:720 fmt:nv12 sar:0/1 flags:0x4 [h264_v4l2m2m @ 0x55a0ca5610] probing device /dev/video12 [h264_v4l2m2m @ 0x55a0ca5610] driver &#x27;bcm2835-codec&#x27; on card &#x27;bcm2835-codec-isp&#x27; in mplane mode [h264_v4l2m2m @ 0x55a0ca5610] v4l2 capture format not supported [h264_v4l2m2m @ 0x55a0ca5610] probing device /dev/video11 [h264_v4l2m2m @ 0x55a0ca5610] driver &#x27;bcm2835-codec&#x27; on card &#x27;bcm2835-codec-encode&#x27; in mplane mode [h264_v4l2m2m @ 0x55a0ca5610] Using device /dev/video11 [h264_v4l2m2m @ 0x55a0ca5610] driver &#x27;bcm2835-codec&#x27; on card &#x27;bcm2835-codec-encode&#x27; in mplane mode [h264_v4l2m2m @ 0x55a0ca5610] requesting formats: output=NV12 capture=H264 [h264_v4l2m2m @ 0x55a0ca5610] output: NV12 32 buffers initialized: 1280x0720, sizeimage 01382400, bytesperline 00001280 [h264_v4l2m2m @ 0x55a0ca5610] capture: H264 16 buffers initialized: 1280x0720, sizeimage 00524288, bytesperline 00000000 [h264_v4l2m2m @ 0x55a0ca5610] Failed to set number of B-frames: Invalid argument [h264_v4l2m2m @ 0x55a0ca5610] Failed to get number of B-frames [h264_v4l2m2m @ 0x55a0ca5610] Failed to set header mode: Invalid argument [h264_v4l2m2m @ 0x55a0ca5610] Encoder: bit rate = 6000000 [h264_v4l2m2m @ 0x55a0ca5610] Failed to set frame level rate control: Invalid argument [h264_v4l2m2m @ 0x55a0ca5610] Failed to set gop size: Invalid argument [h264_v4l2m2m @ 0x55a0ca5610] Encoder: repeat parameter sets = 1 [h264_v4l2m2m @ 0x55a0ca5610] Encoder Context: id (27), profile (-99), frame rate(25/1), number b-frames (0), gop size (50), bit rate (6000000), qmin (-1), qmax (-1) [h264_v4l2m2m @ 0x55a0ca5610] Failed to set minimum video quantizer scale: Invalid argument [h264_v4l2m2m @ 0x55a0ca5610] Failed to set maximum video quantizer scale: Invalid argument Forced keyframe at time 0.000000 [h264_v4l2m2m @ 0x55a0ca5610] Encoder: force key frame = 0 cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream) cur_dts is invalid st:1 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;[graph_1_in_1_0 @ 0x55a0d465d0] Setting &#x27;time_base&#x27; to value &#x27;1/48000&#x27;&#xA;[graph_1_in_1_0 @ 0x55a0d465d0] Setting &#x27;sample_rate&#x27; to value &#x27;48000&#x27;&#xA;[graph_1_in_1_0 @ 0x55a0d465d0] Setting &#x27;sample_fmt&#x27; to value &#x27;s16&#x27;&#xA;[graph_1_in_1_0 @ 0x55a0d465d0] Setting &#x27;channel_layout&#x27; to value &#x27;0x3&#x27;&#xA;[graph_1_in_1_0 @ 0x55a0d465d0] tb:1/48000 samplefmt:s16 samplerate:48000 chlayout:0x3&#xA;[format_out_0_1 @ 0x55a0d46af0] Setting &#x27;sample_fmts&#x27; to value &#x27;fltp&#x27;&#xA;[format_out_0_1 @ 0x55a0d46af0] Setting &#x27;sample_rates&#x27; to value &#x27;96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025|8000|7350&#x27;&#xA;[format_out_0_1 @ 0x55a0d46af0] auto-inserting filter &#x27;auto_resampler_0&#x27; between the filter &#x27;Parsed_anull_0&#x27; and the filter &#x27;format_out_0_1&#x27;&#xA;[AVFilterGraph @ 0x55a0d45c10] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed&#xA;[auto_resampler_0 @ 0x55a0d47740] [SWR @ 0x55a0d47890] Using s16p internally between filters&#xA;[auto_resampler_0 @ 0x55a0d47740] ch:2 chl:stereo fmt:s16 r:48000Hz -> ch:2 chl:stereo fmt:fltp r:48000Hz [mpegts @ 0x55a0caec00] service 1 using PCR in pid=256, pcr_period=80ms [mpegts @ 0x55a0caec00] muxrate VBR, sdt every 500 ms, pat/pmt every 100 ms Output #0, mpegts, to &#x27;/home/pi/Videos/output.mp4&#x27;:&#xA;  Metadata:&#xA;    encoder         : Lavf58.45.100&#xA;    Stream #0:0, 0, 1/90000: Video: h264 (h264_v4l2m2m), 1 reference frame, nv12(progressive), 1280x720, 0/1, q=-1--1, 6000 kb/s, 25 fps, 90k tbn, 25 tbc&#xA;    Metadata:&#xA;      encoder         : Lavc58.91.100 h264_v4l2m2m&#xA;    Stream #0:1, 0, 1/90000: Audio: aac (LC), 48000 Hz, stereo, fltp, delay 1024, 128 kb/s&#xA;    Metadata:&#xA;      encoder         : Lavc58.91.100 aac&#xA;cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream) cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream) [rawvideo @ 0x55a0c89130] PACKET SIZE: 4147200, STRIDE: 3840 Clipping frame in rate conversion by 0.132942 cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)&#xA;    Last message repeated 17 times&#xA;^Cframe=    2 fps=0.3 q=-0.0 Lsize=     183kB time=00:21:16.64 bitrate=   1.2kbits/s speed= 189x&#xA;video:24kB audio:101kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 46.992252% Input file #0 (/dev/video0):&#xA;  Input stream #0:0 (video): 34 packets read (8294400 bytes); 2 frames decoded;&#xA;  Total: 34 packets (8294400 bytes) demuxed Input file #1 (hw:CARD=C4K,DEV=0):&#xA;  Input stream #1:0 (audio): 2712 packets read (1233148 bytes); 2712 frames decoded (308287 samples);&#xA;  Total: 2712 packets (1233148 bytes) demuxed Output file #0 (/home/pi/Videos/output.mp4):&#xA;  Output stream #0:0 (video): 2 frames encoded; 2 packets muxed (24588 bytes);&#xA;  Output stream #0:1 (audio): 301 frames encoded (308224 samples); 302 packets muxed (103182 bytes);&#xA;  Total: 304 packets (127770 bytes) muxed&#xA;2714 frames successfully decoded, 0 decoding errors [AVIOContext @ 0x55a0ca7100] Statistics: 0 seeks, 1 writeouts [aac @ 0x55a0ca65e0] Qavg: 165.061 Exiting normally, received signal 2.&#xA;

    &#xA;

    can anyone please help me figure this out ?

    &#xA;

    Thanks much !

    &#xA;

    RS

    &#xA;

  • Joining realtime raw PCM streams with ffmpeg and streaming them back out

    15 avril 2024, par Nathan Ladwig

    I am trying to use ffmpeg to join two PCM streams. I have it sorta kinda working but it's not working great.

    &#xA;

    I am using Python to receive two streams from two computers running Scream Audio Driver ( ttps ://github.com/duncanthrax/scream )

    &#xA;

    I am taking them in over UDP and writing them to pipes. The pipes are being received by ffmpeg and mixed, it's writing the mixed stream to another pipe. I'm reading that back in Python and sending it to the target receiver.

    &#xA;

    My ffmpeg command is

    &#xA;

    [&#x27;ffmpeg&#x27;, &#xA;&#x27;-use_wallclock_as_timestamps&#x27;, &#x27;true&#x27;, &#x27;-f&#x27;, &#x27;s24le&#x27;, &#x27;-ac&#x27;, &#x27;2&#x27;, &#x27;-ar&#x27;, &#x27;48000&#x27;, &#x27;-i&#x27;, &#x27;/tmp/ffmpeg-fifo-1&#x27;,&#xA;&#x27;-use_wallclock_as_timestamps&#x27;, &#x27;true&#x27;, &#x27;-f&#x27;, &#x27;s24le&#x27;, &#x27;-ac&#x27;, &#x27;2&#x27;, &#x27;-ar&#x27;, &#x27;48000&#x27;, &#x27;-i&#x27;, &#x27;/tmp/ffmpeg-fifo-2&#x27;,&#xA;&#x27;-filter_complex&#x27;, &#x27;[0]aresample=async=1[a0],[1]aresample=async=1[a1],[a0][a1]amix&#x27;, &#x27;-y&#x27;,&#xA;&#x27;-f&#x27;, &#x27;s24le&#x27;, &#x27;-ac&#x27;, &#x27;2&#x27;, &#x27;-ar&#x27;, &#x27;48000&#x27;, &#x27;/tmp/ffmpeg-fifo-in&#x27;]&#xA;

    &#xA;

    My main issue is that it should be reading ffmpeg-fifo-1 and ffmpeg-fifo-2 asynchronously, but it appears to be not. When the buffers get more than 50 frames out of sync with each other ffmpeg hangs and doesn't recover. I would like to fix this.

    &#xA;

    In this hacky test code the number of frames sent over each stream are counted and empty frames are sent if the count hits 12. This keeps ffmpeg happy.

    &#xA;

    The code below takes in two 48KHz 24-bit stereo PCM streams with Scream's header, mixes them, applies the same header, and sends them back out.

    &#xA;

    It works most of the time. Sometimes I'm getting blasted with static, I think this is when only one or two bytes of a frame are making it to ffmpeg, and it loses track.

    &#xA;

    The header is always 1152 bytes of pcm data with a 5 byte header. It's described in the Scream repo readme

    &#xA;

    This is my header :

    &#xA;

    01 18 02 03 00

    &#xA;

    01 - 48KHz&#xA;18 - Sampling Rate (18h=24d, 24bit)&#xA;02 - 2 channels&#xA;03 00 - WAVEFORMATEXTENSIBLE

    &#xA;

    import socket&#xA;import struct&#xA;import threading&#xA;import os&#xA;import sys&#xA;import time&#xA;import subprocess&#xA;import tempfile&#xA;import select&#xA;&#xA;class Sender(threading.Thread):&#xA;    def __init__(self):&#xA;        super().__init__()&#xA;        TEMPDIR = tempfile.gettempdir() &#x2B; "/"&#xA;        self.fifoin = TEMPDIR &#x2B; "ffmpeg-fifo-in"&#xA;        self.start()&#xA;&#xA;    def run(self):&#xA;        self.fd = open(self.fifoin, "rb")&#xA;        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)&#xA;        while True:&#xA;            try:&#xA;                header = bytes([0x01, 0x18, 0x02, 0x03, 0x00])  # 48khz, 24-bit, stereo&#xA;                data = self.fd.read(1152)&#xA;                sendbuf = header &#x2B; data&#xA;                self.sock.sendto(sendbuf, ("192.168.3.199", 4010))  # Audio sink&#xA;            except Exception as e:&#xA;                print("Except")&#xA;                print(e)&#xA;&#xA;class Receiver(threading.Thread):&#xA;    def __init__(self):&#xA;        super().__init__()&#xA;        TEMPDIR = tempfile.gettempdir() &#x2B; "/"&#xA;        self.fifo1 = TEMPDIR &#x2B; "ffmpeg-fifo-1"&#xA;        self.fifo2 = TEMPDIR &#x2B; "ffmpeg-fifo-2"&#xA;        self.fifoin = TEMPDIR &#x2B; "ffmpeg-fifo-in"&#xA;        self.fifos = [self.fifo1, self.fifo2]&#xA;        try:&#xA;            try:&#xA;                os.remove(self.fifoin)&#xA;            except:&#xA;                pass&#xA;            os.mkfifo(self.fifoin)&#xA;        except:&#xA;            pass&#xA;        self.start()&#xA;        sender=Sender()&#xA;&#xA;    def run(self):&#xA;        ffmpeg_command=[&#x27;ffmpeg&#x27;, &#x27;-use_wallclock_as_timestamps&#x27;, &#x27;true&#x27;, &#x27;-f&#x27;, &#x27;s24le&#x27;, &#x27;-ac&#x27;, &#x27;2&#x27;, &#x27;-ar&#x27;, &#x27;48000&#x27;, &#x27;-i&#x27;, self.fifo1,&#xA;                                  &#x27;-use_wallclock_as_timestamps&#x27;, &#x27;true&#x27;, &#x27;-f&#x27;, &#x27;s24le&#x27;, &#x27;-ac&#x27;, &#x27;2&#x27;, &#x27;-ar&#x27;, &#x27;48000&#x27;, &#x27;-i&#x27;, self.fifo2,&#xA;                                  &#x27;-filter_complex&#x27;, &#x27;[0]aresample=async=1[a0],[1]aresample=async=1[a1],[a0][a1]amix&#x27;, "-y", &#x27;-f&#x27;, &#x27;s24le&#x27;, &#x27;-ac&#x27;, &#x27;2&#x27;, &#x27;-ar&#x27;, &#x27;48000&#x27;, self.fifoin]&#xA;        print(ffmpeg_command)&#xA;&#xA;        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)&#xA;        sock.setsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF,4096)&#xA;        sock.bind(("", 16401))&#xA;&#xA;        recvbuf = bytearray(1157)&#xA;        framecount = [0,0]&#xA;        closed = 1&#xA;        while True:&#xA;            ready = select.select([sock], [], [], .2)&#xA;            if ready[0]:&#xA;                recvbuf, addr = sock.recvfrom(1157)&#xA;                if closed == 1:&#xA;                    for fifo in self.fifos:&#xA;                        try:&#xA;                            try:&#xA;                                os.remove(fifo)&#xA;                            except:&#xA;                                pass&#xA;                            os.mkfifo(fifo)&#xA;                        except:&#xA;                            pass&#xA;                    framecount = [0,0]&#xA;                    print("data, starting ffmpeg")&#xA;                    ffmpeg = subprocess.Popen (ffmpeg_command, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)&#xA;                    fifo1_fd = os.open(self.fifo1, os.O_RDWR)&#xA;                    fifo1_file = os.fdopen(fifo1_fd, &#x27;wb&#x27;, 0)&#xA;                    fifo2_fd = os.open(self.fifo2, os.O_RDWR)&#xA;                    fifo2_file = os.fdopen(fifo2_fd, &#x27;wb&#x27;, 0)&#xA;                    closed = 0&#xA;                    for i in range(0,6):&#xA;                        fifo1_file.write(bytes([0]*1157))&#xA;                        fifo2_file.write(bytes([0]*1157))&#xA;&#xA;                if addr[0] == "192.168.3.199":&#xA;                    fifo1_file.write(recvbuf[5:])&#xA;                    framecount[0] = framecount[0] &#x2B; 1&#xA;&#xA;                if addr[0] == "192.168.3.119":&#xA;                    fifo2_file.write(recvbuf[5:])&#xA;                    framecount[1] = framecount[1] &#x2B; 1&#xA;&#xA;                # Keep buffers roughly in sync while playing&#xA;                targetframes=max(framecount)&#xA;                if targetframes - framecount[0] > 11:&#xA;                    while (targetframes - framecount[0]) > 0:&#xA;                        fifo1_file.write(bytes([0]*1157))&#xA;                        framecount[0] = framecount[0] &#x2B; 1&#xA;&#xA;                if targetframes - framecount[1] > 11:&#xA;                    while (targetframes - framecount[1]) > 0:&#xA;                        fifo2_file.write(bytes([0]*1157))&#xA;                        framecount[1] = framecount[1] &#x2B; 1&#xA;            else:&#xA;                if closed == 0:&#xA;                    ffmpeg.kill()&#xA;                    print("No data, killing ffmpeg")&#xA;                    fifo1_file.close()&#xA;                    fifo2_file.close()&#xA;                    closed = 1&#xA;receiver=Receiver()&#xA;&#xA;while True:&#xA;    time.sleep(50000)&#xA;

    &#xA;

    Does anybody have any pointers on how I can make this better ?

    &#xA;