
Recherche avancée
Autres articles (105)
-
Configurer la prise en compte des langues
15 novembre 2010, parAccéder à la configuration et ajouter des langues prises en compte
Afin de configurer la prise en compte de nouvelles langues, il est nécessaire de se rendre dans la partie "Administrer" du site.
De là, dans le menu de navigation, vous pouvez accéder à une partie "Gestion des langues" permettant d’activer la prise en compte de nouvelles langues.
Chaque nouvelle langue ajoutée reste désactivable tant qu’aucun objet n’est créé dans cette langue. Dans ce cas, elle devient grisée dans la configuration et (...) -
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" ; -
MediaSPIP version 0.1 Beta
16 avril 2011, parMediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
Pour avoir une installation fonctionnelle, 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 (...)
Sur d’autres sites (6679)
-
Hikvision NVR video conversion ffmpeg
6 août 2024, par astralmasterI have a Hikvision NVR that stores security camera footage that I need to display on a website. I know that Hikvision uses proprietary H.264 codec that makes it impossible to play (coherently) in popular video players, like VLC, unless you install that codec everywhere you play it.



My plan was to transcode the video using ffmpeg to regular H.264 codec and AAC for audio but the produced file has the same issues as the original - no audio when playing and very disruptive video. 
So the question is, does ffmpeg support encoding from Hikvision video/audio codecs ? Or perhaps should try to convert to different web-capable codecs using ffmpeg ?
My ffmpeg command looks like this :



ffmpeg -i C:\1.mp4 -c:v libx264 -preset fast -crf 30 -b:v 200k -c:a aac -strict experimental -movflags faststart -threads 0 C:\2.mp4




EDIT : What's interesting is that
ffplay.exe
opens and plays the original video files with no problem whatsoever, even on a computer where Hikvision codecs are not isntalled, therefore I figured conversion should be possible as well ?


Mediainfo output of the video file in question :



General
CompleteName : C:\DownLoad\1.mp4
Format : MPEG-PS
FileSize/String : 8.60 MiB
Duration/String : 2 h 7 min
OverallBitRate/String : 9 395 b/s
FileExtension_Invalid : mpeg mpg m2p vob pss evo

Video
ID/String : 224 (0xE0)
Format : AVC
Format/Info : Advanced Video Codec
Format_Profile : Baseline@L4
Format_Settings : 1 Ref Frames
Format_Settings_CABAC/String : No
Format_Settings_RefFrames/String : 1 frame
Format_Settings_GOP : M=1, N=30
Duration/String : 2 min 0 s
Width/String : 1 920 pixels
Height/String : 1 080 pixels
DisplayAspectRatio/String : 16:9
FrameRate_Mode/String : Variable
ColorSpace : YUV
ChromaSubsampling/String : 4:2:0
BitDepth/String : 8 bits
ScanType/String : Progressive

Audio
ID/String : 192 (0xC0)
Format : MPEG Audio
Duration/String : 2 h 7 min
Compression_Mode/String : Lossy
Video_Delay/String : -33 min 40 s




Output of ffmpeg :



C:\ffmpeg\bin>ffmpeg -i C:\DownLoad\1.mp4 -c:v libx264 -preset fast -crf 30 -b:v 75k -c:a aac -strict experimental -movflags faststart -threads 0 C:\DownLoad\2.mp4
ffmpeg version N-86537-gae6f6d4 Copyright (c) 2000-2017 the FFmpeg developers
 built with gcc 7.1.0 (GCC)
 configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
 libavutil 55. 66.100 / 55. 66.100
 libavcodec 57. 99.100 / 57. 99.100
 libavformat 57. 73.100 / 57. 73.100
 libavdevice 57. 7.100 / 57. 7.100
 libavfilter 6. 94.100 / 6. 94.100
 libswscale 4. 7.101 / 4. 7.101
 libswresample 2. 8.100 / 2. 8.100
 libpostproc 54. 6.100 / 54. 6.100
Input #0, mpeg, from 'C:\DownLoad\1.mp4':
 Duration: 02:07:57.93, start: 789.820800, bitrate: 9 kb/s
 Stream #0:0[0x1e0]: Video: h264 (Baseline), yuv420p(progressive), 1920x1080, 25 fps, 25 tbr, 90k tbn, 50 tbc
 Stream #0:1[0x1c0]: Audio: pcm_mulaw, 8000 Hz, mono, s16, 64 kb/s
File 'C:\DownLoad\2.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
 Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
 Stream #0:1 -> #0:1 (pcm_mulaw (native) -> aac (native))
Press [q] to stop, [?] for help
[aac @ 0000000002cd0280] Too many bits 8832.000000 > 6144 per frame requested, clamping to max
[libx264 @ 0000000002514c80] using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX XOP FMA4
[libx264 @ 0000000002514c80] profile High, level 4.0
[libx264 @ 0000000002514c80] 264 - core 150 r2833 df79067 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=6 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=30 rc=crf mbtree=1 crf=30.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'C:\DownLoad\2.mp4':
 Metadata:
 encoder : Lavf57.73.100
 Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1920x1080, q=-1--1, 75 kb/s, 25 fps, 12800 tbn, 25 tbc
 Metadata:
 encoder : Lavc57.99.100 libx264
 Side data:
 cpb: bitrate max/min/avg: 0/0/75000 buffer size: 0 vbv_delay: -1
 Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 8000 Hz, mono, fltp, 48 kb/s
 Metadata:
 encoder : Lavc57.99.100 aac
[mp4 @ 00000000010e9e00] Starting second pass: moving the moov atom to the beginning of the file speed= 116x
frame= 3269 fps= 66 q=-1.0 Lsize= 11086kB time=01:34:24.38 bitrate= 16.0kbits/s dup=269 drop=0 speed= 115x
video:10429kB audio:592kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.594114%
[libx264 @ 0000000002514c80] frame I:14 Avg QP:21.86 size: 59795
[libx264 @ 0000000002514c80] frame P:833 Avg QP:24.81 size: 8993
[libx264 @ 0000000002514c80] frame B:2422 Avg QP:28.70 size: 970
[libx264 @ 0000000002514c80] consecutive B-frames: 1.0% 0.2% 1.4% 97.4%
[libx264 @ 0000000002514c80] mb I I16..4: 18.9% 66.3% 14.8%
[libx264 @ 0000000002514c80] mb P I16..4: 4.0% 7.7% 0.4% P16..4: 16.2% 2.0% 0.6% 0.0% 0.0% skip:69.1%
[libx264 @ 0000000002514c80] mb B I16..4: 0.6% 0.2% 0.0% B16..8: 5.5% 0.1% 0.0% direct: 0.7% skip:92.9% L0:44.0% L1:55.0% BI: 1.0%
[libx264 @ 0000000002514c80] 8x8 transform intra:59.0% inter:83.3%
[libx264 @ 0000000002514c80] coded y,uvDC,uvAC intra: 25.3% 36.1% 7.7% inter: 1.0% 2.3% 0.1%
[libx264 @ 0000000002514c80] i16 v,h,dc,p: 23% 24% 43% 10%
[libx264 @ 0000000002514c80] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 37% 26% 23% 2% 2% 3% 2% 3% 3%
[libx264 @ 0000000002514c80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 43% 23% 12% 4% 4% 5% 4% 4% 2%
[libx264 @ 0000000002514c80] i8c dc,h,v,p: 81% 7% 9% 3%
[libx264 @ 0000000002514c80] Weighted P-Frames: Y:1.0% UV:0.0%
[libx264 @ 0000000002514c80] ref P L0: 73.6% 26.4%
[libx264 @ 0000000002514c80] ref B L0: 80.9% 19.1%
[libx264 @ 0000000002514c80] ref B L1: 90.0% 10.0%
[libx264 @ 0000000002514c80] kb/s:653.30
[aac @ 0000000002cd0280] Qavg: 64512.656

C:\ffmpeg\bin>




Download link to sample :



https://www.dropbox.com/s/9ccptsuiqk2ntsv/1.zip?dl=0



This sample is exactly 2 minutes long, but VLC will tell you otherwise.


-
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.
-
Codec issue ? Mp4 video flashing during play via JW Player (and same issue with mac computer)
19 décembre 2017, par janosdupaiI have a linux based server online. It has Mp4 videos. I try to play these video with JW Player. I had any problems with them, but some files has the following problem : https://www.video.match-meeting.com/drive/5a350a6700bc4.mp4
If I download this file to a windows computer, it plays without problem. Is that a codec problem with my server (and on my mac) ?