
Recherche avancée
Autres articles (111)
-
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 -
Les formats acceptés
28 janvier 2010, parLes commandes suivantes permettent d’avoir des informations sur les formats et codecs gérés par l’installation local de ffmpeg :
ffmpeg -codecs ffmpeg -formats
Les format videos acceptés en entrée
Cette liste est non exhaustive, elle met en exergue les principaux formats utilisés : h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 m4v : raw MPEG-4 video format flv : Flash Video (FLV) / Sorenson Spark / Sorenson H.263 Theora wmv :
Les formats vidéos de sortie possibles
Dans un premier temps on (...) -
Encoding and processing into web-friendly formats
13 avril 2011, parMediaSPIP automatically converts uploaded files to internet-compatible formats.
Video files are encoded in MP4, Ogv and WebM (supported by HTML5) and MP4 (supported by Flash).
Audio files are encoded in MP3 and Ogg (supported by HTML5) and MP3 (supported by Flash).
Where possible, text is analyzed in order to retrieve the data needed for search engine detection, and then exported as a series of image files.
All uploaded files are stored online in their original format, so you can (...)
Sur d’autres sites (6208)
-
FFMPEG C Library : Encoding h264 stream into Matroska .mkv container creates corrupt files
16 mars 2024, par Marvin KillingI want to use the FFMPEG C Library to create a Matroska Video .mkv file with only an h264 stream, but the resulting .mkv file comes out corrupt.


The file cannot be played back with Windows Media Player, ffplay, or VLC, and when I try to
ffprobe
the resulting file, these are the error messages :

[h264 @ 0000015060d8f5c0] No start code is found.
 Last message repeated 1 times
[h264 @ 0000015060d8f5c0] non-existing PPS 0 referenced
 Last message repeated 1 times
[h264 @ 0000015060d8f5c0] decode_slice_header error
[h264 @ 0000015060d8f5c0] no frame!
[h264 @ 0000015060d8f5c0] non-existing PPS 0 referenced
 Last message repeated 1 times
[h264 @ 0000015060d8f5c0] decode_slice_header error
[h264 @ 0000015060d8f5c0] no frame!
[h264 @ 0000015060d8f5c0] non-existing PPS 0 referenced
 Last message repeated 1 times
# [...]
# this continues for a long time



I have followed the other troubleshooting steps for encoding h264 into Matroska, but none of them seemed to have done the trick for me :


- 

- Setting
AV_CODEC_FLAG_GLOBAL_HEADER
: Invalid data when creating mkv container with h264 stream because extradata is null - Allocating some space for extradata : Initializing an output file for muxing mkv with FFmpeg






This is my C code :


#include 
#include <libavutil></libavutil>opt.h>
#include <libavutil></libavutil>imgutils.h>
#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>

int main(void) {
 char *out_file_path = "./video.mkv";
 AVFormatContext *format_context;
 AVStream *video_stream;
 AVCodecContext *codec_context;

 avformat_alloc_output_context2(&format_context, NULL, NULL, out_file_path);

 const AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_H264);
 video_stream = avformat_new_stream(format_context, NULL);

 codec_context = avcodec_alloc_context3(codec);
 av_opt_set(codec_context->priv_data, "preset", "superfast", 0);
 av_opt_set(codec_context->priv_data, "crf", "22", 0);

 codec_context->width = 1920;
 codec_context->height = 1080;
 codec_context->time_base = av_make_q(1, 30);
 codec_context->pix_fmt = AV_PIX_FMT_YUV420P;

 if (strncmp("./video.mkv", out_file_path, 11) == 0) {
 printf("Writing .mkv...\n");
 codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
 codec_context->extradata = (uint8_t*)av_mallocz(1024 * 1024);
 codec_context->extradata_size = 1024 * 1024;
 } else {
 printf("Writing .mp4...\n");
 }

 // XXX avcodec_parameters_from_context is potentially superfluous (?)
 int ret = avcodec_parameters_from_context(video_stream->codecpar, codec_context);

 ret = avcodec_open2(codec_context, codec, NULL);

 avio_open(&format_context->pb, out_file_path, AVIO_FLAG_WRITE);

 ret = avformat_write_header(format_context, NULL);

 // create a black input frame
 AVFrame *input_frame = av_frame_alloc();
 input_frame->width = 1920;
 input_frame->height = 1080;
 input_frame->format = AV_PIX_FMT_YUV420P;
 ret = av_image_alloc(input_frame->data, input_frame->linesize, input_frame->width, input_frame->height, input_frame->format, 32);
 ptrdiff_t linesize[4] = { input_frame->linesize[0], input_frame->linesize[1], input_frame->linesize[2], input_frame->linesize[3] };
 ret = av_image_fill_black(input_frame->data, linesize, input_frame->format, 0, 1920, 1080);

 // write 2 seconds of video, all black
 for (size_t current_pts = 0; current_pts < 60; current_pts++) {
 input_frame->pts = av_rescale_q(current_pts, av_make_q(1, 30), codec_context->time_base);;

 ret = avcodec_send_frame(codec_context, input_frame);

 AVPacket* packet = av_packet_alloc();

 while (1) {
 ret = avcodec_receive_packet(codec_context, packet);
 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
 break;
 } else if (ret < 0) {
 printf("avcodec_receive_packet failed");
 } else {
 av_packet_rescale_ts(packet, codec_context->time_base, video_stream->time_base);
 ret = av_interleaved_write_frame(format_context, packet);
 }
 }

 av_packet_free(&packet);
 }

 av_frame_free(&input_frame);

 // flush encoder
 avcodec_send_frame(codec_context, NULL);
 AVPacket *flush_packet = av_packet_alloc();
 while (avcodec_receive_packet(codec_context, flush_packet) != AVERROR_EOF) {
 //int ret = av_interleaved_write_frame(format_context_, packet);
 av_packet_rescale_ts(flush_packet, codec_context->time_base, video_stream->time_base);
 ret = av_write_frame(format_context, flush_packet);
 }
 av_packet_free(&flush_packet);

 ret = av_write_trailer(format_context);
 ret = avio_close(format_context->pb);

 return 0;
}



The error handling is stripped out, but it does not raise any errors.


This code works when I write into an mp4 file, but creates a corrupt file when writing into .mkv. You can change the output container format to mp4 by setting

char *out_file_path = "./video.mp4";


You can compile this by running


clang -I$(FFMPEG_DIR)/include -L$(FFMPEG_DIR)/lib -lavformat -lavcodec -lavutil main.c -o makemkv



The output I’m getting while the above code is running :


Writing .mkv...
[libx264 @ 0x139804c40] using cpu capabilities: ARMv8 NEON
[libx264 @ 0x139804c40] profile High, level 4.0, 4:2:0, 8-bit
[libx264 @ 0x139804c40] 264 - core 164 r3108 31e19f9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2023 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x3 me=dia subme=1 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=15 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=crf mbtree=0 crf=22.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 pb_ratio=1.30 aq=1:1.00



When I use the ffmpeg CLI, I can create a working .mkv from my working .mp4 like this :


ffmpeg -i video.mp4 -c:v copy created-with-ffmpeg-cli.mkv



I have uploaded the resulting video files here : https://drive.google.com/drive/folders/1FS-0fBAwKBbO-tyxC0VrFqcCyyqd0BR_?usp=sharing


- Setting
-
Ffmpeg configuration to stream the frames of my webcam
6 juillet 2023, par RidwengI'm trying to build a server in NodeJs to stream in RTSP my webcam using Angular to retrieve the frames and connecting using websockets. The server side is using "express-ws" module to create the Websocket.


I was successfull in sending the frames from the webcam to the server in base64, the server is receiving these messages from a function on interval of (1000 / 30)ms.


The issue relies on the implementation of my Ffmpeg child process. I retrieve the message and convert it into a buffer to then write this in the function of Ffmpeg.


My current implementation is this one :


const { spawn } = require('child_process');
exports.stream = (ws ,req) => {
 try{
 const mess = `connection from: ${req._remoteAddress} at ${req._startTime}.`
 const initialMess =`Started ${mess}`
 ws.uuid = uuidv4()
 console.log(initialMess)

 ws.on('message', function incoming(message) {
 message = JSON.parse(message)
 console.log(`Res: ${message.width} x ${message.height}`);
 const ffmpeg = spawn('ffmpeg', [
 '-f', 'rawvideo',
 '-pixel_format', 'rgb24',
 '-video_size', `${message.width}x${message.height}`,
 '-framerate', `${message.framerate}`,
 '-i', '-',
 '-codec:v', 'libx264',
 '-preset', 'ultrafast',
 '-tune', 'zerolatency',
 '-f', 'rtsp',
 'rtsp://127.0.0.1:554/rtsp/stream',
 ]);
 const base64Data = message.video;
 const videoData = Buffer.from(base64Data, 'base64');

 ffmpeg.stdin.write(videoData);
 ffmpeg.stdin.end();
 
 ffmpeg.stderr.on('data', (data) => {
 console.error(`FFmpeg : ${data}`);
 });

 ffmpeg.on('exit', (code, signal) => {
 if (dev) console.log(`FFmpeg process exited with code ${code} and signal ${signal}`);
 
 // Close the WebSocket connection
 ws.close();
 });
 });
 ws.on('close', () => {
 const finalMess = `Stopped ${mess}`
 rem(ws.uuid)
 console.log(finalMess)
 })
 }catch(err){
 console.log(err)
 }
}



In terms of the message received, this is the Angular side sending the message :


const imageData = this.canvas.toDataURL('image/jpeg');
socket.send(JSON.stringify({video: imageData, width: this.canvas.width, height: this.canvas.height, framerate: interval }));



The interval variable is the divisor of the interval that is triggering the function (in this case 30).


I'm currently receiving the error message from Ffmpeg :


ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
 built with Apple clang version 14.0.3 (clang-1403.0.22.14.1)

FFmpeg : configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/6.0 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
 libavutil 58. 2.100 / 58. 2.100
 libavcodec 60. 3.100 / 60. 3.100
 libavformat 60. 3.100 / 60. 3.100
 libavdevice 60. 1.100 / 60. 1.100
 libavfilter 9. 3.100 / 9. 3.100
 libswscale 7. 1.100 / 7. 1.100
 libswresample 4. 10.100 / 4. 10.100
 libpostproc 57. 1.100 / 57. 1.100

FFmpeg : [rawvideo @ 0x150005ff0] Packet corrupt (stream = 0, dts = 0).

FFmpeg : Input #0, rawvideo, from 'fd:':
 Duration: N/A, start: 0.000000, bitrate: 221184 kb/s
 Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 640x480, 221184 kb/s, 30 tbr, 30 tbn

FFmpeg : Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))

FFmpeg : fd:: corrupt input packet in stream 0
[rawvideo @ 0x14ef24290] Invalid buffer size, packet size 76343 < expected frame_size 921600

FFmpeg : Error while decoding stream #0:0: Invalid argument

FFmpeg : [libx264 @ 0x14ef25a20] using cpu capabilities: ARMv8 NEON

FFmpeg : [libx264 @ 0x14ef25a20] profile High 4:4:4 Predictive, level 3.0, 4:4:4, 8-bit

FFmpeg : [libx264 @ 0x14ef25a20] 264 - core 164 r3095 baee400 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - 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=6 threads=7 lookahead_threads=7 sliced_threads=1 slices=7 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0

FFmpeg : [tcp @ 0x1500078a0] Connection to tcp://127.0.0.1:554?timeout=0 failed: Connection refused
[out#0/rtsp @ 0x14ef24b00] Could not write header (incorrect codec parameters ?): Connection refused

FFmpeg : [vost#0:0/libx264 @ 0x14ef256d0] Error initializing output stream: 

FFmpeg : Conversion failed!

FFmpeg process exited with code 1 and signal null



This is the reason I believe the issue relies on the configuration of Ffmpeg and how to set it for this case. It would be great to being able to play this RTSP link in my VLC to conclude it as successfull.


I would apreciate any suggestions or guidence.
Thanks in advance.


-
Receive RTMP stream with OpenCV (python)
12 février 2024, par OvernoutI'm trying to process an RTMP stream in Python, using OpenCV2 but I'm not able to get OpenCV to capture it.


I can run FFmpeg/FFplay from the command line and receive the stream successfully.
What could cause OpenCV to fail opening the stream in listening mode ?


Here is my code :


import cv2

cap = cv2.VideoCapture("rtmp://0.0.0.0/live/stream", cv2.CAP_FFMPEG)

if not cap.isOpened():
 print("Cannot open video source")
 exit()



And the output :


[tcp @ 00000192c490d640] Connection to tcp://0.0.0.0:1935 failed: Error number -138 occurred
[rtmp @ 00000192c490d580] Cannot open connection tcp://0.0.0.0:1935 Cannot open video source



Here is the output of cv2.getBuildInformation()


General configuration for OpenCV 4.9.0 =====================================
 Version control: 4.9.0

 Platform:
 Timestamp: 2023-12-31T11:21:12Z
 Host: Windows 10.0.17763 AMD64
 CMake: 3.24.2
 CMake generator: Visual Studio 14 2015
 CMake build tool: MSBuild.exe
 MSVC: 1900
 Configuration: Debug Release

 CPU/HW features:
 Baseline: SSE SSE2 SSE3
 requested: SSE3
 Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2
 requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
 SSE4_1 (16 files): + SSSE3 SSE4_1
 SSE4_2 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2
 FP16 (0 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
 AVX (8 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
 AVX2 (36 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2

 C/C++:
 Built as dynamic libs?: NO
 C++ standard: 11
 C++ Compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe (ver 19.0.24247.2)
 C++ flags (Release): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP /O2 /Ob2 /DNDEBUG 
 C++ flags (Debug): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP /Zi /Ob0 /Od /RTC1 
 C Compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
 C flags (Release): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /O2 /Ob2 /DNDEBUG 
 C flags (Debug): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /Zi /Ob0 /Od /RTC1 
 Linker flags (Release): /machine:x64 /NODEFAULTLIB:atlthunk.lib /INCREMENTAL:NO /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib
 Linker flags (Debug): /machine:x64 /NODEFAULTLIB:atlthunk.lib /debug /INCREMENTAL /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib
 ccache: NO
 Precompiled headers: YES
 Extra dependencies: wsock32 comctl32 gdi32 ole32 setupapi ws2_32
 3rdparty dependencies: libprotobuf ade ittnotify libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf zlib ippiw ippicv

 OpenCV modules:
 To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching video videoio
 Disabled: java world
 Disabled by dependency: -
 Unavailable: python2 ts
 Applications: -
 Documentation: NO
 Non-free algorithms: NO

 Windows RT support: NO

 GUI: WIN32UI
 Win32 UI: YES
 VTK support: NO

 Media I/O: 
 ZLib: build (ver 1.3)
 JPEG: build-libjpeg-turbo (ver 2.1.3-62)
 SIMD Support Request: YES
 SIMD Support: NO
 WEBP: build (ver encoder: 0x020f)
 PNG: build (ver 1.6.37)
 TIFF: build (ver 42 - 4.2.0)
 JPEG 2000: build (ver 2.5.0)
 OpenEXR: build (ver 2.3.0)
 HDR: YES
 SUNRASTER: YES
 PXM: YES
 PFM: YES

 Video I/O:
 DC1394: NO
 FFMPEG: YES (prebuilt binaries)
 avcodec: YES (58.134.100)
 avformat: YES (58.76.100)
 avutil: YES (56.70.100)
 swscale: YES (5.9.100)
 avresample: YES (4.0.0)
 GStreamer: NO
 DirectShow: YES
 Media Foundation: YES
 DXVA: YES

 Parallel framework: Concurrency

 Trace: YES (with Intel ITT)

 Other third-party libraries:
 Intel IPP: 2021.11.0 [2021.11.0]
 at: D:/a/opencv-python/opencv-python/_skbuild/win-amd64-3.7/cmake-build/3rdparty/ippicv/ippicv_win/icv
 Intel IPP IW: sources (2021.11.0)
 at: D:/a/opencv-python/opencv-python/_skbuild/win-amd64-3.7/cmake-build/3rdparty/ippicv/ippicv_win/iw
 Lapack: NO
 Eigen: NO
 Custom HAL: NO
 Protobuf: build (3.19.1)
 Flatbuffers: builtin/3rdparty (23.5.9)

 OpenCL: YES (NVD3D11)
 Include path: D:/a/opencv-python/opencv-python/opencv/3rdparty/include/opencl/1.2
 Link libraries: Dynamic load

 Python 3:
 Interpreter: C:/hostedtoolcache/windows/Python/3.7.9/x64/python.exe (ver 3.7.9)
 Libraries: C:/hostedtoolcache/windows/Python/3.7.9/x64/libs/python37.lib (ver 3.7.9)
 numpy: C:/hostedtoolcache/windows/Python/3.7.9/x64/lib/site-packages/numpy/core/include (ver 1.17.0)
 install path: python/cv2/python-3

 Python (for build): C:\hostedtoolcache\windows\Python\3.7.9\x64\python.exe

 Java: 
 ant: NO
 Java: YES (ver 1.8.0.392)
 JNI: C:/hostedtoolcache/windows/Java_Temurin-Hotspot_jdk/8.0.392-8/x64/include C:/hostedtoolcache/windows/Java_Temurin-Hotspot_jdk/8.0.392-8/x64/include/win32 C:/hostedtoolcache/windows/Java_Temurin-Hotspot_jdk/8.0.392-8/x64/include
 Java wrappers: NO
 Java tests: NO

 Install to: D:/a/opencv-python/opencv-python/_skbuild/win-amd64-3.7/cmake-install
-----------------------------------------------------------------