
Recherche avancée
Médias (39)
-
Stereo master soundtrack
17 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Audio
-
ED-ME-5 1-DVD
11 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Audio
-
1,000,000
27 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Demon Seed
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
The Four of Us are Dying
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Corona Radiata
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
Autres articles (39)
-
Automated installation script of MediaSPIP
25 avril 2011, parTo overcome the difficulties mainly due to the installation of server side software dependencies, an "all-in-one" installation script written in bash was created to facilitate this step on a server with a compatible Linux distribution.
You must have access to your server via SSH and a root account to use it, which will install the dependencies. Contact your provider if you do not have that.
The documentation of the use of this installation script is available here.
The code of this (...) -
La sauvegarde automatique de canaux SPIP
1er avril 2010, parDans le cadre de la mise en place d’une plateforme ouverte, il est important pour les hébergeurs de pouvoir disposer de sauvegardes assez régulières pour parer à tout problème éventuel.
Pour réaliser cette tâche on se base sur deux plugins SPIP : Saveauto qui permet une sauvegarde régulière de la base de donnée sous la forme d’un dump mysql (utilisable dans phpmyadmin) mes_fichiers_2 qui permet de réaliser une archive au format zip des données importantes du site (les documents, les éléments (...) -
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;
Sur d’autres sites (6215)
-
ffprobe different results video duration using pipe and reading a file from the file system
5 février 2024, par alexI have a method to convert a video file, after processing the file I use
pipe
to pass bytes to a method to get meta information about the file using pipe. But in this case I get wrongduration
of video file, 8.22, but if I save the file on file system and read it to get meta information I get result 15.85. Why is this happening ?

Video Convert method :


// ConvertVideoWithPath converts a video file specified by its path using FFmpeg.
// It returns the converted video data and any error that occurred during conversion.
func (f *FFmpeg) ConvertVideoWithPath(filePath string) (bytes []byte, err error) {
 if filePath == "" {
 return nil, ErrEmptyPath
 }

 // Create a CmdRunner instance for executing FFmpeg.
 commander := &CmdRunner{}
 commander.Command = "ffmpeg"
 args := []string{
 "-loglevel", "fatal",
 "-i", filePath,
 "-y",
 "-filter:v", "crop=trunc(iw/2)*2:trunc(ih/2)*2",
 "-c:v", f.videoCodec, // libx264
 "-c:a", f.audioCodec, // aac
 "-pix_fmt", "yuv420p",
 "-movflags", "frag_keyframe+faststart",
 "-map_metadata", "-1",
 "-crf", "5",
 "-vsync", "2",
 "-bufsize", "15000000",
 "-maxrate", "5000000",
 "-preset", "medium",
 "-f", "mp4",
 "pipe:1",
 }
 commander.Args = args

 // Initialize output pipe.
 reader := commander.InitStdOutPipe()

 // Use WaitGroup to synchronize goroutines.
 wg := &sync.WaitGroup{}
 wg.Add(1)

 // Goroutine for reading data from the output pipe.
 go func() {
 defer reader.Close()
 defer wg.Done()

 // Read data from the output pipe.
 data, _ := io.ReadAll(reader)
 // Safely update the 'bytes' variable.
 f.mutex.Lock()
 bytes = data
 f.mutex.Unlock()
 }()

 // Run the FFmpeg command with pipes and wait for completion.
 err = <-commander.RunWithPipe()
 wg.Wait()

 return
}



// MetadataWithReader retrieves metadata from media data provided by an io.Reader using FFprobe.
// It returns the metadata and any error that occurred during metadata retrieval.
func (f *FFmpeg) MetadataWithReader(fileBytes io.Reader) (*Metadata, error) {
 if fileBytes == nil {
 return nil, ErrInvalidArgument
 }

 // Create a CmdRunner instance for executing FFprobe.
 commander := &CmdRunner{}
 commander.Command = "ffprobe"
 args := []string{
 "-loglevel", "fatal",
 "-i", "pipe:0",
 "-print_format", "json",
 "-show_format", "-show_streams",
 "-show_error",
 }
 commander.Args = args

 // Get output data from FFprobe with pipes.
 err := commander.GetOutputWithPipe(fileBytes)
 if err != nil {
 return nil, err
 }

 // Unmarshal JSON output into a Metadata struct.
 output := &Metadata{}
 err = json.Unmarshal(commander.GetOutput(), output)
 if err != nil {
 return nil, err
 }

 return output, err
}



// MetadataWithPath extracts metadata of a file using FFprobe.
// It returns a Metadata struct or an error if the operation fails.
func (f *FFmpeg) MetadataWithPath(filePath string) (*Metadata, error) {
 if filePath == "" {
 return nil, ErrEmptyPath
 }

 // Create a CmdRunner instance for executing FFprobe.
 commander := &CmdRunner{}
 commander.Command = "ffprobe"
 args := []string{
 "-loglevel", "fatal",
 "-i", filePath,
 "-loglevel",
 "fatal",
 "-print_format", "json",
 "-show_format", "-show_streams", "-show_error",
 }
 commander.Args = args
 buffer := bytes.NewBuffer([]byte{})
 commander.StdOutWriter = buffer

 err := commander.Run()
 if err != nil {
 return nil, err
 }

 // Unmarshal JSON output into a Metadata struct.
 output := &Metadata{}
 err = json.Unmarshal(buffer.Bytes(), output)
 if err != nil {
 return nil, err
 }

 return output, nil
}



The source code of the
CmdRunner
biblio library can be found here link , so as not to overload the question with a large piece of code.

Unit test code


t.Run("convert video", func(t *testing.T) {
 ffmpeg := NewFFmpeg("aac", "libx264", "24M", "12M")

 filePath := "../../test/testdata/input_video_ts.mp4"
 firstMeta, err := ffmpeg.MetadataWithPath(filePath)
 assert.NoError(t, err)
 fmt.Print("first meta duration: ", firstMeta.Format.DurationSeconds) // 15.75

 outFile := "../../test/testdata/output_mp4.mp4"
 newVideoOut, err := ffmpeg.ConvertVideoWithPath(filePath)
 assert.NoError(t, err)
 assert.NotEmpty(t, newVideoOut)

 meta, err := ffmpeg.MetadataWithReader(bytes.NewBuffer(newVideoOut))
 assert.NoError(t, err)
 assert.NotEmpty(t, meta)

 err = os.WriteFile(outFile, newVideoOut, 0644)
 assert.NoError(t, err)
 assert.FileExists(t, outFile)

 fmt.Print("meta duration: ", meta.Format.DurationSeconds) // 8.22

 secondMeta, err := ffmpeg.MetadataWithPath(outFile)
 assert.NoError(t, err)
 fmt.Print("second meta duration: ", secondMeta.Format.DurationSeconds) //15.85

 err = os.Remove(outFile)
 assert.NoError(t, err)
 })



-
FFMPEG loudnorm filter does not work in combination with silenceremove filter
12 mai 2021, par MareikePI want to consistently normalize audio files for TTS model training. The output audio files should meet the following criteria :


- 

- mono channel
- sample rate of 22050 Hz
- wav format
- no silence at beginning and end of audio clip
- volume of -24 dB












I have already fulfilled the first 4 criteria. So far, it works properly.


Normalizing the volume basically works as well with this ffmpeg command
-af loudnorm=I=-24:LRA=11:TP=-1.5
, but not in combination with the silence removal : As soon as I remove silence with this ffmpeg commandagate=threshold=0.045:attack=0.5:release=500:ratio=5000,silenceremove=start_periods=1:start_threshold=0.0075,areverse,silenceremove=start_periods=1:start_threshold=0.0075,areverse
, the loudness normalization does not work any longer : the output volume now varies between -25dB and -32dB instead of the desired -24 dB.

This is the complete ffmpeg command I used :


ffmpeg -i filename.flac -ac 1 -af agate=threshold=0.045:attack=0.5:release=500:ratio=5000,silenceremove=start_periods=1:start_threshold=0.0075,areverse,silenceremove=start_periods=1:start_threshold=0.0075,areverse,loudnorm=I=-24:LRA=11:TP=-1.5,aresample=22050 -y -hide_banner filename.wav



And this is the piece of code that I'm using to run it :


import os

INPUT_DIR = '/home/username/all_data'
OUTPUT_DIR = '/home/username/normalized_data'
for filename in os.listdir(INPUT_DIR):
 wav_filename = filename[:-5] + '.wav'
 command = (f'ffmpeg -i {INPUT_DIR}/{filename} -ac 1 -af agate='
 f'threshold=0.045:attack=0.5:release=500:ratio=5000,'
 f'silenceremove=start_periods=1:start_threshold=0.0075,'
 f'areverse,silenceremove=start_periods=1:start_threshold='
 f'0.0075,areverse,loudnorm=I=-24:LRA=11:TP=-1.5,aresample'
 f'=22050 -y -hide_banner {OUTPUT_DIR}/{wav_filename}')
 os.system(command)



EDIT :


A complete log from the ffmpeg command can be seen here :


username@pop-os:~$ ffmpeg -i /home/username/audios/filename.flac -ac 1 -af agate=threshold=0.045:attack=0.5:release=500:ratio=5000,silenceremove=start_periods=1:start_threshold=0.0075,areverse,silenceremove=start_periods=1:start_threshold=0.0075,areverse,loudnorm=I=-24:LRA=11:TP=-1.5,aresample=22050 /home/username/result.wav
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
 built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
 configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
 libavutil 56. 31.100 / 56. 31.100
 libavcodec 58. 54.100 / 58. 54.100
 libavformat 58. 29.100 / 58. 29.100
 libavdevice 58. 8.100 / 58. 8.100
 libavfilter 7. 57.100 / 7. 57.100
 libavresample 4. 0. 0 / 4. 0. 0
 libswscale 5. 5.100 / 5. 5.100
 libswresample 3. 5.100 / 3. 5.100
 libpostproc 55. 5.100 / 55. 5.100
Input #0, flac, from '/home/mareike/tts_data/save/audios_flac/0a6c8520-7536-11eb-8338-b7015f354987.flac':
 Duration: 00:00:04.64, start: 0.000000, bitrate: 1090 kb/s
 Stream #0:0: Audio: flac, 44100 Hz, stereo, s32 (24 bit)
Stream mapping:
 Stream #0:0 -> #0:0 (flac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, wav, to '/home/mareike/result_0a6c8520-7536-11eb-8338-b7015f354987.wav':
 Metadata:
 ISFT : Lavf58.29.100
 Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 Hz, mono, s16, 352 kb/s
 Metadata:
 encoder : Lavc58.54.100 pcm_s16le
size= 138kB time=00:00:03.19 bitrate= 353.0kbits/s speed=14.3x 
video:0kB audio:138kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.055375%



Can anyone tell me what I'm doing wrong and how I can finally get the volume normalized to -24 dB (in combination with silence removal) ? Any help is appreciated, thank you very much !


-
ffmpeg error on decode
25 octobre 2013, par ademar111190I'm developing an android app with the libav and I'm trying decode a 3gp with code below :
#define simbiLog(...) __android_log_print(ANDROID_LOG_DEBUG, "simbiose", __VA_ARGS__)
...
AVCodec *codec;
AVCodecContext *c = NULL;
int len;
FILE *infile, *outfile;
uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
AVPacket avpkt;
AVFrame *decoded_frame = NULL;
simbiLog("inbuf size: %d", sizeof(inbuf) / sizeof(inbuf[0]));
av_register_all();
av_init_packet(&avpkt);
codec = avcodec_find_decoder(AV_CODEC_ID_AMR_NB);
if (!codec) {
simbiLog("codec not found");
return ERROR;
}
c = avcodec_alloc_context3(codec);
if (!c) {
simbiLog("Could not allocate audio codec context");
return ERROR;
}
int open = avcodec_open2(c, codec, NULL);
if (open < 0) {
simbiLog("could not open codec %d", open);
return ERROR;
}
infile = fopen(inputPath, "rb");
if (!infile) {
simbiLog("could not open %s", inputPath);
return ERROR;
}
outfile = fopen(outputPath, "wb");
if (!outfile) {
simbiLog("could not open %s", outputPath);
return ERROR;
}
avpkt.data = inbuf;
avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, infile);
int iterations = 0;
while (avpkt.size > 0) {
simbiLog("iteration %d", (++iterations));
simbiLog("avpkt.size %d avpkt.data %X", avpkt.size, avpkt.data);
int got_frame = 0;
if (!decoded_frame) {
if (!(decoded_frame = avcodec_alloc_frame())) {
simbiLog("out of memory");
return ERROR;
}
} else {
avcodec_get_frame_defaults(decoded_frame);
}
//below the error, but it isn't occur on first time, only in 4th loop interation
len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt);
if (len < 0) {
simbiLog("Error while decoding error %d frame %d duration %d", len, got_frame, avpkt.duration);
return ERROR;
} else {
simbiLog("Decoding length %d frame %d duration %d", len, got_frame, avpkt.duration);
}
if (got_frame) {
int data_size = av_samples_get_buffer_size(NULL, c->channels, decoded_frame->nb_samples, c->sample_fmt, 1);
size_t* fwrite_size = fwrite(decoded_frame->data[0], 1, data_size, outfile);
simbiLog("fwrite returned %d", fwrite_size);
}
avpkt.size -= len;
avpkt.data += len;
if (avpkt.size < AUDIO_REFILL_THRESH) {
memmove(inbuf, avpkt.data, avpkt.size);
avpkt.data = inbuf;
len = fread(avpkt.data + avpkt.size, 1, AUDIO_INBUF_SIZE - avpkt.size, infile);
if (len > 0)
avpkt.size += len;
simbiLog("fread returned %d", len);
}
}
fclose(outfile);
fclose(infile);
avcodec_close(c);
av_free(c);
av_free(decoded_frame);but I'm getting the follow log and error :
inbuf size: 20488
iteration 1
avpkt.size 3305 avpkt.data BEEED40C
Decoding length 13 frame 1 duration 0
fwrite returned 640
fread returned 0
iteration 2
avpkt.size 3292 avpkt.data BEEED40C
Decoding length 13 frame 1 duration 0
fwrite returned 640
fread returned 0
iteration 3
avpkt.size 3279 avpkt.data BEEED40C
Decoding length 14 frame 1 duration 0
fwrite returned 640
fread returned 0
iteration 4
avpkt.size 3265 avpkt.data BEEED40C
Error while decoding error -1052488119 frame 0 duration 0the audio file I'm trying decode :
$ avprobe blue.3gp
avprobe version 0.8.6-6:0.8.6-1ubuntu2, Copyright (c) 2007-2013 the Libav developers
built on Mar 30 2013 22:23:21 with gcc 4.7.2
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'blue.3gp':
Metadata:
major_brand : 3gp4
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2013-09-19 18:53:38
Duration: 00:00:01.52, start: 0.000000, bitrate: 17 kb/s
Stream #0.0(eng): Audio: amrnb, 8000 Hz, 1 channels, flt, 12 kb/s
Metadata:
creation_time : 2013-09-19 18:53:38thanks a lot !
EDITED
I read on ffmper documentation about the method
avcodec_decode_audio4
the follow :@warning The input buffer, avpkt->data must be FF_INPUT_BUFFER_PADDING_SIZE larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end.
@note You might have to align the input buffer. The alignment requirements depend on the CPU and the decoder.and I see here a solution using
posix_memalign
, to android i founded a similar method calledmemalign
, so i did the change :removed :
uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
inserted :
int inbufSize = sizeof(uint8_t) * (AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
uint8_t *inbuf = memalign(FF_INPUT_BUFFER_PADDING_SIZE, inbufSize);
simbiLog("inbuf size: %d", inbufSize);
for (; inbufSize >= 0; inbufSize--)
simbiLog("inbuf position: %d index: %p", inbufSize, &inbuf[inbufSize]);I'm getting the correct memory sequence position, but the error not changed.
A piece of outpout :
inbuf position: 37 index: 0x4e43d745
inbuf position: 36 index: 0x4e43d744
inbuf position: 35 index: 0x4e43d743
inbuf position: 34 index: 0x4e43d742
inbuf position: 33 index: 0x4e43d741
inbuf position: 32 index: 0x4e43d740
inbuf position: 31 index: 0x4e43d73f
inbuf position: 30 index: 0x4e43d73e
inbuf position: 29 index: 0x4e43d73d
inbuf position: 28 index: 0x4e43d73c
inbuf position: 27 index: 0x4e43d73b
inbuf position: 26 index: 0x4e43d73a
inbuf position: 25 index: 0x4e43d739
inbuf position: 24 index: 0x4e43d738
inbuf position: 23 index: 0x4e43d737
inbuf position: 22 index: 0x4e43d736
inbuf position: 21 index: 0x4e43d735
inbuf position: 20 index: 0x4e43d734
inbuf position: 19 index: 0x4e43d733