
Recherche avancée
Médias (1)
-
Rennes Emotion Map 2010-11
19 octobre 2011, par
Mis à jour : Juillet 2013
Langue : français
Type : Texte
Autres articles (7)
-
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" ; -
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 -
Menus personnalisés
14 novembre 2010, parMediaSPIP utilise le plugin Menus pour gérer plusieurs menus configurables pour la navigation.
Cela permet de laisser aux administrateurs de canaux la possibilité de configurer finement ces menus.
Menus créés à l’initialisation du site
Par défaut trois menus sont créés automatiquement à l’initialisation du site : Le menu principal ; Identifiant : barrenav ; Ce menu s’insère en général en haut de la page après le bloc d’entête, son identifiant le rend compatible avec les squelettes basés sur Zpip ; (...)
Sur d’autres sites (4336)
-
avformat_close_input memory leak ?
20 janvier 2021, par Keen JackdawI developed an app to push live stream with ffmpeg. When I checked the app with
leaks --atExit -- <the app="app"></the>
(I'm on mac), I found some memory leak with AVFormatContext.

The minimized code are provided below :


#include <iostream>

extern "C" {
#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libavdevice></libavdevice>avdevice.h>
}

void foo() {
 avdevice_register_all();

 AVFormatContext *avInputFormatContext = avformat_alloc_context();
 AVInputFormat *avInputFormat = av_find_input_format("avfoundation");
 std::cout << "open input" << std::endl;
 int ret = avformat_open_input(&avInputFormatContext, "Capture screen 0", avInputFormat, nullptr);
 if (ret < 0) { std::cout << "open input failed: " << ret << std::endl; return;}

 avformat_close_input(&avInputFormatContext);

}

int main() {
 foo();
 return 0;
}

</iostream>


The output is


Process: ffmpegtest [87726]
Path: /Users/USER/*/ffmpegtest
Load Address: 0x10a752000
Identifier: ffmpegtest
Version: ???
Code Type: X86-64
Platform: macOS
Parent Process: leaks [87725]

Date/Time: 2021-01-20 15:44:57.533 +0800
Launch Time: 2021-01-20 15:44:55.760 +0800
OS Version: macOS 11.1 (20C69)
Report Version: 7
Analysis Tool: /Applications/Xcode.app/Contents/Developer/usr/bin/leaks
Analysis Tool Version: Xcode 12.3 (12C33)

Physical footprint: 9.9M
Physical footprint (peak): 10.6M
----

leaks Report Version: 4.0
Process 87726: 14143 nodes malloced for 2638 KB
Process 87726: 1 leak for 32 total leaked bytes.

 1 (32 bytes) ROOT LEAK: 0x7f8c61e1b040 [32] length: 16 "Capture screen 0"



Did I miss something ?


-
FFmpeg from Python has Corrupted Output
14 juillet 2019, par MazyodIn a python script, I have :
os.system(ff_cmd)
# also tried Popen(ff_cmd, shell=True).wait()Then, I ran that same
ff_cmd
from terminal directly. Here are the results :# ff_cmd
ffmpeg -i "114006.mp3" -acodec pcm_s16le -ar 16000 -ac 1 "114-006-a4dec52a.wav"
# after running from python
% file 114-006-a4dec52a.wav
114-006-a4dec52a.wav: Audio file with ID3 version 2.4.0, contains:MPEG ADTS, layer III, v2, 40 kbps, 16 kHz, Monaural
# after running from terminal
% file 114-006-a4dec52a.wav
114-006-a4dec52a.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 16000 HzCan anyone please explain why in the world would they result in different outputs ?
Output from Python :
ffmpeg version 4.1.4 Copyright (c) 2000-2019 the FFmpeg developers
built with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.4 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
[mp3 @ 0x7ffa34001800] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from '/.../114006.mp3':
Duration: 00:00:09.53, start: 0.000000, bitrate: 64 kb/s
Stream #0:0: Audio: mp3, 22050 Hz, stereo, fltp, 64 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, wav, to '/.../114-006-a4dec52a.wav':
Metadata:
ISFT : Lavf58.20.100
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 Hz, mono, s16, 256 kb/s
Metadata:
encoder : Lavc58.35.100 pcm_s16le
size= 298kB time=00:00:09.53 bitrate= 256.1kbits/s speed= 166x
video:0kB audio:298kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.025564%Output from terminal :
ffmpeg version 4.1.4 Copyright (c) 2000-2019 the FFmpeg developers
built with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.4 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
[mp3 @ 0x7f98ed005800] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from '/.../114006.mp3':
Duration: 00:00:09.53, start: 0.000000, bitrate: 64 kb/s
Stream #0:0: Audio: mp3, 22050 Hz, stereo, fltp, 64 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, wav, to '/.../114-006-a4dec52a.wav':
Metadata:
ISFT : Lavf58.20.100
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 Hz, mono, s16, 256 kb/s
Metadata:
encoder : Lavc58.35.100 pcm_s16le
size= 298kB time=00:00:09.53 bitrate= 256.1kbits/s speed= 469x
video:0kB audio:298kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.025564% -
Failed to add audio to mp4 with moviepy
24 avril, par D GI generated an audio
sound.wav
and a videotemp.mp4
that makes use of the audio. Both with the same duration.

I got the following warning when generating the
temp.mp4
. The animation is out of sync, it means that it freezes before the audio finishes.



.venv\Lib\site-packages\moviepy\video\io\ffmpeg_reader.py:178 : UserWarning : In file temp.mp4, 1080000 bytes wanted but 0
bytes read at frame index 299 (out of a total 300 frames), at time 4.98/5.00 sec. Using the last valid frame instead.
warnings.warn(




Complete code :


# to generate sound.wav
import numpy as np
import soundfile as sf
from tqdm import tqdm
from os import startfile

# Parameters
filename = "sound.wav"
duration = 5 # seconds
num_voices = 1000
sample_rate = 44100 # Hz
chunk_size = sample_rate # write in 1-second chunks


t = np.linspace(0, duration, int(sample_rate * duration), endpoint=False)

# Create many detuned sine waves (Deep Note style)
start_freqs = np.random.uniform(100, 400, num_voices)
end_freqs = np.linspace(400, 800, num_voices) # target harmony

# Each voice sweeps from start to end frequency
signal = np.zeros_like(t)
for i in range(num_voices):
 freqs = np.linspace(start_freqs[i], end_freqs[i], t.size)
 voice = np.sin(2 * np.pi * freqs * t)
 voice *= np.sin(np.pi * i / num_voices) # slight variance
 signal += voice

# Volume envelope
envelope = np.linspace(0.01, 1.0, t.size)
signal *= envelope

# Normalize
signal /= np.max(np.abs(signal))

# Save with progress bar using soundfile
with sf.SoundFile(
 filename, "w", samplerate=sample_rate, channels=1, subtype="PCM_16"
) as f:
 for i in tqdm(range(0, len(signal), chunk_size), desc=f"Saving {filename}"):
 f.write(signal[i : i + chunk_size])


startfile(filename)



# to generate temp.mp4
from numpy import pi, sin, cos
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from os import startfile
from tqdm import tqdm
from moviepy import VideoFileClip, AudioFileClip, CompositeAudioClip

# Output settings
filename = "temp.mp4"
duration = 5 # seconds of animation
maxdim = 4 # canvas size in plot units (scaled)
fps = 60

# Real-world parameters
r = 40 # km (radius)
endtime = 2 # hours (duration of real motion)
rph = 0.5 # rotations per hour
omega = 2 * pi * rph # rad/hour
speed = omega * r # km/hour

# Animation setup
frames = duration * fps
scale = maxdim / r # scale from km to plot units
dt = endtime / frames # time per frame in hours

# Prepare figure and axes
fig, ax = plt.subplots(figsize=(6, 6))
ax.set_xlim(-maxdim - 1, maxdim + 1)
ax.set_ylim(-maxdim - 1, maxdim + 1)
ax.set_aspect("equal")
ax.grid()



# Plot circle path
circle = plt.Circle((0, 0), r * scale, color="lightgray", fill=False, linestyle="--")
ax.add_patch(circle)

# Moving point
(point,) = ax.plot([], [], "ro")

# Info text at center of the circle
info_text = ax.text(
 0, 0, "", fontsize=10,
 ha="center", va="center",
 bbox=dict(boxstyle="round,pad=0.4", facecolor="white", alpha=0.8)
)


def init():
 point.set_data([], [])
 info_text.set_text("")
 return point, info_text


def update(frame):
 t = frame * dt # time in hours
 theta = omega * t # angle in radians

 x = r * cos(theta) * scale
 y = r * sin(theta) * scale

 point.set_data([x], [y])
 info_text.set_text(
 f"Time: {t:.2f} hr\nRadius: {r:.1f} km\nSpeed: {speed:.2f} km/h"
 )
 return point, info_text



# Create animation
anim = FuncAnimation(
 fig, update, frames=frames, init_func=init, blit=True, interval=1000 / fps
)


with tqdm(total=frames, desc="Saving", unit="frame") as pbar:
 anim.save(filename, fps=fps, progress_callback=lambda i, n: pbar.update(1))

# Add sound using MoviePy
video = VideoFileClip(filename)
video.audio = CompositeAudioClip([AudioFileClip("sound.wav")])
video.write_videofile(filename)

startfile(filename)



Could you figure out what the culprit is and how to fix it ?




Edit


Based on the given comment, I did the following but the problem still exists.


# Add sound using MoviePy
video = VideoFileClip(filename)
audio = AudioFileClip("sound.wav")
audio.duration = video.duration
video.audio = CompositeAudioClip([audio])
video.write_videofile(filename)