
Recherche avancée
Autres articles (23)
-
Récupération d’informations sur le site maître à l’installation d’une instance
26 novembre 2010, parUtilité
Sur le site principal, une instance de mutualisation est définie par plusieurs choses : Les données dans la table spip_mutus ; Son logo ; Son auteur principal (id_admin dans la table spip_mutus correspondant à un id_auteur de la table spip_auteurs)qui sera le seul à pouvoir créer définitivement l’instance de mutualisation ;
Il peut donc être tout à fait judicieux de vouloir récupérer certaines de ces informations afin de compléter l’installation d’une instance pour, par exemple : récupérer le (...) -
Publier sur MédiaSpip
13 juin 2013Puis-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 -
MediaSPIP Player : problèmes potentiels
22 février 2011, parLe lecteur ne fonctionne pas sur Internet Explorer
Sur Internet Explorer (8 et 7 au moins), le plugin utilise le lecteur Flash flowplayer pour lire vidéos et son. Si le lecteur ne semble pas fonctionner, cela peut venir de la configuration du mod_deflate d’Apache.
Si dans la configuration de ce module Apache vous avez une ligne qui ressemble à la suivante, essayez de la supprimer ou de la commenter pour voir si le lecteur fonctionne correctement : /** * GeSHi (C) 2004 - 2007 Nigel McNie, (...)
Sur d’autres sites (5290)
-
Batch generating spectrograms with ffmpeg or SoX : how to customize their appearance, and is my code so far correct ?
4 mai 2024, par Mark II have a .flac music library, and for organizational and quality assessment reasons I want to have spectrograms of every song in it. After finding out that the program I usually use to view them, Spek, doesn't offer a batch export option, I have found ways to batch generate spectrograms with both SoX and fmpeg. Below you can find the two scripts I've got, which take as an input a folder which contains flac files or subfolders containing flac files, and output their spectrograms (with the same names as their corresponding flacs) to an output folder with the same structure as the input folder :


SoX :


@echo off
setlocal enabledelayedexpansion

REM Root folder containing flac files
set "root_folder=%~1"

REM Output folder for spectrogram images
set "output_folder=0. Spectrograms"

REM Create the output folder if it doesn't exist
mkdir "%output_folder%" 2>nul

REM Loop through all flac files recursively
for /r "%root_folder%" %%F in (*.flac) do (
 REM Get the directory of the flac file
 set "directory=%%~dpF"

 REM Get the relative path of the directory from the root folder
 set "relative_path=!directory:%root_folder%\=!"

 REM Create the corresponding subfolder in the output folder
 mkdir "%output_folder%\!relative_path!" 2>nul

 REM Get the filename without extension
 set "filename=%%~nF"

 REM Get the filename with full path
 set "filename_with_path=%%F"

 REM Generate spectrogram image using sox
 sox "%%F" -n spectrogram -x 640 -y 360 -t "!filename_with_path!" -o "%output_folder%\!relative_path!\!filename!.png"
)




It's slow but it works as intended, this is what the output looks like :


ffmpeg :


@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

:: The root directory of the input files
SET "rootdir=%~1"

:: The output directory where the spectrograms will be saved
SET "outputdir=%rootdir%\0. Spectrograms"

:: Function to create spectrograms recursively
CALL :processFolder "%rootdir%"

GOTO :EOF

:processFolder
FOR /D %%D IN ("%~1\*") DO (
 SET "subdir=%%D"
 SET "spectrodir=!subdir:%rootdir%=%outputdir%!"
 IF NOT EXIST "!spectrodir!" MKDIR "!spectrodir!"
 CALL :processFolder "%%D"
)

FOR %%F IN ("%~1\*.flac") DO (
 SET "filename=%%~nxF"
 SET "spectroname=!filename:.flac=.png!"
 SET "spectropath=!spectrodir!\!spectroname!"
 ffmpeg -i "%%F" -lavfi showspectrumpic=s=1280x720 "!spectropath!"
)
GOTO :EOF



It's much faster, and this is what it outputs :


I added them to the Windows Send To folder, and use both by right clicking the folder containing the subfolders with the flacs, then Send To and then the script I want to use.


I have 3 questions :


- 

- Is my code as optimized as it could be ? Is everything correct ? And is it "folder structure agnostic" ? When outputting the spectrograms will the scripts mimic the structure of the input folder in all cases, or are there flaws in the code that would prevent them from being able to do it in some cases (i.e. if the .flac files are 3 layers under the input folder or something like that) ?
- How do I modify the function calls at each of these scripts (whichever approach I stick with, I'm leaning towards ffmpeg cause it's much faster and appears to be better supported) to have the spectrogram image include some info about the file, customize its font, x axis time format, and other things ? I want it look like what Spek outputs as much as possible. Can't find much in the documentation of SoX and ffmpeg, but Spek uses ffmpeg as its backend right ?
- Is it recommended to show both channels on the spectrograms, like the SoX script does, or is one sufficient for my purposes ?








-
How to write a video file using FFmpeg
15 janvier 2024, par SummitI am trying to write a video file using FFMPEG but i get the following errors


[libx264 @ 000002bdf90c3c00] broken ffmpeg default settings detected
[libx264 @ 000002bdf90c3c00] use an encoding preset (e.g. -vpre medium)
[libx264 @ 000002bdf90c3c00] preset usage: -vpre <speed> -vpre <profile>
[libx264 @ 000002bdf90c3c00] speed presets are listed in x264 --help
[libx264 @ 000002bdf90c3c00] profile is optional; x264 defaults to high
</profile></speed>


This is my code


#pragma warning(disable : 4996)

extern "C" {
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>opt.h>
#include <libavutil></libavutil>mathematics.h>
#include <libswscale></libswscale>swscale.h>
}

int main() {
 av_register_all();
 AVFormatContext* formatContext = nullptr;
 AVOutputFormat* outputFormat = nullptr;
 AVStream* videoStream = nullptr;

 const char* filename = "output.mp4";

 // Open the output file
 if (avformat_alloc_output_context2(&formatContext, nullptr, nullptr, filename) < 0) {
 fprintf(stderr, "Error allocating output format context\n");
 return -1;
 }

 outputFormat = formatContext->oformat;

 // Add a video stream
 videoStream = avformat_new_stream(formatContext, nullptr);
 if (!videoStream) {
 fprintf(stderr, "Error creating video stream\n");
 return -1;
 }

 // Set codec parameters, you may need to adjust these based on your needs
 AVCodecContext* codecContext = avcodec_alloc_context3(nullptr);
 codecContext->codec_id = outputFormat->video_codec;
 codecContext->codec_type = AVMEDIA_TYPE_VIDEO;
 codecContext->pix_fmt = AV_PIX_FMT_YUV420P;
 codecContext->width = 640;
 codecContext->height = 480;
 codecContext->time_base = { 1, 25 };

 // Open the video codec
 AVCodec* videoCodec = avcodec_find_encoder(codecContext->codec_id);
 if (!videoCodec) {
 fprintf(stderr, "Error finding video codec\n");
 return -1;
 }

 if (avcodec_open2(codecContext, videoCodec, nullptr) < 0) {
 fprintf(stderr, "Error opening video codec\n");
 return -1;
 }

 videoStream->codecpar->codec_id = codecContext->codec_id;
 videoStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
 videoStream->codecpar->format = codecContext->pix_fmt;
 videoStream->codecpar->width = codecContext->width;
 videoStream->codecpar->height = codecContext->height;

 if (avformat_write_header(formatContext, nullptr) < 0) {
 fprintf(stderr, "Error writing header\n");
 return -1;
 }

 // Create a frame
 AVFrame* frame = av_frame_alloc();
 frame->format = codecContext->pix_fmt;
 frame->width = codecContext->width;
 frame->height = codecContext->height;
 av_frame_get_buffer(frame, 32);

 // Fill the frame with red color
 for (int y = 0; y < codecContext->height; ++y) {
 for (int x = 0; x < codecContext->width; ++x) {
 frame->data[0][y * frame->linesize[0] + x * 3] = 255; // Red component
 frame->data[0][y * frame->linesize[0] + x * 3 + 1] = 0; // Green component
 frame->data[0][y * frame->linesize[0] + x * 3 + 2] = 0; // Blue component
 }
 }

 // Write video frames
 AVPacket packet;
 for (int i = 0; i < 100; ++i) {
 // Send the frame for encoding
 if (avcodec_send_frame(codecContext, frame) < 0) {
 fprintf(stderr, "Error sending a frame for encoding\n");
 return -1;
 }

 // Receive the encoded packet
 while (avcodec_receive_packet(codecContext, &packet) == 0) {
 // Write the packet to the output file
 if (av_write_frame(formatContext, &packet) != 0) {
 fprintf(stderr, "Error writing video frame\n");
 return -1;
 }
 av_packet_unref(&packet);
 }
 }

 // Write the trailer
 if (av_write_trailer(formatContext) != 0) {
 fprintf(stderr, "Error writing trailer\n");
 return -1;
 }

 // Clean up resources
 av_frame_free(&frame);
 avcodec_free_context(&codecContext);
 avformat_free_context(formatContext);

 return 0;
}



-
How to write a video file using FFmpeg
15 janvier 2024, par SummitI am trying to write a video file using FFMPEG but i get the following errors


[libx264 @ 000002bdf90c3c00] broken ffmpeg default settings detected
[libx264 @ 000002bdf90c3c00] use an encoding preset (e.g. -vpre medium)
[libx264 @ 000002bdf90c3c00] preset usage: -vpre <speed> -vpre <profile>
[libx264 @ 000002bdf90c3c00] speed presets are listed in x264 --help
[libx264 @ 000002bdf90c3c00] profile is optional; x264 defaults to high
</profile></speed>


This is my code


#pragma warning(disable : 4996)

extern "C" {
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>opt.h>
#include <libavutil></libavutil>mathematics.h>
#include <libswscale></libswscale>swscale.h>
}

int main() {
 av_register_all();
 AVFormatContext* formatContext = nullptr;
 AVOutputFormat* outputFormat = nullptr;
 AVStream* videoStream = nullptr;

 const char* filename = "output.mp4";

 // Open the output file
 if (avformat_alloc_output_context2(&formatContext, nullptr, nullptr, filename) < 0) {
 fprintf(stderr, "Error allocating output format context\n");
 return -1;
 }

 outputFormat = formatContext->oformat;

 // Add a video stream
 videoStream = avformat_new_stream(formatContext, nullptr);
 if (!videoStream) {
 fprintf(stderr, "Error creating video stream\n");
 return -1;
 }

 // Set codec parameters, you may need to adjust these based on your needs
 AVCodecContext* codecContext = avcodec_alloc_context3(nullptr);
 codecContext->codec_id = outputFormat->video_codec;
 codecContext->codec_type = AVMEDIA_TYPE_VIDEO;
 codecContext->pix_fmt = AV_PIX_FMT_YUV420P;
 codecContext->width = 640;
 codecContext->height = 480;
 codecContext->time_base = { 1, 25 };

 // Open the video codec
 AVCodec* videoCodec = avcodec_find_encoder(codecContext->codec_id);
 if (!videoCodec) {
 fprintf(stderr, "Error finding video codec\n");
 return -1;
 }

 if (avcodec_open2(codecContext, videoCodec, nullptr) < 0) {
 fprintf(stderr, "Error opening video codec\n");
 return -1;
 }

 videoStream->codecpar->codec_id = codecContext->codec_id;
 videoStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
 videoStream->codecpar->format = codecContext->pix_fmt;
 videoStream->codecpar->width = codecContext->width;
 videoStream->codecpar->height = codecContext->height;

 if (avformat_write_header(formatContext, nullptr) < 0) {
 fprintf(stderr, "Error writing header\n");
 return -1;
 }

 // Create a frame
 AVFrame* frame = av_frame_alloc();
 frame->format = codecContext->pix_fmt;
 frame->width = codecContext->width;
 frame->height = codecContext->height;
 av_frame_get_buffer(frame, 32);

 // Fill the frame with red color
 for (int y = 0; y < codecContext->height; ++y) {
 for (int x = 0; x < codecContext->width; ++x) {
 frame->data[0][y * frame->linesize[0] + x * 3] = 255; // Red component
 frame->data[0][y * frame->linesize[0] + x * 3 + 1] = 0; // Green component
 frame->data[0][y * frame->linesize[0] + x * 3 + 2] = 0; // Blue component
 }
 }

 // Write video frames
 AVPacket packet;
 for (int i = 0; i < 100; ++i) {
 // Send the frame for encoding
 if (avcodec_send_frame(codecContext, frame) < 0) {
 fprintf(stderr, "Error sending a frame for encoding\n");
 return -1;
 }

 // Receive the encoded packet
 while (avcodec_receive_packet(codecContext, &packet) == 0) {
 // Write the packet to the output file
 if (av_write_frame(formatContext, &packet) != 0) {
 fprintf(stderr, "Error writing video frame\n");
 return -1;
 }
 av_packet_unref(&packet);
 }
 }

 // Write the trailer
 if (av_write_trailer(formatContext) != 0) {
 fprintf(stderr, "Error writing trailer\n");
 return -1;
 }

 // Clean up resources
 av_frame_free(&frame);
 avcodec_free_context(&codecContext);
 avformat_free_context(formatContext);

 return 0;
}