
Recherche avancée
Médias (2)
-
Granite de l’Aber Ildut
9 septembre 2011, par
Mis à jour : Septembre 2011
Langue : français
Type : Texte
-
Géodiversité
9 septembre 2011, par ,
Mis à jour : Août 2018
Langue : français
Type : Texte
Autres articles (75)
-
Emballe médias : à quoi cela sert ?
4 février 2011, parCe 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, parLe 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, parMediaSPIP 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 NCrusherI’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 foundNext 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 argumentI’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 foundSo 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 theError 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 argumentI’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 DemirayI’m trying to convert a
cv::Mat
to anAVFrame
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 withsws_scale()
fromAV_PIX_FMT_BGR24
toAV_PIX_FMT_YUV420P
keeping the dimensions the same, and it all goes fine until I callavcodec_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 faultAnd that
sample.jpg
file’s details byidentify
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 << "cv::Mat [width=" << width << ", height=" << height << ", depth=" << cvFrame.depth() << ", channels=" << cvFrame.channels() << ", step=" << cvFrame.step << "]" << 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 < 250; i++)
{
/**
* Allocate source frame, i.e. input to sws_scale()
*/
avpicture_alloc((AVPicture*)sourceAvFrame, sourcePixelFormat, width, height);
for (int h = 0; h < height; h++)
memcpy(&(sourceAvFrame->data[0][h*sourceAvFrame->linesize[0]]), &(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(&avEncodedPacket);
avEncodedPacket.data = NULL;
avEncodedPacket.size = 0;
// av_free_packet(&avEncodedPacket); w/ or w/o result doesn't change
cerr << "I'll soon crash.." << endl;
if (avcodec_encode_video2(h264outputstream->codec, &avEncodedPacket, destAvFrame, &got_frame) < 0)
exit(1);
cerr << "Checking if we have a frame" << endl;
if (got_frame)
av_write_frame(cv2avFormatContext, &avEncodedPacket);
av_free_packet(&avEncodedPacket);
av_frame_free(&sourceAvFrame);
av_frame_free(&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:99EDIT2 : 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 YazdanSo 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


// this file contains upload function 
// checks if the file exists in server
include("../db/database.php");
require_once(dirname(__FILE__) . '/../../../config.php');
global $IP;

$ajaxdata = $_POST['mediaUpload'];

$FILENAME = $ajaxdata[1];
$IMAGE=$ajaxdata[0];
// an array to check which category the media belongs too
$animal= array("bird","cat","dog","horse","sheep","cow","elephant","bear","giraffe","zebra");
$allowedExts = array("mp3","wav");
$temp = explode(".", $_FILES["audio"]["name"]);
$extension = end($temp);



$test = $_FILES["audio"]["type"]; 


if (
 $_FILES["audio"]["type"] == "audio/wav"||
 $_FILES["audio"]["type"] == "audio/mp3"||
 $_FILES["audio"]["type"] == "audio/mpeg"
 &&
 in_array($extension, $allowedExts)
 )
 {

 // if the name detected by object detection is present in the animal array
 // then initialize target path to animal database or to others
 if (in_array($FILENAME, $animal)) 
 { 
 $image_target_dir = "image_dir/";
 $audio_target_dir = "audio_dir/";
 } 
 else
 { 
 $image_target_dir = "other_image_dir/";
 $audio_target_dir = "other_audio_dir/";
 } 
 // Get file path
 
 $img = $IMAGE;
 // decode base64 image
 $img = str_replace('data:image/png;base64,', '', $img);
 $img = str_replace(' ', '+', $img);
 $image_data = base64_decode($img);

 //$extension = pathinfo( $_FILES["fileUpload"]["name"], PATHINFO_EXTENSION ); // jpg
 $image_extension = "png";
 $image_target_file =$image_target_dir . basename($FILENAME . "." . $image_extension);
 $image_file_upload = "http://localhost:8888/moodle310/blocks/testblock/classes/".$image_target_file;
 
 
 $audio_extension ="mp3";
 $audio_target_file= $audio_target_dir . basename($FILENAME. "." . $audio_extension) ;
 $audio_file_upload = "http://localhost:8888/moodle310/blocks/testblock/classes/".$audio_target_file;

 // file size limit
 if(($_FILES["audio"]["size"])<=51242880)
 {

 $fileName = $_FILES["audio"]["name"]; // The file name
 $fileTmpLoc = $_FILES["audio"]["tmp_name"]; // File in the PHP tmp folder
 $fileType = $_FILES["audio"]["type"]; // The type of file it is
 $fileSize = $_FILES["audio"]["size"]; // File size in bytes
 $fileErrorMsg = $_FILES["audio"]["error"]; // 0 for false... and 1 for true
 
 if (in_array($FILENAME, $animal)) 
 { 
 $sql = "INSERT INTO mdl_media_animal (animal_image_path,animal_name,animal_audio_path) VALUES ('$image_file_upload','$FILENAME','$audio_file_upload')";
 } else {
 $sql = "INSERT INTO mdl_media_others (others_image_path,others_name,others_audio_path) VALUES ('$image_file_upload','$FILENAME','$audio_file_upload')";
 }

 // if file exists
 if (file_exists($audio_target_file) || file_exists($image_target_file)) {
 echo "alert";
 } else {
 // write image file
 if (file_put_contents($image_target_file, $image_data) ) {
 // ffmpeg to write audio file
 $output = shell_exec("ffmpeg -i $fileTmpLoc -ab 160k -ac 2 -ar 44100 -vn $audio_target_file");
 echo $output;
 
 // $stmt = $conn->prepare($sql);
 $db = mysqli_connect("localhost", "root", "root", "moodle310"); 
 // echo $sql;
 if (!$db) {
 echo "nodb";
 die("Connection failed: " . mysqli_connect_error());
 }
 // echo"sucess";
 if(mysqli_query($db, $sql)){
 // if($stmt->execute()){
 echo $fileTmpLoc;
 echo "sucess"; 
 echo $output;
 }
 else {
 // echo "Error: " . $sql . "<br />" . mysqli_error($conn);
 echo "failed";
 }

 }else {
 echo "failed";
 }

 
 
 
 }
 
 // $test = "ffmpeg -i $outputfile -ab 160k -ac 2 -ar 44100 -vn bub.wav";
 } else
 {
 echo "File size exceeds 5 MB! Please try again!";
 }
}
else
{
 echo "PHP! Not a video! ";//.$extension." ".$_FILES["uploadimage"]["type"];
 }

?>



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.


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 caseElephant.mp3
was changed as the initial tmp path so in this case as suggested by Mr.CBroe the permissons shouldn't be an issue.

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

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

[Mon May 31 18:11:33 2021] [notice] caught SIGTERM, shutting down
[Mon May 31 18:11:40 2021] [notice] Digest: generating secret for digest authentication ...
[Mon May 31 18:11:40 2021] [notice] Digest: done
[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
sh: ffmpeg: command not found
sh: ffmpeg: command not found
sh: ffmpeg: command not found