Recherche avancée

Médias (2)

Mot : - Tags -/kml

Autres articles (75)

  • Emballe médias : à quoi cela sert ?

    4 février 2011, par

    Ce plugin vise à gérer des sites de mise en ligne de documents de tous types.
    Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;

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

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

Sur d’autres sites (4497)

  • constructing an ffmpeg script for use in Xcode/swift project

    21 octobre 2019, par NCrusher

    I’m going back to the drawing board with this post because I’ve been through so much trial and error over the last day with this issue that the information I posted earlier is no longer relevant.

    I’ve only been learning both Swift and FFmpeg for a few weeks, and I’ve just exhausted my ability to troubleshoot this.

    I’m maybe 90% certain this is a problem with my ffmpeg script, rather than with the Swift component. But I think it’s complicated by what characters need special formatting in Swift (particularly mathematical operatives.)

    I started off using a method in Xcode modeled after this post, which Xcode actually managed to guide me through updating for current versions of swift without breaking. Which left me with this :

    func ffmpegConvert(inputPath: String, filters: String, outputPath: String) {
       guard let launchPath = Bundle.main.path(forResource: "ffmpeg", ofType: "") else { return }
       do {
           let convertTask: Process = Process()
           convertTask.launchPath = launchPath
           convertTask.arguments = [
               "-i", inputPath,
               filters,
               outputPath
           ]
           convertTask.standardInput = FileHandle.nullDevice
           convertTask.launch()
           convertTask.waitUntilExit()
       }
    }

    I call this function when I click the "Start Conversion" button on my app. Like I said, that part seems to work fine. The problem is either in the way ffmpeg is being called by the app, or with the construction of the strings in my arguments array.

    The inputFilePath and outputFilePath strings are self-explanatory. Both of them are perfectly acceptably formatted filepath strings.

    The filters is a little tougher. My app has five conversion options and a different filter set for each one. One is as simple as -c copy and the most complex is -c:a libmp3lame -ac 1 -ar 22050 -q:a 9 (I’m working with audiobooks so I don’t need a lot of complexity in my arguments.

    The app appears to be launching ffmpeg perfectly. But the console keeps giving me errors. And the errors keep changing depending on what I try. Here’s what I’ve been through so far :

    var inputFilePath = "/Volumes/CSW External/ffmpeg/diamonds.aac"
    var ffmpegFilters = "-c copy"
    var outputFilePath = "/Volumes/CSW External/ffmpeg/diamonds.m4b"

    Result :

    Unrecognized option ’c copy’.
    Error splitting the argument list : Option not found

    Next attempt, I tried var ffmpegFilters = "--c copy". Result was the same error.

    Then I tried var ffmpegFilters = " -c copy" and it actually read the metadata from my file before throwing a different error at me :

    Unable to find a suitable output format for ’ -c copy’ -c copy :
    Invalid argument

    I’m assuming that the fact that it read the metadata before throwing a different error at me means I made...some form of progress ?

    I spent a few hours researching that particular error and why people might be getting it and couldn’t find a situation that was analogous to what I was trying to do. Mostly people were encountering it from the command line and/or other operating systems. So no help there.

    At that point, since I was just throwing things at the wall to see what might stick, I decided to throw the whole command, inputPath / ffMpegFilters / outputPath into a single string to see if I could make that work (under the logic that if it did, I could narrow the cause of my trouble down to the way the separate strings are being constructed by XCode.)

    I tried it both with the whitespace in the filepath and with the whitespace escaped out (using double \ as required by Swift.) The ffmpeg log came displayed a perfectly valid

    Doing so took me back to the first error I got :

    Unrecognized option ’-c copy’.
    Error splitting the argument list : Option not found

    So then I started researching THAT error. Some of the discussions I came across indicated that the problem was that the arguments couldn’t all be in a single string, they needed to be split up and put in an array. Which I could see for a longer argument, but -c copy shouldn’t need that.

    But I decided to give it a go. Formerly my method for constructing the string of arguments would have looked like this

    func conversionSelection() {
       if inputFileUrl != nil {
           let conversionChoice = conversionOptionsPopup.indexOfSelectedItem
           switch conversionChoice {
               case 1 :
                   outputExtension = ".mp3"
                   ffmpegFilters = "-c:a libmp3lame -ac 1 -ar 22050 -q:a 9"
               (...case 2, 3, 4, default, etc)
           }
       }
    }

    Now it looks more like this :

    func conversionSelection() {
       if inputFileUrl != nil {
           let conversionChoice = conversionOptionsPopup.indexOfSelectedItem
           switch conversionChoice {
               case 1 :
                   outputExtension = ".mp3"
                   ffmpegCodec = "-c:a libmp3lame"
                   ffmpegChannels = "-ac 1"
                   ffmpegSampling = "-ar 22050"
                   ffmpegBitrate = "-q:a 9"
               (case 2, case 3, case 4, default, etc)
           }
       }
    }

    Unfortunately, this just brought me full circle. If I try to use -c:a libmp3lame or --c:a libmp3lame I get the Error splitting the argument list: Option not found error. Interestingly, however, it gives the argument with relation to the ffmpegSampling argument, which is a slight difference.

    If I put a whitespace in front of it -c:a libmp3lame it will get far enough into the process to read the input file metadata, then I get this :

    Unable to find a suitable output format for ’ -c:a libmp3lame’ -c:a
    libmp3lame : Invalid argument

    I’m stumped. I thought this was going to be an easy fix, but I’ve been at it almost a full day with all the trial and error, and nothing is working, and I’ve exhausted my newbie understanding of both Swift and ffmpeg.

  • Segmentation fault with avcodec_encode_video2() while encoding H.264

    16 juillet 2015, par Baris Demiray

    I’m trying to convert a cv::Mat to an AVFrame to encode it then in H.264 and wanted to start from a simple example, as I’m a newbie in both. So I first read in a JPEG file, and then do the pixel format conversion with sws_scale() from AV_PIX_FMT_BGR24 to AV_PIX_FMT_YUV420P keeping the dimensions the same, and it all goes fine until I call avcodec_encode_video2().

    I read quite a few discussions regarding an AVFrame allocation and the question segmetation fault while avcodec_encode_video2 seemed like a match but I just can’t see what I’m missing or getting wrong.

    Here is the minimal code that you can reproduce the crash, it should be compiled with,

    g++ -o OpenCV2FFmpeg OpenCV2FFmpeg.cpp -lopencv_imgproc -lopencv_highgui -lopencv_core -lswscale -lavutil -lavcodec -lavformat

    It’s output on my system,

    cv::Mat [width=420, height=315, depth=0, channels=3, step=1260]
    I'll soon crash..
    Segmentation fault

    And that sample.jpg file’s details by identify tool,

    ~temporary/sample.jpg JPEG 420x315 420x315+0+0 8-bit sRGB 38.3KB 0.000u 0:00.000

    Please note that I’m trying to create a video out of a single image, just to keep things simple.

    #include <iostream>
    #include <cassert>
    using namespace std;

    extern "C" {
       #include <libavcodec></libavcodec>avcodec.h>
       #include <libswscale></libswscale>swscale.h>
       #include <libavformat></libavformat>avformat.h>
    }

    #include <opencv2></opencv2>core/core.hpp>
    #include <opencv2></opencv2>highgui/highgui.hpp>

    const string TEST_IMAGE = "/home/baris/temporary/sample.jpg";

    int main(int /*argc*/, char** argv)
    {
       av_register_all();
       avcodec_register_all();

       /**
        * Initialise the encoder
        */
       AVCodec *h264encoder = avcodec_find_encoder(AV_CODEC_ID_H264);
       AVFormatContext *cv2avFormatContext = avformat_alloc_context();

       /**
        * Create a stream and allocate frames
        */
       AVStream *h264outputstream = avformat_new_stream(cv2avFormatContext, h264encoder);
       avcodec_get_context_defaults3(h264outputstream->codec, h264encoder);
       AVFrame *sourceAvFrame = av_frame_alloc(), *destAvFrame = av_frame_alloc();
       int got_frame;

       /**
        * Pixel formats for the input and the output
        */
       AVPixelFormat sourcePixelFormat = AV_PIX_FMT_BGR24;
       AVPixelFormat destPixelFormat = AV_PIX_FMT_YUV420P;

       /**
        * Create cv::Mat
        */
       cv::Mat cvFrame = cv::imread(TEST_IMAGE, CV_LOAD_IMAGE_COLOR);
       int width = cvFrame.size().width, height = cvFrame.size().height;
       cerr &lt;&lt; "cv::Mat [width=" &lt;&lt; width &lt;&lt; ", height=" &lt;&lt; height &lt;&lt; ", depth=" &lt;&lt; cvFrame.depth() &lt;&lt; ", channels=" &lt;&lt; cvFrame.channels() &lt;&lt; ", step=" &lt;&lt; cvFrame.step &lt;&lt; "]" &lt;&lt; endl;

       h264outputstream->codec->pix_fmt = destPixelFormat;
       h264outputstream->codec->width = cvFrame.cols;
       h264outputstream->codec->height = cvFrame.rows;

       /**
        * Prepare the conversion context
        */
       SwsContext *bgr2yuvcontext = sws_getContext(width, height,
                                                   sourcePixelFormat,
                                                   h264outputstream->codec->width, h264outputstream->codec->height,
                                                   h264outputstream->codec->pix_fmt,
                                                   SWS_BICUBIC, NULL, NULL, NULL);

       /**
        * Convert and encode frames
        */
       for (uint i=0; i &lt; 250; i++)
       {
           /**
            * Allocate source frame, i.e. input to sws_scale()
            */
           avpicture_alloc((AVPicture*)sourceAvFrame, sourcePixelFormat, width, height);

           for (int h = 0; h &lt; height; h++)
               memcpy(&amp;(sourceAvFrame->data[0][h*sourceAvFrame->linesize[0]]), &amp;(cvFrame.data[h*cvFrame.step]), width*3);

           /**
            * Allocate destination frame, i.e. output from sws_scale()
            */
           avpicture_alloc((AVPicture *)destAvFrame, destPixelFormat, width, height);

           sws_scale(bgr2yuvcontext, sourceAvFrame->data, sourceAvFrame->linesize,
                     0, height, destAvFrame->data, destAvFrame->linesize);

           /**
            * Prepare an AVPacket for encoded output
            */
           AVPacket avEncodedPacket;
           av_init_packet(&amp;avEncodedPacket);
           avEncodedPacket.data = NULL;
           avEncodedPacket.size = 0;
           // av_free_packet(&amp;avEncodedPacket); w/ or w/o result doesn't change

           cerr &lt;&lt; "I'll soon crash.." &lt;&lt; endl;
           if (avcodec_encode_video2(h264outputstream->codec, &amp;avEncodedPacket, destAvFrame, &amp;got_frame) &lt; 0)
               exit(1);

           cerr &lt;&lt; "Checking if we have a frame" &lt;&lt; endl;
           if (got_frame)
               av_write_frame(cv2avFormatContext, &amp;avEncodedPacket);

           av_free_packet(&amp;avEncodedPacket);
           av_frame_free(&amp;sourceAvFrame);
           av_frame_free(&amp;destAvFrame);
       }
    }
    </cassert></iostream>

    Thanks in advance !

    EDIT : And the stack trace after the crash,

    Thread 2 (Thread 0x7fffe5506700 (LWP 10005)):
    #0  0x00007ffff4bf6c5d in poll () at /lib64/libc.so.6
    #1  0x00007fffe9073268 in  () at /usr/lib64/libusb-1.0.so.0
    #2  0x00007ffff47010a4 in start_thread () at /lib64/libpthread.so.0
    #3  0x00007ffff4bff08d in clone () at /lib64/libc.so.6

    Thread 1 (Thread 0x7ffff7f869c0 (LWP 10001)):
    #0  0x00007ffff5ecc7dc in avcodec_encode_video2 () at /usr/lib64/libavcodec.so.56
    #1  0x00000000004019b6 in main(int, char**) (argv=0x7fffffffd3d8) at ../src/OpenCV2FFmpeg.cpp:99

    EDIT2 : Problem was that I hadn’t avcodec_open2() the codec as spotted by Ronald. Final version of the code is at https://github.com/barisdemiray/opencv2ffmpeg/, with leaks and probably other problems hoping that I’ll improve it while learning both libraries.

  • Why does File upload for moving image and Audio to tmp PHP folder work on Windows but only image upload portion works on Mac using MAMP ?

    31 mai 2021, par Yazdan

    So according to my colleague who tested this on Windows says it works perfectly fine , but in my case when I use it on a Mac with MAMP for Moodle , the image files get uploaded to the correct destination folder without an issue whereas the audio files don't move from the tmp folder to the actual destination folder and to check if this was the case ... I just changed and gave a fixed path instead of $fileTmpLoc and the file made it to the correct destination. Sorry I know the first half of the code isn't the main issue but I still wanted to post the whole code so one could understand it easily, moreover I am just beginning to code so please "have a bit of patience with me" . Thanks in advance

    &#xA;

    &#xA;// this file contains upload function &#xA;// checks if the file exists in server&#xA;include("../db/database.php");&#xA;require_once(dirname(__FILE__) . &#x27;/../../../config.php&#x27;);&#xA;global $IP;&#xA;&#xA;$ajaxdata = $_POST[&#x27;mediaUpload&#x27;];&#xA;&#xA;$FILENAME = $ajaxdata[1];&#xA;$IMAGE=$ajaxdata[0];&#xA;// an array to check which category the media belongs too&#xA;$animal= array("bird","cat","dog","horse","sheep","cow","elephant","bear","giraffe","zebra");&#xA;$allowedExts = array("mp3","wav");&#xA;$temp = explode(".", $_FILES["audio"]["name"]);&#xA;$extension = end($temp);&#xA;&#xA;&#xA;&#xA;$test = $_FILES["audio"]["type"]; &#xA;&#xA;&#xA;if (&#xA;   $_FILES["audio"]["type"] == "audio/wav"||&#xA;   $_FILES["audio"]["type"] == "audio/mp3"||&#xA;   $_FILES["audio"]["type"] == "audio/mpeg"&#xA;   &amp;&amp;&#xA;   in_array($extension, $allowedExts)&#xA;   )&#xA;   {&#xA;&#xA;       // if the name detected by object detection is present in the animal array&#xA;       // then initialize target path to animal database or to others&#xA;       if (in_array($FILENAME, $animal)) &#xA;       { &#xA;           $image_target_dir = "image_dir/";&#xA;           $audio_target_dir = "audio_dir/";&#xA;       } &#xA;       else&#xA;       { &#xA;           $image_target_dir = "other_image_dir/";&#xA;           $audio_target_dir = "other_audio_dir/";&#xA;       } &#xA;       // Get file path&#xA;       &#xA;       $img = $IMAGE;&#xA;       // decode base64 image&#xA;       $img = str_replace(&#x27;data:image/png;base64,&#x27;, &#x27;&#x27;, $img);&#xA;       $img = str_replace(&#x27; &#x27;, &#x27;&#x2B;&#x27;, $img);&#xA;       $image_data = base64_decode($img);&#xA;&#xA;       //$extension  = pathinfo( $_FILES["fileUpload"]["name"], PATHINFO_EXTENSION ); // jpg&#xA;       $image_extension = "png";&#xA;       $image_target_file =$image_target_dir . basename($FILENAME . "." . $image_extension);&#xA;       $image_file_upload = "http://localhost:8888/moodle310/blocks/testblock/classes/".$image_target_file;&#xA;       &#xA;       &#xA;       $audio_extension ="mp3";&#xA;       $audio_target_file= $audio_target_dir . basename($FILENAME. "." . $audio_extension) ;&#xA;       $audio_file_upload = "http://localhost:8888/moodle310/blocks/testblock/classes/".$audio_target_file;&#xA;&#xA;       // file size limit&#xA;       if(($_FILES["audio"]["size"])&lt;=51242880)&#xA;       {&#xA;&#xA;           $fileName = $_FILES["audio"]["name"]; // The file name&#xA;           $fileTmpLoc = $_FILES["audio"]["tmp_name"]; // File in the PHP tmp folder&#xA;           $fileType = $_FILES["audio"]["type"]; // The type of file it is&#xA;           $fileSize = $_FILES["audio"]["size"]; // File size in bytes&#xA;           $fileErrorMsg = $_FILES["audio"]["error"]; // 0 for false... and 1 for true&#xA;           &#xA;           if (in_array($FILENAME, $animal)) &#xA;           { &#xA;               $sql = "INSERT INTO mdl_media_animal (animal_image_path,animal_name,animal_audio_path) VALUES (&#x27;$image_file_upload&#x27;,&#x27;$FILENAME&#x27;,&#x27;$audio_file_upload&#x27;)";&#xA;           } else {&#xA;               $sql = "INSERT INTO mdl_media_others (others_image_path,others_name,others_audio_path) VALUES (&#x27;$image_file_upload&#x27;,&#x27;$FILENAME&#x27;,&#x27;$audio_file_upload&#x27;)";&#xA;           }&#xA;&#xA;           // if file exists&#xA;           if (file_exists($audio_target_file) || file_exists($image_target_file)) {&#xA;               echo "alert";&#xA;           } else {&#xA;               // write image file&#xA;               if (file_put_contents($image_target_file, $image_data) ) {&#xA;                   // ffmpeg to write audio file&#xA;                   $output = shell_exec("ffmpeg -i $fileTmpLoc -ab 160k -ac 2 -ar 44100 -vn $audio_target_file");&#xA;                   echo $output;&#xA;               &#xA;                   // $stmt = $conn->prepare($sql);&#xA;                   $db = mysqli_connect("localhost", "root", "root", "moodle310"); &#xA;                   // echo $sql;&#xA;                   if (!$db) {&#xA;                       echo "nodb";&#xA;                       die("Connection failed: " . mysqli_connect_error());&#xA;                   }&#xA;                   // echo"sucess";&#xA;                   if(mysqli_query($db, $sql)){&#xA;                   // if($stmt->execute()){&#xA;                       echo $fileTmpLoc;&#xA;                       echo "sucess";  &#xA;                       echo $output;&#xA;                   }&#xA;                   else {&#xA;                       // echo "Error: " . $sql . "<br />" . mysqli_error($conn);&#xA;                       echo "failed";&#xA;                   }&#xA;&#xA;               }else {&#xA;                   echo "failed";&#xA;               }&#xA;&#xA;               &#xA;           &#xA;           &#xA;           }&#xA;   &#xA;    // $test = "ffmpeg -i $outputfile -ab 160k -ac 2 -ar 44100 -vn bub.wav";&#xA;       } else&#xA;       {&#xA;         echo "File size exceeds 5 MB! Please try again!";&#xA;       }&#xA;}&#xA;else&#xA;{&#xA;   echo "PHP! Not a video! ";//.$extension." ".$_FILES["uploadimage"]["type"];&#xA;   }&#xA;&#xA;?>&#xA;

    &#xA;

    I am a student learning frontend but a project of mine requires a fair bit of backend. So forgive me if my question sounds silly.

    &#xA;

    What I meant by manually overriding it was creating another folder and a index.php file with echo "hello"; $output = shell_exec("ffmpeg -i Elephant.mp3 -ab 160k -ac 2 -ar 44100 -vn bub.mp3"); echo $output; so only yes in this case Elephant.mp3 was changed as the initial tmp path so in this case as suggested by Mr.CBroe the permissons shouldn't be an issue.

    &#xA;

    Okay I checked my Apache_error.logonly to find out ffmpeg is indeed the culprit ... I had installed ffmpeg globally so I am not sure if it is an access problem but here is a snippet of the log

    &#xA;

    I checked my php logs and found out that FFmpeg is the culprit.&#xA;Attached is a short log file

    &#xA;

    [Mon May 31 18:11:33 2021] [notice] caught SIGTERM, shutting down&#xA;[Mon May 31 18:11:40 2021] [notice] Digest: generating secret for digest authentication ...&#xA;[Mon May 31 18:11:40 2021] [notice] Digest: done&#xA;[Mon May 31 18:11:40 2021] [notice] Apache/2.2.34 (Unix) mod_ssl/2.2.34 OpenSSL/1.0.2o PHP/7.2.10 configured -- resuming normal operations&#xA;sh: ffmpeg: command not found&#xA;sh: ffmpeg: command not found&#xA;sh: ffmpeg: command not found&#xA;

    &#xA;