Recherche avancée

Médias (1)

Mot : - Tags -/book

Autres articles (16)

  • 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

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

  • Gestion générale des documents

    13 mai 2011, par

    MédiaSPIP ne modifie jamais le document original mis en ligne.
    Pour chaque document mis en ligne il effectue deux opérations successives : la création d’une version supplémentaire qui peut être facilement consultée en ligne tout en laissant l’original téléchargeable dans le cas où le document original ne peut être lu dans un navigateur Internet ; la récupération des métadonnées du document original pour illustrer textuellement le fichier ;
    Les tableaux ci-dessous expliquent ce que peut faire MédiaSPIP (...)

Sur d’autres sites (3797)

  • How to Convert 16:9 Video to 9:16 Ratio While Ensuring Speaker Presence in Frame ?

    28 avril 2024, par shreesha

    I am tried so many time to figure out the problem in detecting the face and also it's not so smooth enough to like other tools out there.

    


    So basically I am using python and Yolo in this project but I want the person who is talking and who the ROI (region of interest) is.

    


    Here is the code :

    


    from ultralytics import YOLO
from ultralytics.engine.results import Results
from moviepy.editor import VideoFileClip, concatenate_videoclips
from moviepy.video.fx.crop import crop

# Load the YOLOv8 model
model = YOLO("yolov8n.pt")

# Load the input video
clip = VideoFileClip("short_test.mp4")

tacked_clips = []

for frame_no, frame in enumerate(clip.iter_frames()):
    # Process the frame
    results: list[Results] = model(frame)

    # Get the bounding box of the main object
    if results[0].boxes:
        objects = results[0].boxes
        main_obj = max(
            objects, key=lambda x: x.conf
        )  # Assuming the first detected object is the main one

        x1, y1, x2, y2 = [int(val) for val in main_obj.xyxy[0].tolist()]

        # Calculate the crop region based on the object's position and the target aspect ratio
        w, h = clip.size
        new_w = int(h * 9 / 16)
        new_h = h

        x_center = x2 - x1
        y_center = y2 - y1

        # Adjust x_center and y_center if they would cause the crop region to exceed the bounds
        if x_center + (new_w / 2) > w:
            x_center -= x_center + (new_w / 2) - w
        elif x_center - (new_w / 2) < 0:
            x_center += abs(x_center - (new_w / 2))

        if y_center + (new_h / 2) > h:
            y_center -= y_center + (new_h / 2) - h
        elif y_center - (new_h / 2) < 0:
            y_center += abs(y_center - (new_h / 2))

        # Create a subclip for the current frame
        start_time = frame_no / clip.fps
        end_time = (frame_no + 1) / clip.fps
        subclip = clip.subclip(start_time, end_time)

        # Apply cropping using MoviePy
        cropped_clip = crop(
            subclip, x_center=x_center, y_center=y_center, width=new_w, height=new_h
        )

        tacked_clips.append(cropped_clip)

reframed_clip = concatenate_videoclips(tacked_clips, method="compose")
reframed_clip.write_videofile("output_video.mp4")


    


    So basically I want to fix the face detection with ROI detection where it can detect the face and make that face and the body on to the frame and making sure that the speaker who is speaking is brought to the frame

    


  • FFmpegFrameGrabber and FFmpegFrameRecorder Audio Issue

    20 août 2015, par Sheheryar Chagani

    I am compress an existing camera recorded video using FFmpegframerecorder and ffmpegFrameGrabber.

    The issue is that its audio is not occurring after compression.

    Please note that I am using googlecode.javacv along with javacpp and armeabi in lib folder.

    Below is the code which I have used.

    public void compressVideo(String filePath)

       FrameGrabber grabber = new FFmpegFrameGrabber(filePath);
       grabber.start();
       fileoutput = filePath.replace("trimmed", "compressed");
       // recorder.setAudioCodec(grabber.get);
       FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(fileoutput, 480,
               480, grabber.getAudioChannels());
       recorder.setFrameRate(grabber.getFrameRate());
       recorder.setSampleRate(grabber.getSampleRate());
       recorder.setSampleFormat(grabber.getSampleFormat());
       recorder.setFormat(grabber.getFormat());
       // recorder.setPixelFormat(grabber.getPixelFormat());

       recorder.start();
       Frame frame;
       int count = 0;
       while ((frame = grabber.grabFrame()) != null) {
           if (frame.image != null) {
               publishProgress(count);
               count++;
               IplImage rotateImage = rotate(frame.image, 90);
               IplImage cropImage = resizeImage(rotateImage, 480, 480, true);
               frame.image = cropImage;
               recorder.record(frame);
               if (rotateImage != null)
                   opencv_core.cvReleaseImage(rotateImage);
               if (cropImage != null)
                   opencv_core.cvReleaseImage(cropImage);
           } else {
               recorder.record(frame);
           }

       }
       recorder.stop();
       grabber.stop();
       recorder.release();
       grabber.release();
    }

    IplImage resizeImage(IplImage origImg, int newWidth, int newHeight,
           boolean keepAspectRatio) {

       IplImage outImg;
       int origWidth = 0;
       int origHeight = 0;
       if (origImg != null) {
           origWidth = origImg.width();
           origHeight = origImg.height();
       }
       if (newWidth <= 0 || newHeight <= 0 || origImg == null
               || origWidth <= 0 || origHeight <= 0) {
           // cerr << "ERROR: Bad desired image size of " << newWidth
           // << "x" << newHeight << " in resizeImage().\n";
           return null;
       }

       if (keepAspectRatio) {
           // Resize the image without changing its aspect ratio,
           // by cropping off the edges and enlarging the middle section.
           CvRect r;
           // input aspect ratio
           float origAspect = (origWidth / (float) origHeight);
           // output aspect ratio
           float newAspect = (newWidth / (float) newHeight);
           // crop width to be origHeight * newAspect
           if (origAspect > newAspect) {
               int tw = (origHeight * newWidth) / newHeight;
               // System.out.println((origWidth - tw) / 2+" "+)
               r = opencv_core.cvRect((origWidth - tw) / 2, 0, tw, origHeight);
           } else { // crop height to be origWidth / newAspect
               int th = (origWidth * newHeight) / newWidth;
               r = opencv_core.cvRect(0, (origHeight - th) / 2, origWidth, th);
           }
           IplImage croppedImg = cropImage(origImg, r);

           // Call this function again, with the new aspect ratio image.
           // Will do a scaled image resize with the correct aspect ratio.
           outImg = resizeImage(croppedImg, newWidth, newHeight, false);
           opencv_core.cvReleaseImage(croppedImg);

       } else {

           // Scale the image to the new dimensions,
           // even if the aspect ratio will be changed.
           outImg = opencv_core.cvCreateImage(
                   opencv_core.cvSize(newWidth, newHeight), origImg.depth(),
                   origImg.nChannels());
           if (newWidth > origImg.width() && newHeight > origImg.height()) {
               // Make the image larger
               opencv_core.cvResetImageROI((IplImage) origImg);
               // CV_INTER_LINEAR: good at enlarging.
               // CV_INTER_CUBIC: good at enlarging.
               cvResize(origImg, outImg, CV_INTER_LINEAR);
           } else {
               // Make the image smaller
               opencv_core.cvResetImageROI((IplImage) origImg);
               // CV_INTER_AREA: good at shrinking (decimation) only.
               cvResize(origImg, outImg, CV_INTER_AREA);
           }

       }
       return outImg;
    }

    // Returns a new image that is a cropped version (rectangular cut-out)
    // of the original image.
    IplImage cropImage(IplImage img, CvRect region) {
       IplImage imageCropped;
       opencv_core.CvSize size = new CvSize();

       if (img.width() <= 0 || img.height() <= 0 || region.width() <= 0
               || region.height() <= 0) {
           // cerr << "ERROR in cropImage(): invalid dimensions." << endl;
           return null;
       }

       if (img.depth() != opencv_core.IPL_DEPTH_8U) {
           // cerr << "ERROR in cropImage(): image depth is not 8." << endl;
           return null;
       }

       // Set the desired region of interest.
       opencv_core.cvSetImageROI((IplImage) img, region);
       // Copy region of interest into a new iplImage and return it.
       size.width(region.width());
       size.height(region.height());
       imageCropped = opencv_core.cvCreateImage(size,
               opencv_core.IPL_DEPTH_8U, img.nChannels());
       opencv_core.cvCopy(img, imageCropped); // Copy just the region.

       return imageCropped;
    }

    public IplImage rotate(IplImage image, double angle) {
       IplImage copy = opencv_core.cvCloneImage(image);

       IplImage rotatedImage = opencv_core.cvCreateImage(
               opencv_core.cvGetSize(copy), copy.depth(), copy.nChannels());
       CvMat mapMatrix = opencv_core.cvCreateMat(2, 3, opencv_core.CV_32FC1);

       // Define Mid Point
       CvPoint2D32f centerPoint = new CvPoint2D32f();
       centerPoint.x(copy.width() / 2);
       centerPoint.y(copy.height() / 2);

       // Get Rotational Matrix
       opencv_imgproc.cv2DRotationMatrix(centerPoint, angle, 1.0, mapMatrix);

       // Rotate the Image
       opencv_imgproc.cvWarpAffine(copy, rotatedImage, mapMatrix,
               opencv_imgproc.CV_INTER_CUBIC
                       + opencv_imgproc.CV_WARP_FILL_OUTLIERS,
               opencv_core.cvScalarAll(170));
       opencv_core.cvReleaseImage(copy);
       opencv_core.cvReleaseMat(mapMatrix);
       return rotatedImage;
    }

    I am rotating the video frame and then resizing the frame image.

    The code was working fine 3 days ago but not suddenly it started messing up.

  • Unable to stream video file from MediaMTX media server to browser via WebRTC

    8 juin 2024, par thegreatjedi

    I took over a repository at work. It's a working demo comprising a web server which receives video and camera feeds from a media server (built from the rtsp-simple-server Docker image) via a RTSP relay server and streams the feeds to the client, all deployed via Docker Compose.

    


    I'm trying to switch over to use WebRTC instead. rtsp-simple-server has upgraded into MediaMTX since the time the demo was created 2 years ago. This is the relevant section of the updated Docker Compose configuration :

    


      media-server:
    image: bluenviron/mediamtx:latest-ffmpeg
    expose:
      - 8889
    init: true
    ports:
      - 8889:8889
    restart: unless-stopped
    volumes:
      - type: bind
        source: ./demo/vids
        target: /vids
      - type: bind
        source: ./demo/mediamtx.yml
        target: /mediamtx.yml


    


    Relevant part of the MediaMTX custom configuration in mediamtx.yml :

    


    ###############################################
# Path settings

# Settings in "paths" are applied to specific paths, and the map key
# is the name of the path.
# Any setting in "pathDefaults" can be overridden here.
# It's possible to use regular expressions by using a tilde as prefix,
# for example "~^(test1|test2)$" will match both "test1" and "test2",
# for example "~^prefix" will match all paths that start with "prefix".
paths:
  # example:
  # my_camera:
  #   source: rtsp://my_camera
  ~^demo\d+$:
    runOnDemand: ffmpeg -re -stream_loop -1 -i /vids/$MTX_PATH.mp4 -c:v libvpx -b:v 0 -crf 18 -qmin 18 -qmax 18 -f webm http://localhost:8889/$MTX_PATH/whip

  # Settings under path "all_others" are applied to all paths that
  # do not match another entry.
  all_others:


    


    I've absolutely no experience with WebRTC. This is my first time hearing of this protocol, let alone working with it. From what I understand, I need to convert my demo mp4 videos (which were successfully streaming via RTSP in the previous implementation) to a compatible video codec, so I've opted for VP8.

    


    Before trying to stream the videos into my web server, I tested the stream directly in the browser (tried with both the latest versions of Chrome and Edge). I went to http://localhost:8889/demo0 (which should convert demo0.mp4 to VP8 and then stream it over WebRTC). The video player loaded in the browser but no video data was received and nothing played. After several seconds, the screen displayed "Error : bad status code 400, retrying in some seconds". In the browser console, it showed :

    


    Failed to load resource : the server responded with a status of 400 (Bad Request)

    


    Inside the MediaMTX container's runtime logs, this is what's displayed :

    


    2024-04-02 14:53:08 ffmpeg version 6.1.1 Copyright (c) 2000-2023 the FFmpeg developers
2024-04-02 14:53:08   built with gcc 13.2.1 (Alpine 13.2.1_git20231014) 20231014
2024-04-02 14:53:08   configuration: --prefix=/usr --disable-librtmp --disable-lzma --disable-static --disable-stripping --enable-avfilter --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libmp3lame --enable-libopenmpt --enable-libopus --enable-libplacebo --enable-libpulse --enable-librav1e --enable-librist --enable-libsoxr --enable-libsrt --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-lto=auto --enable-lv2 --enable-openssl --enable-pic --enable-postproc --enable-pthreads --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-vulkan --optflags=-O3 --enable-libjxl --enable-libsvtav1 --enable-libvpl
2024-04-02 14:53:08   libavutil      58. 29.100 / 58. 29.100
2024-04-02 14:53:08   libavcodec     60. 31.102 / 60. 31.102
2024-04-02 14:53:08   libavformat    60. 16.100 / 60. 16.100
2024-04-02 14:53:08   libavdevice    60.  3.100 / 60.  3.100
2024-04-02 14:53:08   libavfilter     9. 12.100 /  9. 12.100
2024-04-02 14:53:08   libswscale      7.  5.100 /  7.  5.100
2024-04-02 14:53:08   libswresample   5.  0.100 /  5.  0.100
2024-04-02 14:53:08   libpostproc    57.  3.100 / 57.  3.100
2024-04-02 14:53:08 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/vids/demo0.mp4':
2024-04-02 14:53:08   Metadata:
2024-04-02 14:53:08     major_brand     : isom
2024-04-02 14:53:08     minor_version   : 512
2024-04-02 14:53:08     compatible_brands: isomiso2mp41
2024-04-02 14:53:08     encoder         : Lavf58.76.100
2024-04-02 14:53:08   Duration: 00:00:03.47, start: 0.000000, bitrate: 1675 kb/s
2024-04-02 14:53:08   Stream #0:0[0x1](und): Video: mpeg1video (mp4v / 0x7634706D), yuv420p(tv, progressive), 640x360 [SAR 1:1 DAR 16:9], 104857 kb/s, 30 fps, 30 tbr, 90k tbn (default)
2024-04-02 14:53:08     Metadata:
2024-04-02 14:53:08       handler_name    : VideoHandler
2024-04-02 14:53:08       vendor_id       : [0][0][0][0]
2024-04-02 14:53:08     Side data:
2024-04-02 14:53:08       cpb: bitrate max/min/avg: 0/0/0 buffer size: 49152 vbv_delay: N/A
2024-04-02 14:53:08 Stream mapping:
2024-04-02 14:53:08   Stream #0:0 -> #0:0 (mpeg1video (native) -> vp8 (libvpx))
2024-04-02 14:53:08 Press [q] to stop, [?] for help
2024-04-02 14:53:08 [libvpx @ 0x7faa8591b8c0] v1.13.1
2024-04-02 14:53:08 [libvpx @ 0x7faa8591b8c0] Bitrate not specified for constrained quality mode, using default of 256kbit/sec
2024-04-02 14:53:08 Output #0, webm, to 'http://localhost:8889/demo0/whip':
2024-04-02 14:53:08   Metadata:
2024-04-02 14:53:08     major_brand     : isom
2024-04-02 14:53:08     minor_version   : 512
2024-04-02 14:53:08     compatible_brands: isomiso2mp41
2024-04-02 14:53:08     encoder         : Lavf60.16.100
2024-04-02 14:53:08   Stream #0:0(und): Video: vp8, yuv420p(tv, progressive), 640x360 [SAR 1:1 DAR 16:9], q=2-31, 256 kb/s, 30 fps, 1k tbn (default)
2024-04-02 14:53:08     Metadata:
2024-04-02 14:53:08       handler_name    : VideoHandler
2024-04-02 14:53:08       vendor_id       : [0][0][0][0]
2024-04-02 14:53:08       encoder         : Lavc60.31.102 libvpx
2024-04-02 14:53:08     Side data:
2024-04-02 14:53:08       cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
2024-04-02 14:53:18 2024/04/02 06:53:18 INF [path demo0] runOnDemand command stopped: timed out
2024-04-02 14:53:18 2024/04/02 06:53:18 INF [WebRTC] [session 0f460c76] closed: source of path 'demo0' has timed out
[out#0/webm @ 0x7faa859487c0] video:272kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.042856%
2024-04-02 14:53:18 frame=  315 fps= 32 q=18.0 Lsize=     275kB time=00:00:10.46 bitrate= 215.1kbits/s speed=1.05x    
2024-04-02 14:53:18 Exiting normally, received signal 2.


    


    I'm not sure what this is supposed to mean ? Why isn't the server able to stream this 3-second, 709kb video even once ? The browser connected to the server and the URL successfully, but no data was being transferred.

    


    Just in case, I decided to manually convert all of my mp4 files to webm using ffmpeg, and verified with Window's media player that the webm videos work. Then, I modified MediaMTX's configuration to stream the webm videos directly :

    


    paths:
  # example:
  # my_camera:
  #   source: rtsp://my_camera
  ~^demo\d+$:
    runOnDemand: ffmpeg -re -stream_loop -1 -i /vids/$MTX_PATH.webm -c copy -f webm http://localhost:8889/$MTX_PATH/whip


    


    However, the error persists :

    


    2024-04-02 15:03:58 ffmpeg version 6.1.1 Copyright (c) 2000-2023 the FFmpeg developers
2024-04-02 15:03:58   built with gcc 13.2.1 (Alpine 13.2.1_git20231014) 20231014
2024-04-02 15:03:58   configuration: --prefix=/usr --disable-librtmp --disable-lzma --disable-static --disable-stripping --enable-avfilter --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libmp3lame --enable-libopenmpt --enable-libopus --enable-libplacebo --enable-libpulse --enable-librav1e --enable-librist --enable-libsoxr --enable-libsrt --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-lto=auto --enable-lv2 --enable-openssl --enable-pic --enable-postproc --enable-pthreads --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-vulkan --optflags=-O3 --enable-libjxl --enable-libsvtav1 --enable-libvpl
2024-04-02 15:03:58   libavutil      58. 29.100 / 58. 29.100
2024-04-02 15:03:58   libavcodec     60. 31.102 / 60. 31.102
2024-04-02 15:03:58   libavformat    60. 16.100 / 60. 16.100
2024-04-02 15:03:58   libavdevice    60.  3.100 / 60.  3.100
2024-04-02 15:03:58   libavfilter     9. 12.100 /  9. 12.100
2024-04-02 15:03:58   libswscale      7.  5.100 /  7.  5.100
2024-04-02 15:03:58   libswresample   5.  0.100 /  5.  0.100
2024-04-02 15:03:58   libpostproc    57.  3.100 / 57.  3.100
2024-04-02 15:03:58 Input #0, matroska,webm, from '/vids/demo0.webm':
2024-04-02 15:03:58   Metadata:
2024-04-02 15:03:58     COMPATIBLE_BRANDS: isomiso2mp41
2024-04-02 15:03:58     MAJOR_BRAND     : isom
2024-04-02 15:03:58     MINOR_VERSION   : 512
2024-04-02 15:03:58     ENCODER         : Lavf60.16.100
2024-04-02 15:03:58   Duration: 00:00:03.47, start: 0.000000, bitrate: 217 kb/s
2024-04-02 15:03:58   Stream #0:0: Video: vp8, yuv420p(tv, progressive), 640x360, SAR 1:1 DAR 16:9, 30 fps, 30 tbr, 1k tbn (default)
2024-04-02 15:03:58     Metadata:
2024-04-02 15:03:58       HANDLER_NAME    : VideoHandler
2024-04-02 15:03:58       VENDOR_ID       : [0][0][0][0]
2024-04-02 15:03:58       ENCODER         : Lavc60.31.102 libvpx
2024-04-02 15:03:58       DURATION        : 00:00:03.466000000
2024-04-02 15:03:58 Output #0, webm, to 'http://localhost:8889/demo0/whip':
2024-04-02 15:03:58   Metadata:
2024-04-02 15:03:58     COMPATIBLE_BRANDS: isomiso2mp41
2024-04-02 15:03:58     MAJOR_BRAND     : isom
2024-04-02 15:03:58     MINOR_VERSION   : 512
2024-04-02 15:03:58     encoder         : Lavf60.16.100
2024-04-02 15:03:58   Stream #0:0: Video: vp8, yuv420p(tv, progressive), 640x360 [SAR 1:1 DAR 16:9], q=2-31, 30 fps, 30 tbr, 1k tbn (default)
2024-04-02 15:03:58     Metadata:
2024-04-02 15:03:58       HANDLER_NAME    : VideoHandler
2024-04-02 15:03:58       VENDOR_ID       : [0][0][0][0]
2024-04-02 15:03:58       ENCODER         : Lavc60.31.102 libvpx
2024-04-02 15:03:58       DURATION        : 00:00:03.466000000
2024-04-02 15:03:58 Stream mapping:
2024-04-02 15:03:58   Stream #0:0 -> #0:0 (copy)
2024-04-02 15:03:58 Press [q] to stop, [?] for help
2024-04-02 15:04:08 2024/04/02 07:04:08 INF [path demo0] runOnDemand command stopped: timed out
2024-04-02 15:04:08 2024/04/02 07:04:08 INF [WebRTC] [session 829664cb] closed: source of path 'demo0' has timed out
[out#0/webm @ 0x7f04b00515c0] video:281kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.023511%
2024-04-02 15:04:08 size=     284kB time=00:00:10.49 bitrate= 221.3kbits/s speed=1.05x    
2024-04-02 15:04:08 Exiting normally, received signal 2.


    


    This is the same when I try to stream my other videos (demo1.mp4, demo2.mp4 etc.). What am I doing wrong ?