
Recherche avancée
Médias (1)
-
The pirate bay depuis la Belgique
1er avril 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Image
Autres articles (61)
-
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 (...) -
Websites made with MediaSPIP
2 mai 2011, parThis page lists some websites based on MediaSPIP.
-
Possibilité de déploiement en ferme
12 avril 2011, parMediaSPIP peut être installé comme une ferme, avec un seul "noyau" hébergé sur un serveur dédié et utilisé par une multitude de sites différents.
Cela permet, par exemple : de pouvoir partager les frais de mise en œuvre entre plusieurs projets / individus ; de pouvoir déployer rapidement une multitude de sites uniques ; d’éviter d’avoir à mettre l’ensemble des créations dans un fourre-tout numérique comme c’est le cas pour les grandes plate-formes tout public disséminées sur le (...)
Sur d’autres sites (8068)
-
AVIOContext custom stream playback glitches/corruption on UDP stream
21 décembre 2017, par WLGfxI’ve written a general all round player (for Android OS) which plays file based streams as well as streams from network sources, and it all works good. File based streams I’ve got the seeking which works too.
What it is I’m now struggling with is now I’m using
AVIOContext
to latch onto a UDP stream which saves the packet data partially in memory and then to transient storage. This is so I can pause live TV and also seek within it.However, after much faffing about, during playback (seeking is only partial at the moment), either the video frame rate will drop from 25FPS (will be deinterlaced on higher spec devices) down to between 17 and 19 frames per second, or, it will glitch and grey out.
When I playback the record TS data from the file, it plays perfect, so the UDP buffering and writing out the overflow is sound. (This is currently not true now, only currently a minor issue)
I’m at the point were I’ve spent a lot of time on this and I’m at a loss as to why I get either frame drops or glitches.
The class def :
#define PKT_SIZE (188)
#define PKT_SIZE7 (PKT_SIZE * 7)
#define UDP_QUEUE_SIZE (12000)
#define UDP_THRESHOLD (100)
#define FILE_QUEUE_PKTS (200000)
#define AVIO_QUEUE_SIZE (24)
#define AVIO_THRESHOLD (10)
extern "C" {
#include "libavformat/avio.h"
};
/*
* PracticalSocket class as found here with examples:
* http://cs.baylor.edu/~donahoo/practical/CSockets/practical/
*/
#include "PracticalSocket.h"
class FFIOBufferManager2 {
public:
AVIOContext *avioContext = nullptr;
bool quit = false;
char udp_buffer[UDP_QUEUE_SIZE][PKT_SIZE7];
int udp_write_pos, udp_size; // by PKT_SIZE7
char *get_udp_buffer(int index);
int get_udp_buffer_size() { return udp_size; }
int file_write_pos, file_size; // by PKT_SIZE7
std::fstream file_out, file_in;
std::mutex udp_mutex, file_mutex;
std::thread udp_thread, file_thread;
static void udp_thread_func(FFIOBufferManager2 *io, const char *ip, int port);
static void file_thread_func(FFIOBufferManager2 *io, const char *dir);
void udp_thread_run(const char *ip, int port);
void file_thread_run();
char avio_buffer[AVIO_QUEUE_SIZE * 7 * PKT_SIZE];
int64_t avio_read_offset; // controlled by udp mutex (quickest)
static int avio_read(void *ptr, uint8_t *buff, int buf_size);
static int64_t avio_seek(void *ptr, int64_t pos, int whence);
int avio_read_run(uint8_t *buf, int buf_size);
int64_t avio_seek_run(int64_t pos, int whence);
void write_udp_overflow();
void start(const char *ip, int port, const char *dir);
void get_size_and_pos(int64_t *size, int64_t *pos);
~FFIOBufferManager2();
};The classes methods :
#include
#include "FFIOBufferManager2.h"
#include "LOG.h"
void FFIOBufferManager2::start(const char *ip, int port, const char *dir) {
file_write_pos = 0;
file_size = 0;
udp_write_pos = 0;
udp_size = 0;
avio_read_offset = 0;
file_thread = std::thread(&FFIOBufferManager2::file_thread_func, this, dir);
udp_thread = std::thread(&FFIOBufferManager2::udp_thread_func, this, ip, port);
LOGD("Initialising avioContext");
avioContext = avio_alloc_context((uint8_t*)avio_buffer,
AVIO_QUEUE_SIZE * PKT_SIZE7,
0,
this,
avio_read,
NULL,
avio_seek);
}
void FFIOBufferManager2::udp_thread_func(FFIOBufferManager2 *io, const char *ip, int port) {
LOGD("AVIO UDP thread started address %s port %d - %08X", ip, port, (uint)io);
io->udp_thread_run(ip, port); // run inside class
LOGD("AVIO UDP thread stopped");
}
void FFIOBufferManager2::udp_thread_run(const char *ip, int port) {
std::string addr = ip;
UDPSocket socket(addr, (uint16_t)port);
socket.joinGroup(addr);
LOGD("UDP loop starting");
while (!quit) {
if (socket.recv(get_udp_buffer(udp_write_pos), PKT_SIZE7) == PKT_SIZE7) {
udp_mutex.lock();
udp_write_pos = (udp_write_pos + 1) % UDP_QUEUE_SIZE;
udp_size++;
if (udp_size >= UDP_QUEUE_SIZE) udp_size--;
else avio_read_offset += PKT_SIZE7;
udp_mutex.unlock();
}
}
}
void FFIOBufferManager2::file_thread_func(FFIOBufferManager2 *io, const char *dir) {
LOGD("AVIO FILE thread started");
std::string file = dir;
const char *tsfile_name = "/tsdata.ts";
file += tsfile_name;
LOGD("Deleting old file %s", file.c_str());
remove(file.c_str());
{
fstream temp; // create the ts file
temp.open(file.c_str());
temp.close();
}
LOGD("Opening %s for read and write", file.c_str());
io->file_out.open(file, fstream::out | fstream::binary);
io->file_in.open(file, fstream::in | fstream::binary);
io->file_thread_run(); // continue inside the class to lessen pointer use
LOGD("AVIO FILE thread stopped");
}
void FFIOBufferManager2::file_thread_run() {
LOGD("FILE thread run");
if (!file_out.is_open() || !file_in.is_open()) {
LOGE("TS data file, error opening...");
quit = true;
return;
}
int udp_threshold = UDP_QUEUE_SIZE - (UDP_THRESHOLD * 4);
while (!quit) {
if (udp_size >= udp_threshold) write_udp_overflow();
else usleep(1000 * 1);
}
}
void FFIOBufferManager2::write_udp_overflow() {
file_mutex.lock();
udp_mutex.lock();
int udp_write_pos_current = udp_write_pos;
int udp_size_current = udp_size;
udp_mutex.unlock();
int udp_index = udp_write_pos_current - udp_size_current;
if (udp_index < 0) udp_index += UDP_QUEUE_SIZE;
int written = 0;
//file_out.seekp((int64_t)file_write_pos * PKT_SIZE7);
while (written < UDP_THRESHOLD) {
file_out.write(get_udp_buffer(udp_index), PKT_SIZE7);
written++;
udp_index = (udp_index + 1) % UDP_QUEUE_SIZE;
file_write_pos++;
if (file_write_pos >= FILE_QUEUE_PKTS) {
file_write_pos = 0;
file_out.seekp(0);
}
file_size++;
if (file_size > FILE_QUEUE_PKTS) file_size = FILE_QUEUE_PKTS;
}
udp_mutex.lock();
udp_size -= UDP_THRESHOLD; // we've written this amount out
udp_mutex.unlock();
//file_out.flush();
file_mutex.unlock();
//LOGD("Written UDP overflow at %d of %d blocks file size %d",
// udp_index, written, file_size);
}
char *FFIOBufferManager2::get_udp_buffer(int index) {
if (index < 0 || index >= UDP_QUEUE_SIZE) return nullptr;
return ((char*)udp_buffer + (index * PKT_SIZE7));
}
/*
* The avio_read and avio_seek now work on either 188 byte alignment or
* byte alignment for the benefit of ffmpeg - byte positioning at the moment
*
* The file_mutex allows for either a read or write operation at a time
*/
int FFIOBufferManager2::avio_read(void *ptr, uint8_t *buff, int buf_size) {
FFIOBufferManager2 *io = (FFIOBufferManager2*)ptr;
return io->avio_read_run(buff, buf_size);
}
int64_t FFIOBufferManager2::avio_seek(void *ptr, int64_t pos, int whence) {
FFIOBufferManager2 *io = (FFIOBufferManager2*)ptr;
return io->avio_seek_run(pos, whence);
}
int FFIOBufferManager2::avio_read_run(uint8_t *buf, int buf_size) {
file_mutex.lock();
udp_mutex.lock();
int64_t cur_udp_write_pos = (int64_t) udp_write_pos * PKT_SIZE7;
int64_t cur_udp_size = (int64_t) udp_size * PKT_SIZE7;
int64_t cur_file_write_pos = (int64_t) file_write_pos * PKT_SIZE7;
int64_t cur_file_size = (int64_t) file_size * PKT_SIZE7;
int64_t cur_avio_read_offset = avio_read_offset; // already int64_t (under the udp_mutex)
udp_mutex.unlock();
if (cur_avio_read_offset < (AVIO_THRESHOLD * 4) * PKT_SIZE7) {
file_mutex.unlock();
return 0;
}
int64_t udp_buffer_max = (int64_t) (UDP_QUEUE_SIZE * PKT_SIZE7);
int64_t file_buffer_max = (int64_t) (FILE_QUEUE_PKTS * PKT_SIZE7);
uint8_t *ptr_udp_buffer = (uint8_t*)udp_buffer;
int cur_written = 0;
int file_reads = 0, udp_reads = 0; // for debugging
int64_t cur_file_offset = cur_file_write_pos - cur_udp_size - cur_avio_read_offset;
while (cur_file_offset < 0) cur_file_offset += file_buffer_max;
if (cur_file_offset >= 0) {
file_in.seekg(cur_file_offset);
while (//cur_avio_read_offset > 0
cur_avio_read_offset > cur_udp_size
&& cur_written < buf_size) { // read from file first
file_in.read(&avio_buffer[cur_written], PKT_SIZE); // get 1 or 188 byte/s
cur_file_offset+=PKT_SIZE;
if (cur_file_offset >= file_buffer_max) { // back to file beginning
cur_file_offset = 0;
file_in.seekg(0);
}
cur_avio_read_offset-=PKT_SIZE;
cur_written+=PKT_SIZE;
file_reads+=PKT_SIZE;
}
}
int64_t cur_udp_offset = (cur_udp_write_pos - cur_avio_read_offset);
if (cur_udp_offset < 0) cur_udp_offset += udp_buffer_max;
while (cur_avio_read_offset > AVIO_THRESHOLD * PKT_SIZE7
&& cur_avio_read_offset <= cur_udp_size
&& cur_written < buf_size) { // read the rest from udp buffer
buf[cur_written] = ptr_udp_buffer[cur_udp_offset]; // get byte
cur_udp_offset = (cur_udp_offset + 1) % udp_buffer_max;
if (cur_udp_offset == 0) LOGD("AVIO UDP BUFFER to start");
cur_avio_read_offset--;
cur_written++;
udp_reads++;
}
udp_mutex.lock();
avio_read_offset -= cur_written;
udp_mutex.unlock();
file_mutex.unlock();
if (cur_written) {
LOGD("AVIO_READ: Written %d of %d, avio_offset %lld, file reads %d, udp reads %d, udp offset %lld, file offset %lld, file size %lld",
cur_written, buf_size,
cur_avio_read_offset,
file_reads, udp_reads,
cur_udp_write_pos, cur_file_write_pos, cur_file_size);
}
return cur_written;
}
int64_t FFIOBufferManager2::avio_seek_run(int64_t pos, int whence) {
// SEEK_SET(0), SEEK_CUR(1), SEEK_END(2), AVSEEK_SIZE
int64_t new_pos = -1;
int64_t full_length = (udp_size + file_size) * PKT_SIZE7;
switch (whence) {
case AVSEEK_SIZE:
LOGD("AVSEEK_SIZE pos %lld", pos);
break;
case SEEK_SET:
LOGD("AVSEEK_SET pos %lld", pos);
if (pos > full_length) new_pos = full_length;
else new_pos = full_length - pos;
break;
case SEEK_CUR:
LOGD("AVSEEK_CUR pos %lld", pos);
break;
case SEEK_END:
LOGD("AVSEEK_END pos %lld", pos);
new_pos = pos;
break;
default:
LOGD("UNKNOWN AVIO SEEK whence %d pos %lld", whence, pos);
break;
}
if (new_pos >= 0) {
udp_mutex.lock();
new_pos = (new_pos / PKT_SIZE) * PKT_SIZE; // align to packet boundary
avio_read_offset = new_pos;
//file_out.seekg(full_length - new_pos);
udp_mutex.unlock();
return full_length - new_pos;
}
return -1;
}
FFIOBufferManager2::~FFIOBufferManager2() {
if (avioContext) ;// TODO whoops
quit = true;
if (udp_thread.joinable()) udp_thread.join();
if (file_thread.joinable()) file_thread.join();
}
void FFIOBufferManager2::get_size_and_pos(int64_t *size, int64_t *pos) {
file_mutex.lock();
udp_mutex.lock();
*size = (udp_size + file_size) * PKT_SIZE7;
*pos = *size - avio_read_offset;
udp_mutex.unlock();
file_mutex.unlock();
}It’ll play for a few seconds before any of the glitches start to appear. I have checked against the udp_buffer and the avio_buffer, but my suspicions lie with one of two things :
- Reading and writing to the file.
- the
avio_read
method is wrong.
Has anybody got any input as to why this is occurring ? Any thoughts would be greatly appreciated.
If you need any more information I’ll be glad to provide more details.
EDIT : Seeking now actually moves to any point within the stream, but now doesn’t read from the file recording. Although that’s only a minor issue at the moment.
The main two issues still stand, frame rate drops dramatically and the glitches after approximately 8 seconds.
-
FFMPEG ALSA xrun crash
13 décembre 2017, par Liam MartensI’m running a YouTube RTMP stream using FFMPEG with x11grab and an alsa loopback device but sometimes after let’s say 20 hours there is an ALSA xrun and then the ffmpeg command crashes, but I’m not sure why or how this happens. (mind you the ffmpeg command does not run continuously it gets restarted automatically every so often, but the xrun makes the command crash causing the stream to go offline sometimes because a crash restart is not fast enough)
I’m using
thread_queue_size
and I’ve even manually compiled ffmpeg with a higherALSA BUFFER SIZE
, but the issue appears to persist still. Besides this I’ve also scoured many posts with people having similar issues but these never really seem to end up resolved.This is the stream command
ffmpeg -loglevel verbose -f alsa -thread_queue_size 12288 -ac 2 -i hw:Loopback,1,0 \
-probesize 10M -f x11grab -field_order tt -thread_queue_size 12288 -video_size 1280x720 -r 30 -i :1.1 \
-c:v libx264 -c:a libmp3lame -shortest -tune fastdecode -tune zerolatency \
-crf 26 -pix_fmt yuv420p -threads 0 -maxrate 2500k -bufsize 2500k -pass 1 -af aresample=async=1 \
-movflags +faststart -flags +global_header -preset ultrafast -r 30 -g 60 -b:v 2000k -b:a 192k -ar 44100 \
-f flv -rtmp_live live rtmp://a.rtmp.youtube.com/live2/{KEY}Log excerpt
ffmpeg version N-89463-gc7a5e80 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18) 20170516
configuration: --prefix=/usr --enable-avresample --enable-avfilter --enable-gpl --enable-libmp3lame --enable-librtmp --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libtheora --enable-postproc --enable-pic --enable-pthreads --enable-shared --disable-stripping --disable-static --enable-vaapi --enable-libopus --enable-libfreetype --enable-libfontconfig --enable-libpulse --disable-debug
libavutil 56. 5.100 / 56. 5.100
libavcodec 58. 6.103 / 58. 6.103
libavformat 58. 3.100 / 58. 3.100
libavdevice 58. 0.100 / 58. 0.100
libavfilter 7. 7.100 / 7. 7.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 0.101 / 5. 0.101
libswresample 3. 0.101 / 3. 0.101
libpostproc 55. 0.100 / 55. 0.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'hw:Loopback,1,0':
Duration: N/A, start: 1513163617.594224, bitrate: 1536 kb/s
Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Input #1, x11grab, from ':1.1':
Duration: N/A, start: 1513163617.632434, bitrate: N/A
Stream #1:0: Video: rawvideo, 1 reference frame (BGR[0] / 0x524742), bgr0(top first), 854x480, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
Parsing...
Parsed protocol: 0
Parsed host : a.rtmp.youtube.com
Parsed app : live2
RTMP_Connect1, ... connected, handshaking
HandShake: Type Answer : 03
HandShake: Server Uptime : 0
HandShake: FMS Version : 4.0.0.1
HandShake: Handshaking finished....
RTMP_Connect1, handshaked
Invoking connect
HandleServerBW: server BW = 2500000
HandleClientBW: client BW = 10000000 2
HandleChangeChunkSize, received: chunk size change to 256
RTMP_ClientPacket, received: invoke 240 bytes
(object begin)
Property:
Property:
Property:
(object begin)
Property: 3,5,3,824>
Property:
Property:
(object end)
Property:
(object begin)
Property:
Property:
Property:
Property:
Property:
(object begin)
Property:
(object end)
(object end)
(object end)
HandleInvoke, server invoking <_result>
HandleInvoke, received result for method call <connect>
Invoking releaseStream
Invoking FCPublish
Invoking createStream
RTMP_ClientPacket, received: invoke 21 bytes
(object begin)
Property:
Property:
Property: NULL
(object end)
HandleInvoke, server invoking <onbwdone>
Invoking _checkbw
RTMP_ClientPacket, received: invoke 29 bytes
(object begin)
Property:
Property:
Property: NULL
Property:
(object end)
HandleInvoke, server invoking <_result>
HandleInvoke, received result for method call <createstream>
Invoking publish
RTMP_ClientPacket, received: invoke 73 bytes
(object begin)
Property:
Property:
Property: NULL
Property:
(object begin)
Property:
Property:
(object end)
(object end)
HandleInvoke, server invoking <onstatus>
HandleInvoke, onStatus: NetStream.Publish.Start
Stream mapping:
Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Stream #0:0 -> #0:1 (pcm_s16le (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
[graph 0 input from stream 1:0 @ 0x5607d087e060] w:854 h:480 pixfmt:bgr0 tb:1/30 fr:30/1 sar:0/1 sws_param:flags=2
[auto_scaler_0 @ 0x5607d087d800] w:iw h:ih flags:'bicubic' interl:0
[format @ 0x5607d087ed40] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_null_0' and the filter 'format'
[auto_scaler_0 @ 0x5607d087d800] w:854 h:480 fmt:bgr0 sar:0/1 -> w:854 h:480 fmt:yuv420p sar:0/1 flags:0x4
[swscaler @ 0x5607d0880260] Warning: data is not aligned! This can lead to a speed loss
[libx264 @ 0x5607d08684e0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x5607d08684e0] profile Constrained Baseline, level 3.1
[libx264 @ 0x5607d08684e0] 264 - core 148 r2748 97eaef2 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=2 lookahead_threads=2 sliced_threads=1 slices=2 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=60 keyint_min=6 scenecut=0 intra_refresh=0 rc_lookahead=0 rc=crf mbtree=0 crf=26.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=1500 vbv_bufsize=1500 crf_max=0.0 nal_hrd=none filler=0 ip_ratio=1.40 aq=0
[graph_1_in_0_0 @ 0x5607d091c840] tb:1/48000 samplefmt:s16 samplerate:48000 chlayout:0x3
[Parsed_aresample_0 @ 0x5607d0916b40] ch:2 chl:stereo fmt:s16 r:48000Hz -> ch:2 chl:stereo fmt:s16p r:44100Hz
Output #0, flv, to 'rtmp://a.rtmp.youtube.com/live2/{KEY}':
Metadata:
encoder : Lavf58.3.100
Stream #0:0: Video: h264 (libx264), 1 reference frame ([7][0][0][0] / 0x0007), yuv420p(top coded first (swapped)), 854x480, q=-1--1, 1000 kb/s, 30 fps, 1k tbn, 30 tbc
Metadata:
encoder : Lavc58.6.103 libx264
Side data:
cpb: bitrate max/min/avg: 1500000/0/1000000 buffer size: 1500000 vbv_delay: -1
Stream #0:1: Audio: mp3 (libmp3lame) ([2][0][0][0] / 0x0002), 44100 Hz, stereo, s16p, delay 1105, 192 kb/s
Metadata:
encoder : Lavc58.6.103 libmp3lame
frame= 29 fps=0.0 q=17.0 size= 146kB time=00:00:00.94 bitrate=1267.3kbits/s speed=1.86x
frame= 44 fps= 44 q=18.0 size= 168kB time=00:00:01.46 bitrate= 942.4kbits/s speed=1.45x
frame= 60 fps= 40 q=16.0 size= 191kB time=00:00:01.96 bitrate= 794.8kbits/s speed= 1.3x
...
frame= 2740 fps= 30 q=17.0 size= 7993kB time=00:01:31.32 bitrate= 717.0kbits/s speed= 1x
frame= 2755 fps= 30 q=18.0 size= 8013kB time=00:01:31.82 bitrate= 714.9kbits/s speed= 1x
[alsa @ 0x5607d084d7e0] ALSA buffer xrun.
</onstatus></createstream></onbwdone></connect> -
How i can add logo on any location on ffmpeg stream ? This is my command :
9 décembre 2017, par Jond Davidffmpeg -y -i input.mp4 -i "logo2.png" -filter_complex "[0:v]setpts=PTS/1.15,boxblur=2:1,scale=iw/1.75 :-1,pad=iw+26:ih+26:13:13:color=blue [v1] ; movie=bgmu.mp4:loop=999,setpts=N/(FRAME_RATE*TB) [v2] ; [v2][v1]overlay=shortest=1:x=W-w-30:y=H-h-22 [v3] ; [v3][1:v]overlay=0:0,setdar=16/9 ; [0:a]atempo=1.15, aecho=0.4:0.66:2:0.2, chorus=0.5:0.9:50|80:0.4|0.42:0.25|0.4:2|1.4, firequalizer=gain_entry=’entry(100,0) ; entry(400, -4) ; entry(1000, -6) ; entry(2000, 0)’,equalizer = f = 1000 : width_type = q : width = 1 : g = 2, equalizer = f = 100 : width_type = q : width = 2 : g = 5,pan=stereo|c0