
Recherche avancée
Médias (91)
-
Richard Stallman et le logiciel libre
19 octobre 2011, par
Mis à jour : Mai 2013
Langue : français
Type : Texte
-
Stereo master soundtrack
17 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Audio
-
Elephants Dream - Cover of the soundtrack
17 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Image
-
#7 Ambience
16 octobre 2011, par
Mis à jour : Juin 2015
Langue : English
Type : Audio
-
#6 Teaser Music
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#5 End Title
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
Autres articles (56)
-
Submit bugs and patches
13 avril 2011Unfortunately a software is never perfect.
If you think you have found a bug, report it using our ticket system. Please to help us to fix it by providing the following information : the browser you are using, including the exact version as precise an explanation as possible of the problem if possible, the steps taken resulting in the problem a link to the site / page in question
If you think you have solved the bug, fill in a ticket and attach to it a corrective patch.
You may also (...) -
MediaSPIP 0.1 Beta version
25 avril 2011, parMediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
The zip file provided here only contains the sources of MediaSPIP in its standalone version.
To get a working installation, you must manually install all-software dependencies on the server.
If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...) -
Participer à sa traduction
10 avril 2011Vous pouvez nous aider à améliorer les locutions utilisées dans le logiciel ou à traduire celui-ci dans n’importe qu’elle nouvelle langue permettant sa diffusion à de nouvelles communautés linguistiques.
Pour ce faire, on utilise l’interface de traduction de SPIP où l’ensemble des modules de langue de MediaSPIP sont à disposition. ll vous suffit de vous inscrire sur la liste de discussion des traducteurs pour demander plus d’informations.
Actuellement MediaSPIP n’est disponible qu’en français et (...)
Sur d’autres sites (3870)
-
FFmpeg HLS input stream shows "Packet corrupt" and "timestamp discontinuity" errors when pushing to RTMP server [closed]
22 mai, par Amul BhatiaI'm trying to restream an HLS URL (https://cache.fastcdn.com.my/edge/53-1.stream/index_0.m3u8?misc=87uq4HjbDEDE3TzIY95ja1ZMxA-Cm1PbOXAk16riVlU&uid=139322&ts=1747931206&e=43200&lat=1747931206&sil=5&sk=no&uip=MTEwLjIyNC4yNDIuOTg&head=aHR0cF94X2ZvcndhcmRlZF9mb3I&chid=53-1') into my RTMP server with FFmpeg. The command I use is :


ffmpeg -i "https://cache.fastcdn.com.my/edge/53-1.stream/index_0.m3u8?misc=87uq4HjbDEDE3TzIY95ja1ZMxA-Cm1PbOXAk16riVlU&uid=139322&ts=1747931206&e=43200&lat=1747931206&sil=5&sk=no&uip=MTEwLjIyNC4yNDIuOTg&head=aHR0cF94X2ZvcndhcmRlZF9mb3I&chid=53-1" -c:v libx264 -preset veryfast -b:v 1000k -c:a aac -b:a 128k -f flv rtmp://69.62.85.241/live/streamkey



getting error


ffmpeg version 6.1.1-3ubuntu5 Copyright (c) 2000-2023 the FFmpeg developers
 built with gcc 13 (Ubuntu 13.2.0-23ubuntu3)
 configuration: --prefix=/usr --extra-version=3ubuntu5 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --disable-omx --enable-gnutls --enable-libaom --enable-libass --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libglslang --enable-libgme --enable-libgsm --enable-libharfbuzz --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-openal --enable-opencl --enable-opengl --disable-sndio --enable-libvpl --disable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-ladspa --enable-libbluray --enable-libjack --enable-libpulse --enable-librabbitmq --enable-librist --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libx264 --enable-libzmq --enable-libzvbi --enable-lv2 --enable-sdl2 --enable-libplacebo --enable-librav1e --enable-pocketsphinx --enable-librsvg --enable-libjxl --enable-shared
 libavutil 58. 29.100 / 58. 29.100
 libavcodec 60. 31.102 / 60. 31.102
 libavformat 60. 16.100 / 60. 16.100
 libavdevice 60. 3.100 / 60. 3.100
 libavfilter 9. 12.100 / 9. 12.100
 libswscale 7. 5.100 / 7. 5.100
 libswresample 4. 12.100 / 4. 12.100
 libpostproc 57. 3.100 / 57. 3.100
[hls @ 0x60992c0c8880] Skip ('#EXT-X-VERSION:3')
[hls @ 0x60992c0c8880] Skip ('#EXT-X-DISCONTINUITY')
 Last message repeated 9 times
[hls @ 0x60992c0c8880] Opening 'https://cache.fastcdn.com.my/error/chunks/407.ts' for reading
 Last message repeated 1 times
Input #0, hls, from 'https://cache.fastcdn.com.my/edge/53-1.stream/index_0.m3u8?misc=87uq4HjbDEDE3TzIY95ja1ZMxA-Cm1PbOXAk16riVlU&uid=139322&ts=1747931206&e=43200&lat=1747931206&sil=5&sk=no&uip=MTEwLjIyNC4yNDIuOTg&head=aHR0cF94X2ZvcndhcmRlZF9mb3I&chid=53-1':
 Duration: 00:01:00.00, start: 1.466667, bitrate: 0 kb/s
 Program 0
 Metadata:
 variant_bitrate : 0
 Stream #0:0: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, unknown/bt709/iec61966-2-1), 854x480 [SAR 1:1 DAR 427:240], 30 fps, 30 tbr, 90k tbn
 Metadata:
 variant_bitrate : 0
Stream mapping:
 Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x60992cd68b00] using SAR=1/1
[libx264 @ 0x60992cd68b00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 AVX512
[libx264 @ 0x60992cd68b00] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 0x60992cd68b00] 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:0x113 me=hex subme=2 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=3 lookahead_threads=1 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=10 rc=abr mbtree=1 bitrate=1000 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://69.62.85.241/live/streamkey':
 Metadata:
 encoder : Lavf60.16.100
 Stream #0:0: Video: h264 ([7][0][0][0] / 0x0007), yuv420p(tv, unknown/bt709/iec61966-2-1, progressive), 854x480 [SAR 1:1 DAR 427:240], q=2-31, 1000 kb/s, 30 fps, 1k tbn
 Metadata:
 variant_bitrate : 0
 encoder : Lavc60.31.102 libx264
 Side data:
 cpb: bitrate max/min/avg: 0/0/1000000 buffer size: 0 vbv_delay: N/A
[https @ 0x60992c48fc40] Opening 'https://cache.fastcdn.com.my/error/chunks/407.ts' for reading
[mpegts @ 0x60992c161940] Packet corrupt (stream = 0, dts = 663000).
[hls @ 0x60992c0c8880] Packet corrupt (stream = 0, dts = 660000).
[in#0/hls @ 0x60992c0c8780] corrupt input packet in stream 0
[vist#0:0/h264 @ 0x60992c47ae80] timestamp discontinuity (stream id=0): -6000000, new offset= 6000000
[https @ 0x60992c4a9d40] Opening 'https://cache.fastcdn.com.my/error/chunks/407.ts' for reading
[mpegts @ 0x60992c161940] Packet corrupt (stream = 0, dts = 663000).
[hls @ 0x60992c0c8880] Packet corrupt (stream = 0, dts = 660000).
[in#0/hls @ 0x60992c0c8780] corrupt input packet in stream 0
[vist#0:0/h264 @ 0x60992c47ae80] timestamp discontinuity (stream id=0): -6000000, new offset= 12000000
[https @ 0x60992c48fc40] Opening 'https://cache.fastcdn.com.my/error/chunks/407.ts' for reading
[mpegts @ 0x60992c161940] Packet corrupt (stream = 0, dts = 663000).
[hls @ 0x60992c0c8880] Packet corrupt (stream = 0, dts = 660000).
[in#0/hls @ 0x60992c0c8780] corrupt input packet in stream 0
[vist#0:0/h264 @ 0x60992c47ae80] timestamp discontinuity (stream id=0): -6000000, new offset= 18000000
[https @ 0x60992c4a9d40] Opening 'https://cache.fastcdn.com.my/error/chunks/407.ts' for reading
[mpegts @ 0x60992c161940] Packet corrupt (stream = 0, dts = 663000).
[hls @ 0x60992c0c8880] Packet corrupt (stream = 0, dts = 660000).
[in#0/hls @ 0x60992c0c8780] corrupt input packet in stream 0
[vist#0:0/h264 @ 0x60992c47ae80] timestamp discontinuity (stream id=0): -6000000, new offset= 24000000
[https @ 0x60992c48fc40] Opening 'https://cache.fastcdn.com.my/error/chunks/407.ts' for reading
[mpegts @ 0x60992c161940] Packet corrupt (stream = 0, dts = 663000).
[hls @ 0x60992c0c8880] Packet corrupt (stream = 0, dts = 660000).
[in#0/hls @ 0x60992c0c8780] corrupt input packet in stream 0
[vist#0:0/h264 @ 0x60992c47ae80] timestamp discontinuity (stream id=0): -6000000, new offset= 30000000
[https @ 0x60992c4a9d40] Opening 'https://cache.fastcdn.com.my/error/chunks/407.ts' for reading
[mpegts @ 0x60992c161940] Packet corrupt (stream = 0, dts = 663000).
[hls @ 0x60992c0c8880] Packet corrupt (stream = 0, dts = 660000).
[in#0/hls @ 0x60992c0c8780] corrupt input packet in stream 0
[vist#0:0/h264 @ 0x60992c47ae80] timestamp discontinuity (stream id=0): -6000000, new offset= 36000000
[https @ 0x60992c48fc40] Opening 'https://cache.fastcdn.com.my/error/chunks/407.ts' for reading
[mpegts @ 0x60992c161940] Packet corrupt (stream = 0, dts = 663000).
[hls @ 0x60992c0c8880] Packet corrupt (stream = 0, dts = 660000).
[in#0/hls @ 0x60992c0c8780] corrupt input packet in stream 0
[vist#0:0/h264 @ 0x60992c47ae80] timestamp discontinuity (stream id=0): -6000000, new offset= 42000000
[https @ 0x60992c4a9d40] Opening 'https://cache.fastcdn.com.my/error/chunks/407.ts' for reading
[mpegts @ 0x60992c161940] Packet corrupt (stream = 0, dts = 663000).
[hls @ 0x60992c0c8880] Packet corrupt (stream = 0, dts = 660000).
[in#0/hls @ 0x60992c0c8780] corrupt input packet in stream 0
[vist#0:0/h264 @ 0x60992c47ae80] timestamp discontinuity (stream id=0): -6000000, new offset= 48000000
[mpegts @ 0x60992c161940] Packet corrupt (stream = 0, dts = 663000).
[hls @ 0x60992c0c8880] Packet corrupt (stream = 0, dts = 660000).
[in#0/hls @ 0x60992c0c8780] corrupt input packet in stream 0
[vist#0:0/h264 @ 0x60992c47ae80] timestamp discontinuity (stream id=0): -6000000, new offset= 54000000
[flv @ 0x60992c88a340] Failed to update header with correct duration.44.8kbits/s speed=22.6x
[flv @ 0x60992c88a340] Failed to update header with correct filesize.
[out#0/flv @ 0x60992cc36180] video:304kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 11.671993%
frame= 1800 fps=685 q=-1.0 Lsize= 339kB time=00:00:59.90 bitrate= 46.4kbits/s speed=22.8x
[libx264 @ 0x60992cd68b00] frame I:8 Avg QP: 2.07 size: 20330
[libx264 @ 0x60992cd68b00] frame P:454 Avg QP: 0.23 size: 218
[libx264 @ 0x60992cd68b00] frame B:1338 Avg QP: 0.21 size: 37
[libx264 @ 0x60992cd68b00] consecutive B-frames: 0.9% 0.0% 0.0% 99.1%
[libx264 @ 0x60992cd68b00] mb I I16..4: 86.7% 0.3% 13.0%
[libx264 @ 0x60992cd68b00] mb P I16..4: 0.1% 0.0% 0.0% P16..4: 1.4% 0.0% 0.0% 0.0% 0.0% skip:98.6%
[libx264 @ 0x60992cd68b00] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.1% 0.0% 0.0% direct: 0.1% skip:99.8% L0:59.9% L1:40.1% BI: 0.0%
[libx264 @ 0x60992cd68b00] final ratefactor: -25.04
[libx264 @ 0x60992cd68b00] 8x8 transform intra:0.3% inter:1.8%
[libx264 @ 0x60992cd68b00] coded y,uvDC,uvAC intra: 13.5% 0.0% 0.0% inter: 0.2% 0.0% 0.0%
[libx264 @ 0x60992cd68b00] i16 v,h,dc,p: 90% 6% 4% 0%
[libx264 @ 0x60992cd68b00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 59% 12% 28% 0% 1% 1% 0% 0% 0%
[libx264 @ 0x60992cd68b00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 41% 18% 19% 4% 4% 4% 3% 4% 3%
[libx264 @ 0x60992cd68b00] i8c dc,h,v,p: 100% 0% 0% 0%
[libx264 @ 0x60992cd68b00] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x60992cd68b00] kb/s:41.38



However, I get repeated errors like :


Packet corrupt (stream = 0, dts = xxxx)


timestamp discontinuity (stream id=0)


corrupt input packet in stream 0


The stream partially works but seems unstable. How can I fix this error ?


my nginx.conf


rtmp {
 server {
 listen 1935;
 chunk_size 4096;

 application live {
 live on;
 record off;

 hls on;
 hls_path /var/www/hls;
 hls_fragment 5; # each TS segment = 5s
 hls_playlist_length 120; # keep last 2 minutes of stream
 hls_cleanup off; # do not delete old segments
 }
 }
}

http {
 include mime.types;
 default_type application/octet-stream;

 sendfile on;
 keepalive_timeout 65;

 server {
 listen 81;

 location /hls {
 root /var/www;
 types {
 application/vnd.apple.mpegurl m3u8;
 video/mp2t ts;
 }

 add_header Cache-Control no-cache;
 add_header Access-Control-Allow-Origin *;
 add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
 add_header Access-Control-Allow-Headers 'Range';
 add_header Access-Control-Expose-Headers 'Content-Length, Content-Range';
 }
 }
}



The same url is working fine when used in browser, but extracting the stream and putting it in RTMP server and accessing my RTMP server at rtmp ://69.62.85.241/live/streamkey not working


-
FFMpeg Coding in C : Encoder returns EOF at first interaction. Encoder not opened correctly ? [closed]
26 février, par Davidhoheyas I'm fairly new to FFMpeg Programming and C in general, the code looks like a mess.


I have smashed my head against a wall trying to get this code to work for about a week.


int decode_encode_pipeline(AVFormatContext *Input_Format_Context, AVFormatContext *Output_Format_Context, int *streams_list){

 const AVCodec *DECodec, *ENCodec;
 AVCodecContext *DECodecContext = NULL, *ENCodecContext = NULL;
 AVCodecParameters *CodecParameters = NULL;
 AVDictionary *opts = NULL;
 AVPacket *Packet;
 AVFrame *Frame;
 int check;

 Packet = av_packet_alloc();
 if(!Packet){
 
 printf("\nFehler bei Allocating Packet");
 
 return 0;
 
 }

 Frame = av_frame_alloc();
 if(!Frame){
 
 printf("\nFehler bei Allocating Frame");
 
 return 0;
 
 }

 CodecParameters = Input_Format_Context->streams[Packet->stream_index]->codecpar;
 if(!CodecParameters){

 printf("\nCodecParameters konnte nicht erstellt oder zugewiesen werden.");

 }

 DECodec = avcodec_find_decoder(CodecParameters->codec_id);
 if(!DECodec){
 
 printf("\nCodec nicht gefunden");
 
 return 0;
 
 }

 DECodecContext = avcodec_alloc_context3(DECodec);
 if (!DECodecContext){
 
 printf("\nFehler bei Allocating CodecContext");
 
 return 0;
 
 }

 ENCodec = avcodec_find_encoder(CodecParameters->codec_id);
 if(!DECodec){
 
 printf("\nCodec nicht gefunden");
 
 return 0;
 
 }

 ENCodecContext = avcodec_alloc_context3(ENCodec);
 if (!ENCodecContext){
 
 printf("\nFehler bei Allocating CodecContext");
 
 return 0;
 
 }

 check = avformat_write_header(Output_Format_Context, &opts);
 if(check < 0){

 printf("\nFehler beim Öffnen des Output Files.");
 
 return 1;

 }

 avcodec_parameters_to_context(DECodecContext, CodecParameters);
 avcodec_parameters_to_context(ENCodecContext, CodecParameters);

 ENCodecContext->width = DECodecContext->width;
 ENCodecContext->height = DECodecContext->height;
 ENCodecContext->bit_rate = DECodecContext->bit_rate;
 ENCodecContext->time_base = (AVRational){1, 30};
 ENCodecContext->framerate = DECodecContext->framerate;
 ENCodecContext->gop_size = DECodecContext->gop_size;
 ENCodecContext->max_b_frames = DECodecContext->max_b_frames;
 ENCodecContext->pix_fmt = DECodecContext->pix_fmt;
 if(ENCodec->id == AV_CODEC_ID_H264){

 av_opt_set(ENCodecContext->priv_data, "preset", "slow", 0);

 }

 check = avcodec_open2(DECodecContext, DECodec, NULL);
 if(check < 0){
 
 printf("\nFehler bei Öffnen von DECodec");
 
 return 1;
 
 }

 check = avcodec_open2(ENCodecContext, ENCodec, NULL);
 if(check < 0){
 
 printf("\nFehler bei Öffnen von ENCodec");
 
 return 1;
 
 }

 while(1){
 
 check = av_read_frame(Input_Format_Context, Packet);
 if(check < 0){
 
 break;
 
 }

 AVStream *in_stream, *out_stream;

 in_stream = Input_Format_Context->streams[Packet->stream_index];
 out_stream = Output_Format_Context->streams[Packet->stream_index];

 if(in_stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && Packet->stream_index == streams_list[Packet->stream_index]){

 check = avcodec_send_packet(DECodecContext, Packet);
 if(check < 0){

 printf("\nFehler bei Encoding");

 return 1;

 }

 AVPacket *EncodedPacket;
 EncodedPacket = av_packet_alloc();
 if(!EncodedPacket){
 
 printf("\nFehler bei Allocating Packet");
 
 return 1;
 
 }

 /*While Loop Decoding*/
 while(check >= 0){
 
 check = avcodec_receive_frame(DECodecContext, Frame);
 if(check == AVERROR(EAGAIN)){
 
 continue;
 
 }else if(check == AVERROR_EOF){
 
 break;
 
 }else if(check < 0){
 
 printf("\nFehler bei Decoding");
 
 return 1;
 
 }

 /*Convert Colorspace*/
 struct SwsContext *SwsContexttoRGB = sws_getContext(Frame->width, Frame->height, Frame->format, Frame->width, Frame->height, AV_PIX_FMT_RGB24, SWS_BILINEAR, NULL, NULL, NULL);
 struct SwsContext *SwsContexttoOriginal = sws_getContext(Frame->width, Frame->height, AV_PIX_FMT_RGB24, Frame->width, Frame->height, Frame->format, SWS_BILINEAR, NULL, NULL, NULL);
 if(!SwsContexttoRGB || !SwsContexttoOriginal){

 printf("\nSwsContext konnte nicht befüllt werden.");

 return 1;

 } 

 if(Frame->linesize < 0){

 printf("\nFehler: linesize ist negativ und nicht kompatibel\n");

 return 1;

 }

 AVFrame *RGBFrame;
 RGBFrame = av_frame_alloc();
 if(!RGBFrame){

 printf("\nFehler bei der Reservierung für den RGBFrame");

 return 1;

 }
 /*
 int number_bytes = av_image_get_buffer_size(AV_PIX_FMT_RGB24, Frame->width, Frame->height, 1);
 if(number_bytes < 0){

 printf("\nFehler bei der Berechnung der benoetigten Bytes fuer Konvertierung");

 return 1;

 }
 
 uint8_t *rgb_buffer = (uint8_t *)av_malloc(number_bytes*sizeof(uint8_t));
 if(rgb_buffer == NULL){

 printf("\nFehler bei der Reservierung für den RGBBuffer");

 return 1;

 }

 check = av_image_fill_arrays(RGBFrame->data, RGBFrame->linesize, rgb_buffer, AV_PIX_FMT_RGB24, Frame->width, Frame->height, 1);
 if(check < 0){

 printf("\nFehler bei der Zuweisung der RGB Daten");

 return 1;

 }*/

 //sws_scale(SwsContexttoRGB, (const uint8_t * const *)Frame->data, Frame->linesize, 0, Frame->height, RGBFrame->data, RGBFrame->linesize);
 sws_scale_frame(SwsContexttoRGB, Frame, RGBFrame);
 printf("\nIch habe die Daten zu RGB konvertiert.");

 //sws_scale(SwsContexttoOriginal, (const uint8_t * const *)RGBFrame->data, RGBFrame->linesize, 0, Frame->height, Frame->data, Frame->linesize);
 sws_scale_frame(SwsContexttoOriginal, RGBFrame, Frame);
 printf("\nIch habe die Daten zurück ins Original konvertiert.");

 Frame->format = ENCodecContext->pix_fmt;
 Frame->width = ENCodecContext->width;
 Frame->height = ENCodecContext->height;
 
 check = av_frame_get_buffer(Frame, 0);
 if(check < 0){
 
 printf("\nFehler bei Allocating Frame Buffer");
 
 return 1;
 
 }

 /* Encoding */
 check = av_frame_make_writable(Frame);
 if(check < 0){

 printf("\nFehler bei Make Frame Writable");

 return 1;

 }

 encode(ENCodecContext, Frame, EncodedPacket, Output_Format_Context);

 sws_freeContext(SwsContexttoRGB);
 sws_freeContext(SwsContexttoOriginal);
 av_frame_free(&RGBFrame);
 //av_free(rgb_buffer);

 }

 /* Flushing Encoder */
 encode(ENCodecContext, NULL, EncodedPacket, Output_Format_Context);

 //avcodec_flush_buffers(DECodecContext);
 //avcodec_flush_buffers(ENCodecContext);

 av_packet_free(&EncodedPacket);

 }else{

 av_interleaved_write_frame(Output_Format_Context, Packet);

 }

 }

 av_write_trailer(Output_Format_Context); 

 /* Memory Free */
 avcodec_free_context(&DECodecContext);
 avcodec_free_context(&ENCodecContext);
 avcodec_parameters_free(&CodecParameters);
 av_frame_free(&Frame);
 av_packet_free(&Packet);

 return 0;

}




The function encode looks as follows :


static void encode(AVCodecContext *ENCodecContext, AVFrame *Frame, AVPacket *EncodedPacket, AVFormatContext *Output_Format_Context){

 int check;



 check = avcodec_send_frame(ENCodecContext, Frame);
 if(check == AVERROR(EAGAIN)){
 printf("\nEAGAIN");
 } 
 if(check == AVERROR_EOF){
 printf("\nEOF");
 }
 if(check == AVERROR(EINVAL)){
 printf("\nEINVAL");
 }
 if(check == AVERROR(ENOMEM)){
 printf("\nENOMEM");
 }
 if(check < 0){

 printf("\nFehler bei Encoding Send Frame. Check = %d", check);

 return;

 }

 while(check >= 0){

 check = avcodec_receive_packet(ENCodecContext, EncodedPacket);
 if(check == AVERROR(EAGAIN) || check == AVERROR_EOF){

 return;

 }else if(check < 0){

 printf("\nFehler bei Encoding");

 return;

 }

 if (av_interleaved_write_frame(Output_Format_Context, EncodedPacket) < 0) {

 printf("\nFehler beim Muxen des Paketes.");
 break;

 }

 av_packet_unref(EncodedPacket);

 }

 return;

}



The program should decode a video into the individual frames convert them to RGB24, so I can work with the raw data of the frame, then convert it back to the original format and encode the frames.


The encoder doesn't play nice, as I get an EOF error at avcodec_send_frame().
But I couldn't figure it out why the encoder behaves like this.
And yes I have read the docs and example files, but either I'm massivly missing a crucial detail or I'm just ****.


Any and all help will be and is massivly appreciated.


PS. : The used libraries are libavutil, libavformat, libavcodec, libswscale. All installed with the "-dev" suffix through linux commandline. Should all be the version 7.0 libraries.


Thanks in advance.
With best regards.


- 

- Read the docs
- Shifting the encoding step out of the decoding while loop






-
Stream sent via FFMPEG (NodeJS) to RTMP (YouTube) not being received
10 décembre 2024, par QumberI am writing a very basic chrome extension that captures and sends video stream to a nodeJS server, which in turns sends it to Youtube live server.


Here is my implementation of the backend which receives data via WebRTC and send to YT using FFMPEG :


const express = require('express');
const cors = require('cors');
const { RTCPeerConnection, RTCSessionDescription } = require('@roamhq/wrtc');
const { spawn } = require('child_process');

const app = express();
app.use(express.json());
app.use(cors());

app.post('/webrtc', async (req, res) => {
 const peerConnection = new RTCPeerConnection();

 // Start ffmpeg process for streaming
 const ffmpeg = spawn('ffmpeg', [
 '-f', 'flv',
 '-i', 'pipe:0',
 '-c:v', 'libx264',
 '-preset', 'veryfast',
 '-maxrate', '3000k',
 '-bufsize', '6000k',
 '-pix_fmt', 'yuv420p',
 '-g', '50',
 '-f', 'flv',
 'rtmp://a.rtmp.youtube.com/live2/MY_KEY'
 ]);

 ffmpeg.on('error', (err) => {
 console.error('FFmpeg error:', err);
 });

 ffmpeg.stderr.on('data', (data) => {
 console.error('FFmpeg stderr:', data.toString());
 });

 ffmpeg.stdout.on('data', (data) => {
 console.log('FFmpeg stdout:', data.toString());
 });

 // Handle incoming tracks
 peerConnection.ontrack = (event) => {
 console.log('Track received:', event.track.kind);
 const track = event.track;

 // Stream the incoming track to FFmpeg
 track.onunmute = () => {
 console.log('Track unmuted:', track.kind);
 const reader = track.createReadStream();
 reader.on('data', (chunk) => {
 console.log('Forwarding chunk to FFmpeg:', chunk.length);
 ffmpeg.stdin.write(chunk);
 });
 reader.on('end', () => {
 console.log('Stream ended');
 ffmpeg.stdin.end();
 });
 };

 track.onmute = () => {
 console.log('Track muted:', track.kind);
 };
 };

 // Set the remote description (offer) received from the client
 await peerConnection.setRemoteDescription(new RTCSessionDescription(req.body.sdp));

 // Create an answer and send it back to the client
 const answer = await peerConnection.createAnswer();
 await peerConnection.setLocalDescription(answer);

 res.json({ sdp: peerConnection.localDescription });
});

app.listen(3000, () => {
 console.log('WebRTC to RTMP server running on port 3000');
});




This is the output I get, but nothing gets sent to YouTube :




FFmpeg stderr: ffmpeg version 7.0.2 Copyright (c) 2000-2024 the FFmpeg developers
 built with Apple clang version 15.0.0 (clang-1500.3.9.4)

FFmpeg stderr: configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/7.0.2_1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh --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

FFmpeg stderr: libavutil 59. 8.100 / 59. 8.100
 libavcodec 61. 3.100 / 61. 3.100
 libavformat 61. 1.100 / 61. 1.100
 libavdevice 61. 1.100 / 61. 1.100

FFmpeg stderr: libavfilter 10. 1.100 / 10. 1.100
 libswscale 8. 1.100 / 8. 1.100
 libswresample 5. 1.100 / 5. 1.100
 libpostproc 58. 1.100 / 58. 1.100





I do not understand what I am doing wrong. Any help would be appreciated.



Optionally Here's the frontend code from the extension, which (to me) appears to be recording and sending the capture :


popup.js & popup.html




document.addEventListener('DOMContentLoaded', () => {
 document.getElementById('openCapturePage').addEventListener('click', () => {
 chrome.tabs.create({
 url: chrome.runtime.getURL('capture.html')
 });
 });
});






 
 <code class="echappe-js"><script src='http://stackoverflow.com/feeds/tag/popup.js'></script>




StreamSavvy













capture.js & capture.html




let peerConnection;

async function startStreaming() {
 try {
 const stream = await navigator.mediaDevices.getDisplayMedia({
 video: {
 cursor: "always"
 },
 audio: false
 });

 peerConnection = new RTCPeerConnection({
 iceServers: [{
 urls: 'stun:stun.l.google.com:19302'
 }]
 });

 stream.getTracks().forEach(track => peerConnection.addTrack(track, stream));

 const offer = await peerConnection.createOffer();
 await peerConnection.setLocalDescription(offer);

 const response = await fetch('http://localhost:3000/webrtc', {
 method: 'POST',
 headers: {
 'Content-Type': 'application/json'
 },
 body: JSON.stringify({
 sdp: peerConnection.localDescription
 })
 });

 const {
 sdp
 } = await response.json();
 await peerConnection.setRemoteDescription(new RTCSessionDescription(sdp));

 console.log("Streaming to server via WebRTC...");
 } catch (error) {
 console.error("Error starting streaming:", error.name, error.message);
 }
}

async function stopStreaming() {
 if (peerConnection) {
 // Stop all media tracks
 peerConnection.getSenders().forEach(sender => {
 if (sender.track) {
 sender.track.stop();
 }
 });

 // Close the peer connection
 peerConnection.close();
 peerConnection = null;
 console.log("Streaming stopped");
 }
}

document.addEventListener('DOMContentLoaded', () => {
 document.getElementById('startCapture').addEventListener('click', startStreaming);
 document.getElementById('stopCapture').addEventListener('click', stopStreaming);
});






 
 <code class="echappe-js"><script src='http://stackoverflow.com/feeds/tag/capture.js'></script>




StreamSavvy Capture















background.js (service worker)




chrome.runtime.onInstalled.addListener(() => {
 console.log("StreamSavvy Extension Installed");
});

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
 if (message.type === 'startStreaming') {
 chrome.tabs.create({
 url: chrome.runtime.getURL('capture.html')
 });
 sendResponse({
 status: 'streaming'
 });
 } else if (message.type === 'stopStreaming') {
 chrome.tabs.query({
 url: chrome.runtime.getURL('capture.html')
 }, (tabs) => {
 if (tabs.length > 0) {
 chrome.tabs.sendMessage(tabs[0].id, {
 type: 'stopStreaming'
 });
 sendResponse({
 status: 'stopped'
 });
 }
 });
 }
 return true; // Keep the message channel open for sendResponse
});