Recherche avancée
Médias (29)
-
#1 The Wires
11 octobre 2011, par
Mis à jour : Février 2013
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
-
Lights in the Sky
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
Sur d’autres sites (147)
-
FFMPEG - Alsa buffer xrun (ALSA_BUFFER_SIZE_MAX overflow)
21 décembre 2014, par HeikkiMy goal is to use ffmpeg to record audio and video from my webcam simultaneously, and to send it to my loopback address, so that I can open the resulting multiplex of video and audio on vlc player.
MY ATTEMPT :
-
First of all, I have to execute mptsconfig.py, a python code that generates the required information tables (it can be downloaded via http://www.avalpa.com/assets/freesoft/opencaster/OpenCaster-tutorials.3.2.2.tgz, and can be found in Tutorials > mpts) :
chmod 777 mptsconfig.py
./mptsconfig.py
-
After that, I open vlc player, and go to Media > Open Network Stream, where I type the loopback address and port 1234 : udp ://@127.0.0.1:1234. I am now able to receive incoming data from my own computer.
-
Finally, I use the following bash script (
bash script.sh)
:#!/bin/bash
# Removing previous FIFOs
rm webcam.mp2
rm webcam.pes
rm webcam.ts
rm audio.mp2
rm audio.pes
rm audio.ts
rm wmux.ts
rm wfinal.ts
# Creating new FIFOs
mkfifo webcam.mp2
mkfifo webcam.pes
mkfifo webcam.ts
mkfifo audio.mp2
mkfifo audio.pes
mkfifo audio.ts
mkfifo wmux.ts
mkfifo wfinal.ts
### 1. WEBCAM VIDEO
# Recording webcam video
ffmpeg -an -f video4linux2 -s pal -r 25 -i /dev/video0 -vcodec mpeg2video -f mpeg2video -s pal -b:v 1000k -minrate:v 1000k -maxrate:v 1000k -bufsize 1835008 -y webcam.mp2 &
# Converting mp2 video Elementary Stream to Packetised Elementary Stream
esvideompeg2pes webcam.mp2 > webcam.pes &
# Converting video ES to Transport Stream
pesvideo2ts 2064 25 112 3450000 0 webcam.pes > webcam.ts &
### 2. WEBCAM AUDIO
# Recording webcam audio (in my case, my webcam microphone is tagged as "hardware card #2"; the number associated to one's webcam mic can be found executing *arecord -l* in bash)
ffmpeg -f alsa -ac 1 -ar 48000 -i hw:2 -preset ultrafast -y audio.mp2 &
# Converting mp2 audio Elementary Stream to Packetised Elementary Stream
esaudio2pes audio.mp2 1152 48000 384 -1 3600 > audio.pes &
# Converting audio ES to Transport Stream
pesaudio2ts 2068 1152 48000 384 -1 audio.pes > audio.ts &
### 3. MULTIPLEXING AUDIO & VIDEO
# Video, audio & PAT, PMT, SDT & NIT Tables Multiplex
tscbrmuxer b:3450000 webcam.ts b:188000 audio.ts b:3008 mptspat.ts b:3008 mptspmt1.ts b:1500 mptssdt.ts b:1400 mptsnit.ts > wmux.ts &
# tssstamp (it solves PCR problems)
tsstamp wmux.ts 3646916 > wfinal.ts &
### 4. SENDING THE FINAL MULTIPLEX
# Sending TS via udp to loopback address
tsudpsend wfinal.ts 127.0.0.1 1234 3646916
I can see and hear the output on vlc player, however, I get a bash error concerning ALSA’s buffer overflow (
ALSA buffer xrun.
). Moreover, the output isn’t played smoothly : the audio is played back with constant interruptions, as it happens with the video.MY ATTEMPTS TO SOLVE THE ISSUE :
-
I’ve been trying to figure out how to solve this problem. I’ve tried
to follow the same steps as explained here
https://bbs.archlinux.org/viewtopic.php?id=171477, without any luck. -
I’ve tried to increase the size of the ALSA buffer, but I don’t have
in my computer any of the directories containing alsa-audio.h. Even
if I create the paths and file by myself, and edit the buffer size,
it won’t work. -
After that, I created .asoundrc and followed the same steps as
listed in http://www.alsa-project.org/main/index.php/Asoundrc,
without any success -
Lastly, I tried to use Qjack, and changed some parameters concerning buffer size from my webcam’s mic. It didn’t work as well.
I don’t know what to do anymore. Does anyone know what I could do in order to solve this problem ?
I’m running Ubuntu 14.04, and using the following software :
- GNU bash v4.3.11(1)-release (x86_64-pc-linux-gnu)
- opencaster (MPEG2 transport stream data generator and packet manipulator ; opencaster 3.2.2+dfs- 1)
- ffmpeg version 1.2.6-7:1.2.6-1 trusty1
- VLC media player (vlc 2.1.4-0ubuntu14.04.1)
- QjackCtl (qjackctl 0.3.10-2)
-
-
Matplotlib : ValueError : I/O operation on closed file [duplicate]
28 septembre 2017, par gopiThis question is an exact duplicate of :
%matplotlib inline
import math,os,sys,numpy as np
from numpy.random import random
from matplotlib import pyplot as plt, rcParams, animation, rc
from __future__ import print_function, division
from ipywidgets import interact, interactive, fixed
from ipywidgets.widgets import *
rc('animation', html='html5')
rcParams['figure.figsize'] = 3,3
%precision 4
np.set_printoptions(precision=4, linewidth=100)
def lin(a,x,b): return a * x + b
a = 3.
b = 8.
n = 30
x = random(n)
y = lin(a,x,b)
plt.scatter(x,y)
def sse(y, y_pred): return ((y-y_pred)**2).sum()
def loss(y, a, x, b): return sse(y, lin(a, x, b))
def avg_loss(y, a, x, b): return np.sqrt(loss(y, a, x, b)/n)
a_guess = -1
b_guess = 1
avg_loss(y, a_guess, x, b_guess)
lr = 0.01
#d[(y-(a*x+b))**2, b] = 2 (y_pred - y)
#d[(y -(a*x+b)) **2, a] = x * dy/db
def upd():
global a_guess, b_guess
y_pred = lin(a_guess, x, b_guess)
dydb = 2 * (y_pred - y)
dyda = x * dydb
a_guess -= lr*dyda.mean()
b_guess -= lr*dydb.mean()
fig = plt.figure(dpi=100, figsize=(5,5))
plt.scatter(x,y)
line, = plt.plot(x, lin(a_guess, x, b_guess))
plt.close()
def animate(i):
line.set_ydata(lin(a_guess, x, b_guess))
for i in range(10): upd()
return line,
ani = animation.FuncAnimation(fig, animate, np.arange(0, 40), interval=100)
aniBut when I run it I get the following error,
ValueError Traceback (most recent call last)
/home/gopinath/Workspace/anaconda3/envs/py27/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
309 method = get_real_method(obj, self.print_method)
310 if method is not None:
--> 311 return method()
312 return None
313 else:
/home/gopinath/Workspace/anaconda3/envs/py27/lib/python2.7/site-packages/matplotlib/animation.pyc in _repr_html_(self)
1233 fmt = rcParams['animation.html']
1234 if fmt == 'html5':
-> 1235 return self.to_html5_video()
1236
1237
/home/gopinath/Workspace/anaconda3/envs/py27/lib/python2.7/site-packages/matplotlib/animation.pyc in to_html5_video(self)
1207 bitrate=rcParams['animation.bitrate'],
1208 fps=1000. / self._interval)
-> 1209 self.save(f.name, writer=writer)
1210
1211 # Now open and base64 encode
/home/gopinath/Workspace/anaconda3/envs/py27/lib/python2.7/site-packages/matplotlib/animation.pyc in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs)
1061 # TODO: See if turning off blit is really necessary
1062 anim._draw_next_frame(d, blit=False)
-> 1063 writer.grab_frame(**savefig_kwargs)
1064
1065 # Reconnect signal for first draw if necessary
/home/gopinath/Workspace/anaconda3/envs/py27/lib/python2.7/contextlib.pyc in __exit__(self, type, value, traceback)
33 value = type()
34 try:
---> 35 self.gen.throw(type, value, traceback)
36 raise RuntimeError("generator didn't stop after throw()")
37 except StopIteration, exc:
/home/gopinath/Workspace/anaconda3/envs/py27/lib/python2.7/site-packages/matplotlib/animation.pyc in saving(self, *args, **kw)
287 yield self
288 finally:
--> 289 self.finish()
290
291 def _run(self):
/home/gopinath/Workspace/anaconda3/envs/py27/lib/python2.7/site-packages/matplotlib/animation.pyc in finish(self)
307 def finish(self):
308 'Finish any processing for writing the movie.'
--> 309 self.cleanup()
310
311 def grab_frame(self, **savefig_kwargs):
/home/gopinath/Workspace/anaconda3/envs/py27/lib/python2.7/site-packages/matplotlib/animation.pyc in cleanup(self)
346 def cleanup(self):
347 'Clean-up and collect the process used to write the movie file.'
--> 348 out, err = self._proc.communicate()
349 self._frame_sink().close()
350 verbose.report('MovieWriter -- '
/home/gopinath/Workspace/anaconda3/envs/py27/lib/python2.7/site-packages/subprocess32.pyc in communicate(self, input, timeout)
925
926 try:
--> 927 stdout, stderr = self._communicate(input, endtime, timeout)
928 finally:
929 self._communication_started = True
/home/gopinath/Workspace/anaconda3/envs/py27/lib/python2.7/site-packages/subprocess32.pyc in _communicate(self, input, endtime, orig_timeout)
1711 if _has_poll:
1712 stdout, stderr = self._communicate_with_poll(input, endtime,
-> 1713 orig_timeout)
1714 else:
1715 stdout, stderr = self._communicate_with_select(input, endtime,
/home/gopinath/Workspace/anaconda3/envs/py27/lib/python2.7/site-packages/subprocess32.pyc in _communicate_with_poll(self, input, endtime, orig_timeout)
1767 select_POLLIN_POLLPRI = select.POLLIN | select.POLLPRI
1768 if self.stdout:
-> 1769 register_and_append(self.stdout, select_POLLIN_POLLPRI)
1770 stdout = self._fd2output[self.stdout.fileno()]
1771 if self.stderr:
/home/gopinath/Workspace/anaconda3/envs/py27/lib/python2.7/site-packages/subprocess32.pyc in register_and_append(file_obj, eventmask)
1746 poller = select.poll()
1747 def register_and_append(file_obj, eventmask):
-> 1748 poller.register(file_obj.fileno(), eventmask)
1749 self._fd2file[file_obj.fileno()] = file_obj
1750
ValueError: I/O operation on closed fileI almost tried everywhere and I couldn’t find a solution, I tried reinstalling ffmpeg from the sources, moved this file to the folder where I installed ffmpeg and gave a try.
I’m using python 3.5,
Ubuntu 16.04
Anaconda 4.4
Matplotlib 2.02actually this particular course was taught using python 2.7 so I created a virenv installed 2.7 along with all related dependencies. So will it be the problem ?? I mean using python 2.7 on top of 3.5 ?
-
Frames from Video Using OpenCV in Ubuntu with Java 17
2 août 2023, par bstrdnI've been trying to extract frames from a video using OpenCV in an Ubuntu environment with Java 17, but all my attempts have been unsuccessful so far. The main issue is that ffmpeg is not detected by the OpenCV library on ubuntu.


Here's my test code :


Main class


import org.opencv.core.Core;
import org.opencv.videoio.VideoCapture;

public class Main {
 public static String videoPath = "";
 static {
 String osName = System.getProperty("os.name").toLowerCase();
 if (osName.contains("win")) {
 System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
 videoPath = ClassLoader.getSystemResource("video.mp4").getPath();
 } else {
 videoPath = "/video.mp4";
// System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
 System.load("/usr/lib/opencv_java470.so");
 }
 }

 public static void main(String[] args) throws InterruptedException {
 VideoCapture videoCapture = new VideoCapture(videoPath);
 if (!videoCapture.isOpened()) {
 System.out.println("Error opening video file.");
 } else {
 System.out.println("Everything is fine.");
 }
 System.out.println(Core.getBuildInformation());
 Thread.sleep(1000000000000000000L);
 }
}



Maven :


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
 <modelversion>4.0.0</modelversion>
 <parent>
 <groupid>org.springframework.boot</groupid>
 <artifactid>spring-boot-starter-parent</artifactid>
 <version>3.0.2</version>
 <relativepath></relativepath> 
 </parent>
 <groupid>org.example</groupid>
 <artifactid>untitled</artifactid>
 <version>1.0-SNAPSHOT</version>
 <properties>
 17
 17
 UTF-8
 </properties>

<dependencies>
<dependency>
 <groupid>org.bytedeco</groupid>
 <artifactid>opencv-platform</artifactid>
 <version>4.7.0-1.5.9</version>
</dependency>

<dependency>
 <groupid>org.springframework.boot</groupid>
 <artifactid>spring-boot-starter-web</artifactid>
</dependency>
</dependencies>
<build>
<plugins>
 <plugin>
 <groupid>org.springframework.boot</groupid>
 <artifactid>spring-boot-maven-plugin</artifactid>
 </plugin>
</plugins>
</build>
</project>



Dockerfile :


FROM ubuntu:20.04
RUN apt-get update && apt-get install -y openjdk-17-jdk
RUN apt-get update && apt-get install -y pkg-config
RUN apt-get update && apt-get install -y ffmpeg libavformat-dev libavcodec-dev libswscale-dev libavresample-dev
ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64
COPY target/*.jar /app.jar
COPY src/main/resources/video.mp4 /
COPY opencv_java470.so /usr/lib
ENV JAVA_TOOL_OPTIONS="-Djava.library.path=/usr/lib:/lib:/usr/local/lib:/usr/local:/usr/lib/x86_64-linux-gnu"
ENV LD_LIBRARY_PATH=/usr/lib:/lib:/usr/local/lib:/usr/local:/usr/lib/x86_64-linux-gnu
ENTRYPOINT [ "sh", "-c", "java $JAVA_TOOL_OPTIONS -jar /app.jar" ]



The application displays the following text (video is not opened) :


Error opening video file.

2023-08-02T13:30:58.448538297Z 
2023-08-02T13:30:58.448572597Z General configuration for OpenCV 4.7.0 =====================================
2023-08-02T13:30:58.448587327Z Version control: v4.7.0
2023-08-02T13:30:58.448590607Z 
2023-08-02T13:30:58.448593217Z Platform:
2023-08-02T13:30:58.448596057Z Timestamp: 2023-03-27T23:13:34Z
2023-08-02T13:30:58.448598747Z Host: Linux 5.4.0-1103-azure x86_64
2023-08-02T13:30:58.448601377Z CMake: 3.25.2
2023-08-02T13:30:58.448604277Z CMake generator: Unix Makefiles
2023-08-02T13:30:58.448606837Z CMake build tool: /usr/bin/make
2023-08-02T13:30:58.448609327Z Configuration: RELEASE
2023-08-02T13:30:58.448611867Z 
.......there is a lot of text......
2023-08-02T13:30:58.448772865Z 
2023-08-02T13:30:58.448775355Z Video I/O:
2023-08-02T13:30:58.448777845Z DC1394: NO
2023-08-02T13:30:58.448780535Z FFMPEG: NO
2023-08-02T13:30:58.448783105Z avcodec: NO
2023-08-02T13:30:58.448785725Z avformat: NO
2023-08-02T13:30:58.448788295Z avutil: NO
2023-08-02T13:30:58.448790755Z swscale: NO
2023-08-02T13:30:58.448793295Z avresample: NO
2023-08-02T13:30:58.448795845Z GStreamer: NO
2023-08-02T13:30:58.448798255Z v4l/v4l2: YES (linux/videodev2.h)
2023-08-02T13:30:58.448800885Z 
2023-08-02T13:30:58.448803525Z Parallel framework: pthreads
2023-08-02T13:30:58.448806345Z 
............
2023-08-02T13:30:58.448859654Z Java: export all functions
2023-08-02T13:30:58.448862024Z ant: /usr/bin/ant (ver 1.10.5)
2023-08-02T13:30:58.448864504Z JNI: /opt/hostedtoolcache/jdk/8.0.362/x64/include /opt/hostedtoolcache/jdk/8.0.362/x64/include/linux /opt/hostedtoolcache/jdk/8.0.362/x64/include
2023-08-02T13:30:58.448867224Z Java wrappers: YES
2023-08-02T13:30:58.448869804Z Java tests: NO
2023-08-02T13:30:58.448872314Z 
2023-08-02T13:30:58.448874734Z Install to: /usr/local



Moreover, ffmpeg is installed on Ubuntu.


How can i fix this ? I'm deathly tired(


Thank you in advance for your assistance !


First I tried installation following the official instructions.https://github.com/bytedeco/javacv#required-software


Then the solution provided in https://stackoverflow.com/a/76750478/8087508,


but the result is the same.