
Recherche avancée
Médias (1)
-
Bug de détection d’ogg
22 mars 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Video
Autres articles (53)
-
Les vidéos
21 avril 2011, parComme les documents de type "audio", Mediaspip affiche dans la mesure du possible les vidéos grâce à la balise html5 .
Un des inconvénients de cette balise est qu’elle n’est pas reconnue correctement par certains navigateurs (Internet Explorer pour ne pas le nommer) et que chaque navigateur ne gère en natif que certains formats de vidéos.
Son avantage principal quant à lui est de bénéficier de la prise en charge native de vidéos dans les navigateur et donc de se passer de l’utilisation de Flash et (...) -
MediaSPIP v0.2
21 juin 2013, parMediaSPIP 0.2 est la première version de MediaSPIP stable.
Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
Comme pour la version précédente, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...) -
Mise à disposition des fichiers
14 avril 2011, parPar défaut, lors de son initialisation, MediaSPIP ne permet pas aux visiteurs de télécharger les fichiers qu’ils soient originaux ou le résultat de leur transformation ou encodage. Il permet uniquement de les visualiser.
Cependant, il est possible et facile d’autoriser les visiteurs à avoir accès à ces documents et ce sous différentes formes.
Tout cela se passe dans la page de configuration du squelette. Il vous faut aller dans l’espace d’administration du canal, et choisir dans la navigation (...)
Sur d’autres sites (9011)
-
FFmpeg splitting large files
1er février 2016, par Yusaf KhaliqI need to split a large video file into multiple pieces quickly and without files with errors. The basic idea is, I have a 2GB video file which I want to change to multiple formats. I have read some encoders can not make use of more than 1 core when encoding to a different format. So I had the idea to split the large file (which is very quick) into 4/8 pieces depending on how many cores I have available on individual servers. re-encode each piece to a new format and use these to display video in sequence.
so
testfile.mp4
becomes
- testfile_piece_1.mp4
- testfile_piece_2.mp4
- testfile_piece_3.mp4
- testfile_piece_4.mp4
these can then be individually be converted.
The solution should not be format specific. However I have found issues with mp4 files.
I have tried the command below, which works really well and fast but creates files with errors.
ffmpeg -i testfile.mp4 -ss 00:00:00 -t 00:20:00 -c copy testfile_piece_1.mp4
When I play the testfile_piece_1.mp4 on VLC it works fine. An issue arises when converting the split file to a different height and width mp4 file. I would get an error similar to "moov atom not found"
I tried adding
-movflags faststart
with no luckI then came across this library https://code.google.com/archive/p/moovrelocator/ which fixed the moov issue but I would then get an error with regards to aac "Error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height"
The other way of splitting the files is useless but involved re-encoding the file. not too bad for smaller file size but the 2GB file would probably take days to complete.
Is there a way to split the largr file quickly without producing files with errors ? I have been working on it for days with no luck.
Console output for comment - FFmpeg splitting large files
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/usr/share/nginx/html/uploads/testfile01.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.36.100
Duration: 00:05:02.08, start: 302.120000, bitrate: 3254 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709) , 1920x1080 [SAR 1:1 DAR 16:9], 3252 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (de fault)
Metadata:
handler_name : VideoHandler
[libx264 @ 0x165ffc0] width not divisible by 2 (853x480)
Output #0, mp4, to '/usr/share/nginx/html/uploads/testfile01_480.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.36.100
Stream #0:0(und): Video: h264, none, q=2-31, 128 kb/s, SAR 2560:2559 DAR 0:0 , 25 fps (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc56.41.100 libx264
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or heightconsole output 2
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/usr/share/nginx/html/uploads/testfile.mp4':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6avc1mp41
creation_time : 2016-01-24 04:26:37
Duration: 01:15:58.08, start: 0.000000, bitrate: 3163 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 3161 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
Metadata:
creation_time : 2016-01-24 04:26:37
handler_name : VideoHandler
[segment @ 0x1197060] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
Output #0, segment, to '/usr/share/nginx/html/uploads/testfile%02d.mp4':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6avc1mp41
encoder : Lavf56.36.100
Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 3161 kb/s, 25 fps, 25 tbr, 12800 tbn, 25 tbc (default)
Metadata:
creation_time : 2016-01-24 04:26:37
handler_name : VideoHandler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 @ 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers -
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 !