
Recherche avancée
Médias (1)
-
Collections - Formulaire de création rapide
19 février 2013, par
Mis à jour : Février 2013
Langue : français
Type : Image
Autres articles (95)
-
Amélioration de la version de base
13 septembre 2013Jolie sélection multiple
Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...) -
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" ; -
Le plugin : Gestion de la mutualisation
2 mars 2010, parLe plugin de Gestion de mutualisation permet de gérer les différents canaux de mediaspip depuis un site maître. Il a pour but de fournir une solution pure SPIP afin de remplacer cette ancienne solution.
Installation basique
On installe les fichiers de SPIP sur le serveur.
On ajoute ensuite le plugin "mutualisation" à la racine du site comme décrit ici.
On customise le fichier mes_options.php central comme on le souhaite. Voilà pour l’exemple celui de la plateforme mediaspip.net :
< ?php (...)
Sur d’autres sites (9408)
-
How to fix here "EPIPE" in Node js Socket.io
23 avril, par Mehdi008Receiving this error :


Error: write EPIPE
 at afterWriteDispatched (node:internal/stream_base_commons:161:15)
 at writeGeneric (node:internal/stream_base_commons:152:3)
 at Socket._writeGeneric (node:net:958:11)
 at Socket._write (node:net:970:8)
 at doWrite (node:internal/streams/writable:598:12)
 at clearBuffer (node:internal/streams/writable:783:7)
 at onwrite (node:internal/streams/writable:653:7)
 at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:107:10)
 Emitted 'error' event on Socket instance at:
 at emitErrorNT (node:internal/streams/destroy:169:8)
 at emitErrorCloseNT (node:internal/streams/destroy:128:3)
 at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
 errno: -4047,
 code: 'EPIPE',
 syscall: 'write'
 }



// for this code: const { spawn } = require("child_process");

module.exports = (socket, pool) => {
 
 let stream_req_token = "";
 let rtmps_array = [];

 socket.on("stream_request_token",async(token)=>{

 const stream_reqs = await pool`SELECT * FROM stream_request WHERE token=${token}`;


 if(stream_reqs.length === 0){
 
 socket.emit("token_validation_response",false);
 return;
 }

 const stream_req = stream_reqs[0];

 if(!stream_req.is_valid){

 socket.emit("token_validation_response",false);
 return;
 }

 socket.emit("token_validation_response",true);

 stream_req_token = token;


 })

 socket.on("rtmps_array",async(array)=>{

 try{

 const rtmps = JSON.parse(array);

 const streams_requests = await pool`SELECT id FROM stream_request WHERE token=${stream_req_token}`;
 const stream_req_id = streams_requests[0].id;

 rtmps_array = rtmps;

 rtmps.map(async(rtmp)=>{

 await pool`INSERT INTO stream (platform,url,url_key,stream_request_id) 
 VALUES(${rtmp.platform},${rtmp.url},${rtmp.key},${stream_req_id})`;
 })

 socket.emit("rtmps_array_response",true);

 } catch(err){

 console.log(err);
 socket.emit("rtmps_array_response",false);

 }


 })

 //Start Streaming
 let ffmpegProcess = null;
 let isStreaming = false; // Flag to track streaming state

 socket.on("stream", (chunk) => {
 if (!ffmpegProcess) {
 console.log('Initializing FFmpeg process...');

 // Spawn FFmpeg process
 const resolution = "1280x720"; // Change to "1920x1080" for 1080p

 const ffmpegArgs = [
 "-i", "pipe:0", // Input from stdin
 "-c:v", "libx264", // Video codec
 "-preset", "veryfast", // Low latency encoding
 "-b:v", "4500k", // Target average bitrate (4.5 Mbps)
 "-minrate", "2500k", // Minimum bitrate
 "-maxrate", "6000k", // Maximum bitrate
 "-bufsize", "16000k", // Buffer size (twice the max bitrate)
 "-r", "30", // **FORCE 30 FPS**
 "-g", "60", // Keyframe interval (every 2 seconds)
 "-tune", "zerolatency", // Low latency tuning
 "-sc_threshold", "0", // Constant bitrate enforcement
 "-flags", "+global_header",
 
 // **Resolution Fix**
 "-s", resolution, // **Set resolution to 720p or 1080p**
 "-aspect", "16:9", // **Maintain aspect ratio**
 
 // **Frame Rate Fix**
 "-vsync", "cfr", // **Forces Constant Frame Rate (CFR)**
 "-fps_mode", "cfr", // **Prevents FFmpeg from auto-adjusting FPS**
 
 // Audio settings
 "-c:a", "aac",
 "-b:a", "128k", // Audio bitrate
 "-ar", "44100", // Audio sample rate
 "-ac", "2", // Stereo audio
 
 "-f", "flv" // Output format
 ];
 
 // Map the streams to multiple RTMP destinations
 rtmps_array.forEach((rtmp) => {
 ffmpegArgs.push("-map", "0:v:0", "-map", "0:a:0", "-f", "flv", `${rtmp.url}/${rtmp.key}`);
 });
 
 // Spawn FFmpeg process
 ffmpegProcess = spawn("ffmpeg", ffmpegArgs);

 ffmpegProcess.stderr.on('data', (data) => {
 console.log(`FFmpeg STDERR: ${data}`);
 });

 ffmpegProcess.on('close', (code) => {
 console.log(`FFmpeg process closed with code ${code}`);
 ffmpegProcess = null; // Reset process
 isStreaming = false; // Reset streaming state
 });

 ffmpegProcess.on('error', (err) => {
 console.error(`FFmpeg process error: ${err.message}`);
 ffmpegProcess = null; // Reset process
 isStreaming = false; // Reset streaming state
 });

 console.log('FFmpeg process started.');
 isStreaming = true; // Set streaming state to true
 }

 // Write chunk to FFmpeg process
 if (isStreaming && ffmpegProcess && ffmpegProcess.stdin && !ffmpegProcess.stdin.destroyed) {
 try {
 ffmpegProcess.stdin.write(chunk); // Write chunk to stdin
 console.log('Chunk written to FFmpeg.');
 } catch (err) {
 console.error('Error writing chunk to FFmpeg stdin:', err.message);
 }
 } else {
 console.error('FFmpeg process or stdin is not ready.');
 }
});

socket.on("stop-stream", async() => {
 console.log('Stream Stopped.');

 if(stream_req_token.length !== 0){

 await pool`UPDATE stream_request 
 SET is_valid=false
 WHERE token=${stream_req_token}`

 await pool`DELETE FROM current_streams WHERE id=${stream_req_token}`; 
 }

 if (ffmpegProcess) {
 isStreaming = false; // Set streaming state to false

 try {
 // Check if stdin is open before closing
 if (ffmpegProcess.stdin) {
 ffmpegProcess.stdin.end(); // End stdin safely
 }

 // Wait for FFmpeg to close before setting to null
 ffmpegProcess.on("close", () => {
 console.log("FFmpeg process closed.");
 ffmpegProcess = null;
 });

 // Kill FFmpeg process
 ffmpegProcess.kill("SIGTERM"); // Use SIGTERM for graceful exit

 } catch (err) {
 console.error("Error while stopping FFmpeg:", err.message);
 }
 } else {
 console.log("No active FFmpeg process.");
 }
});


socket.on('error', (err) => {
 console.error('Socket error:', err);
});

socket.on("disconnect", async() => {
 console.log('Client Disconnected.');

 if(stream_req_token.length !== 0){

 await pool`UPDATE stream_request 
 SET is_valid=false
 WHERE token=${stream_req_token}`;

 await pool`DELETE FROM current_streams WHERE id=${stream_req_token}`; 

 }
 
 if (ffmpegProcess) {
 isStreaming = false; // Set streaming state to false

 try {
 // Check if stdin is open before closing
 if (ffmpegProcess.stdin) {
 ffmpegProcess.stdin.end(); // End stdin safely
 }

 // Wait for FFmpeg to close before setting to null
 ffmpegProcess.on("close", () => {
 console.log("FFmpeg process closed.");
 ffmpegProcess = null;
 });

 // Kill FFmpeg process
 ffmpegProcess.kill("SIGTERM"); // Use SIGTERM for graceful exit


 } catch (err) {
 console.error("Error while stopping FFmpeg:", err.message);
 }
 } else {
 console.log("No active FFmpeg process.");
 }
});

};





-
Is there a way to convert HLS stream into RTSP stream by FFMPEG ?
19 août 2021, par k0342I have a hls stream which i am tying to convert into an rtsp stream so that i can use it further in a gstreamer application. Actually I could have used the hls stream itself but since the stream is secured and have session token, I am facing issues ingesting with souphttpsrc and demuxng with hlsdemux. As a backup, I want to explore a solution with ffmpeg otherwise I will have to use opencv to write frames in a gstreamer pipeline via appsrc.


I was able to convert the hls stream into a container format file by going through some sample examples, but I could not find any sample example on rtsp stream conversion. Since I am new to ffmpeg, If any one has a working solution for it, It would be very helpful.


Thanks in advance.


-
How to save variables at start of script for use later if script needs to be re-run due to errors or bad user input
28 novembre 2023, par slyfox1186I have a script that uses GitHub's API to get the latest version number of the repositories that I am trying to download and then compile.


Due to the fact that without using a specialized token from GitHub you are only allowed 50 API calls a day vs the 5000 a day with the API user token.


I want to be able to parse all of the repositories and grab the version numbers that my script will then import into the code up front so in case someone who accidentally cancels the build in the middle of it (for who knows what reasons) wont have to eat up their 50 day API call allowance.


Essentially, store each repo's version number, if the user then needs to rerun the script and version numbers that have been saved so far will be skipped (thus eliminating an API call) and any numbers that are still needing to be sourced will be called and then stored for used in the script.


I am kinda of lost for a method on how to go about this.


Maybe some sort of external file can be generated ?


So what my script does is it builds FFmpeg from source code and all of the external libraries that you can link to it are also built from their latest source code.


The code calls the function
git_ver_fn
and passes arguments to it which are parsed inside the function and directed to another functionsgit_1_fn or git_2_fn
which passed those parsed arguments that have been passed on to the CURL command which changes the URL based on the arguments passed. It uses thejq
command to capture the GitHubversion number
anddownload link
for thetar.gz
file.

It is the version number I am and trying to figure out the best way to store in case the script fails and has to be rerun, which will eat up all of the 50 APT limit that GitHub imposes without a token. I can't post my token in the script because GitHub deactivates it and thus the users will be SOL if they need to run the script more than once.


curl_timeout='5'

git_1_fn()
{
 # SCRAPE GITHUB WEBSITE FOR LATEST REPO VERSION
 github_repo="$1"
 github_url="$2"

 if curl_cmd="$(curl -m "$curl_timeout" -sSL "https://api.github.com/repos/$github_repo/$github_url")"; then
 g_ver="$(echo "$curl_cmd" | jq -r '.[0].name')"
 g_ver="${g_ver#v}"
 g_ssl="$(echo "$curl_cmd" | jq -r '.[0].name')"
 g_ssl="${g_ssl#OpenSSL }"
 g_pkg="$(echo "$curl_cmd" | jq -r '.[0].name')"
 g_pkg="${g_pkg#pkg-config-}"
 g_url="$(echo "$curl_cmd" | jq -r '.[0].tarball_url')"
 fi
}

git_2_fn()
{
 videolan_repo="$1"
 videolan_url="$2"
 if curl_cmd="$(curl -m "$curl_timeout" -sSL "https://code.videolan.org/api/v4/projects/$videolan_repo/repository/$videolan_url")"; then
 g_ver="$(echo "$curl_cmd" | jq -r '.[0].commit.id')"
 g_sver="$(echo "$curl_cmd" | jq -r '.[0].commit.short_id')"
 g_ver1="$(echo "$curl_cmd" | jq -r '.[0].name')"
 g_ver1="${g_ver1#v}"
 fi
}

git_ver_fn()
{
 local v_flag v_tag url_tag

 v_url="$1"
 v_tag="$2"

 if [ -n "$3" ]; then v_flag="$3"; fi

 if [ "$v_flag" = 'B' ] && [ "$v_tag" = '2' ]; then
 url_tag='git_2_fn' gv_url='branches'
 fi

 if [ "$v_flag" = 'X' ] && [ "$v_tag" = '5' ]; then
 url_tag='git_5_fn'
 fi

 if [ "$v_flag" = 'T' ] && [ "$v_tag" = '1' ]; then
 url_tag='git_1_fn' gv_url='tags'
 elif [ "$v_flag" = 'T' ] && [ "$v_tag" = '2' ]; then
 url_tag='git_2_fn' gv_url='tags'
 fi

 if [ "$v_flag" = 'R' ] && [ "$v_tag" = '1' ]; then
 url_tag='git_1_fn'; gv_url='releases'
 elif [ "$v_flag" = 'R' ] && [ "$v_tag" = '2' ]; then
 url_tag='git_2_fn'; gv_url='releases'
 fi

 case "$v_tag" in
 2) url_tag='git_2_fn';;
 esac

 "$url_tag" "$v_url" "$gv_url" 2>/dev/null
}

# begin source code building
git_ver_fn 'freedesktop/pkg-config' '1' 'T'
if build 'pkg-config' "$g_pkg"; then
 download "https://pkgconfig.freedesktop.org/releases/$g_ver.tar.gz" "$g_ver.tar.gz"
 execute ./configure --silent --prefix="$workspace" --with-pc-path="$workspace"/lib/pkgconfig/ --with-internal-glib
 execute make -j "$cpu_threads"
 execute make install
 build_done 'pkg-config' "$g_pkg"
fi

git_ver_fn 'yasm/yasm' '1' 'T'
if build 'yasm' "$g_ver"; then
 download "https://github.com/yasm/yasm/releases/download/v$g_ver/yasm-$g_ver.tar.gz" "yasm-$g_ver.tar.gz"
 execute ./configure --prefix="$workspace"
 execute make -j "$cpu_threads"
 execute make install
 build_done 'yasm' "$g_ver"
fi