
Recherche avancée
Médias (1)
-
La conservation du net art au musée. Les stratégies à l’œuvre
26 mai 2011
Mis à jour : Juillet 2013
Langue : français
Type : Texte
Autres articles (44)
-
Gestion générale des documents
13 mai 2011, parMédiaSPIP ne modifie jamais le document original mis en ligne.
Pour chaque document mis en ligne il effectue deux opérations successives : la création d’une version supplémentaire qui peut être facilement consultée en ligne tout en laissant l’original téléchargeable dans le cas où le document original ne peut être lu dans un navigateur Internet ; la récupération des métadonnées du document original pour illustrer textuellement le fichier ;
Les tableaux ci-dessous expliquent ce que peut faire MédiaSPIP (...) -
Contribute to translation
13 avril 2011You can help us to improve the language used in the software interface to make MediaSPIP more accessible and user-friendly. You can also translate the interface into any language that allows it to spread to new linguistic communities.
To do this, we use the translation interface of SPIP where the all the language modules of MediaSPIP are available. Just subscribe to the mailing list and request further informantion on translation.
MediaSPIP is currently available in French and English (...) -
Des sites réalisés avec MediaSPIP
2 mai 2011, parCette page présente quelques-uns des sites fonctionnant sous MediaSPIP.
Vous pouvez bien entendu ajouter le votre grâce au formulaire en bas de page.
Sur d’autres sites (3686)
-
How to modify the bit_rate of AVFormatContext ?
27 mars 2023, par Zion LiuHello,I would like to know how to modify the bit_rate of AVFormatContext.


Here is the minimal reproducible example.This is a simple process for pushing rtmp video streams.Now I want to control the bitrate of the video it pushes.


I tried modifying the bitrate like this, but it didn't work.


AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
int64_t bit_rate = 400*1000;
....
ofmt_ctx->bit_rate = bit_rate;



Can be compiled by
g++ -Wall -o -g -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/local/include -L/usr/local/lib simplt_push_streaming.cpp -o test.out -lavformat -lavcodec -lavutil -lgobject-2.0 -lglib-2.0 -lpthread


And my ffmpeg version :
ffmpeg version 4.4.2-0ubuntu0.22.04.1


#include 
extern "C"
{
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>mathematics.h>
#include <libavutil></libavutil>time.h>
};

int main(int argc, char* argv[])
{
 AVOutputFormat *ofmt = NULL;
 //Input AVFormatContext and Output AVFormatContext
 AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
 AVPacket pkt;
 const char *in_filename, *out_filename;
 int ret, i;
 int videoindex=-1;
 int frame_index=0;
 int64_t start_time=0;
 int64_t bit_rate = 400*1000;
 in_filename = "/home/zion/video/mecha.flv";// Input file URL
 out_filename = "rtmp://localhost:1935/live/test";//Output URL [RTMP]
 av_register_all();
 avformat_network_init();
 avformat_open_input(&ifmt_ctx, in_filename, 0, 0);
 avformat_find_stream_info(ifmt_ctx, 0);
 for(i=0; inb_streams; i++) 
 if(ifmt_ctx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
 videoindex=i;
 break;
 }
 //Output
 avformat_alloc_output_context2(&ofmt_ctx, NULL, "flv", out_filename); //RTMP
 ofmt = ofmt_ctx->oformat;
 for (i = 0; i < ifmt_ctx->nb_streams; i++) {
 //Create output AVStream according to input AVStream
 AVStream *in_stream = ifmt_ctx->streams[i];
 AVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec);
 //Copy the settings of AVCodecContext
 ret = avcodec_copy_context(out_stream->codec, in_stream->codec);
 out_stream->codec->codec_tag = 0;
 if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
 out_stream->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
 }
 //Open output URL
 if (!(ofmt->flags & AVFMT_NOFILE)) {
 ret = avio_open(&ofmt_ctx->pb, out_filename, AVIO_FLAG_WRITE);
 }
 //Write file header
 avformat_write_header(ofmt_ctx, NULL);
 start_time=av_gettime();
 while (1) {
 AVStream *in_stream, *out_stream;
 //Get an AVPacket
 ret = av_read_frame(ifmt_ctx, &pkt);
 if (ret < 0)
 break;
 //Important:Delay
 if(pkt.stream_index==videoindex){
 AVRational time_base=ifmt_ctx->streams[videoindex]->time_base;
 AVRational time_base_q={1,AV_TIME_BASE};
 int64_t pts_time = av_rescale_q(pkt.dts, time_base, time_base_q);
 int64_t now_time = av_gettime() - start_time;
 if (pts_time > now_time)
 av_usleep(pts_time - now_time);
 }
 in_stream = ifmt_ctx->streams[pkt.stream_index];
 out_stream = ofmt_ctx->streams[pkt.stream_index];
 if(pkt.stream_index==videoindex){
 printf("Send %8d video frames to output URL\n",frame_index);
 frame_index++;
 }
/*I tried modifying the bitrate here and I'm not sure if this is the correct usage.*/
 ofmt_ctx->bit_rate = bit_rate;
 av_interleaved_write_frame(ofmt_ctx, &pkt);
 av_free_packet(&pkt);
 }
 //Write file trailer
 av_write_trailer(ofmt_ctx);
end:
 avformat_close_input(&ifmt_ctx);
 /* close output */
 if (ofmt_ctx && !(ofmt->flags & AVFMT_NOFILE))
 avio_close(ofmt_ctx->pb);
 avformat_free_context(ofmt_ctx);
 return 0;
}



-
Can't write packet with unknown timestamp av_interleaved_write_frame() : Invalid argument
28 mai 2024, par jagvetinteI'm trying to convert a .ts file with this output to mkv :


ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
 built with Apple clang version 12.0.0 (clang-1200.0.32.27)
 configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_4 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --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-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
 libavutil 56. 51.100 / 56. 51.100
 libavcodec 58. 91.100 / 58. 91.100
 libavformat 58. 45.100 / 58. 45.100
 libavdevice 58. 10.100 / 58. 10.100
 libavfilter 7. 85.100 / 7. 85.100
 libavresample 4. 0. 0 / 4. 0. 0
 libswscale 5. 7.100 / 5. 7.100
 libswresample 3. 7.100 / 3. 7.100
 libpostproc 55. 7.100 / 55. 7.100
[mp3float @ 0x7fbd6282b200] Header missing
[mpegts @ 0x7fbd62809000] PES packet size mismatch
[mpegts @ 0x7fbd62809000] Packet corrupt (stream = 2, dts = 7125804577).
[mpegts @ 0x7fbd62809000] PES packet size mismatch
[mpegts @ 0x7fbd62809000] Packet corrupt (stream = 2, dts = 7125804577).
[mpegts @ 0x7fbd62809000] PES packet size mismatch
[mpegts @ 0x7fbd62809000] Packet corrupt (stream = 1, dts = 7125790091).
Input #0, mpegts, from '/Users/"User"/Downloads/input.ts':
 Duration: 02:11:32.82, start: 71283.837456, bitrate: 17149 kb/s
 Program 1 
 Stream #0:0[0x1004]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuvj420p(pc, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 2.08 tbr, 90k tbn, 100 tbc
 Stream #0:1[0x1104](swe): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 256 kb/s
 Stream #0:2[0x704](swe): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 640 kb/s



To do that I'm using this command :


ffmpeg -i input.ts -c copy output.mkv



But the conversion fails with this error :


Stream mapping:
 Stream #0:0 -> #0:0 (copy)
 Stream #0:2 -> #0:1 (copy)
Press [q] to stop, [?] for help
[matroska @ 0x7fb8c1808200] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[matroska @ 0x7fb8c1808200] Can't write packet with unknown timestamp
av_interleaved_write_frame(): Invalid argument
[matroska @ 0x7fb8c1808200] Can't write packet with unknown timestamp
Error writing trailer of output.mkv: Invalid argument
frame= 27 fps=0.0 q=-1.0 Lsize= 74kB time=00:00:00.85 bitrate= 705.5kbits/s speed= 99x 
video:1092kB audio:35kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!



What should I do in order to fix this ? I've already tried to add
-fflags +genpts
in the beginning but it fails anyway.

EDIT : I did solve it by using MKVToolNix instead.


-
FFMPEG keeping quality when reducing FPS and streaming over RTSP with rtsp-simple-server
25 janvier 2021, par Jens SchneiderI'm using the rtsp-simple-server (https://github.com/aler9/rtsp-simple-server) and feed the RTSP Server with a FFMPEG stream.


I use a docker compose file to start the stream :


version: "3.8"

services:

 ffmpeg:
 container_name: ffmpeg-base
 restart: always
 image: "jenssgb/rtspffmpeg:base"
 depends_on:
 - rtsp-server
 volumes:
 - $PWD/:/video
 network_mode: "host"
 command: "ffmpeg -re -stream_loop -1 -i /video/footage-1-b.mp4 -c copy -f rtsp rtsp://localhost:8554/compose-rtsp"
 
 rtsp-server:
 container_name: rtsp-server-base
 restart: always
 image: "aler9/rtsp-simple-server"
 network_mode: "host"



Now I'm trying to reduce the FPS of my video with transcoding it :


command: -re -stream_loop -1 -i ${VIDEO_FILE} -vf "fps=${FPS_COMPOSE}" -f rtsp rtsp://localhost:8554/compose-rtsp



This is basically working, but the quality of the output video becomes pretty bad. I tried a lot of things like
-c:v libx264
which did help for a minute but let ffmpeg crash then.

av_interleaved_write_frame(): Broken pipe0:00:09.99 bitrate=N/A speed=0.985x 
[rtsp @ 0x5563b1755640] Packets poorly interleaved, failed to avoid negative timestamp -33660 in stream 0.
Try -max_interleave_delta 0 as a possible workaround.
av_interleaved_write_frame(): Broken pipe
Error writing trailer of rtsp://localhost:8554/compose-rtsp: Broken pipe



Any idea how I can reduce the FPS send the stream to the server but keep the video quality ? Later I'm going to reduce the resolution as well - but for now I want to keep resolution and quality but only reduce the FPS.


Full logs from my test with
-c:v libx264
:

ffmpeg -re -stream_loop -1 -i footage-1-b.mp4 -vf "fps=5" -c:v libx264 -f rtsp rtsp://localhost:8554/compose-rtsp
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
 built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
 configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
 libavutil 56. 31.100 / 56. 31.100
 libavcodec 58. 54.100 / 58. 54.100
 libavformat 58. 29.100 / 58. 29.100
 libavdevice 58. 8.100 / 58. 8.100
 libavfilter 7. 57.100 / 7. 57.100
 libavresample 4. 0. 0 / 4. 0. 0
 libswscale 5. 5.100 / 5. 5.100
 libswresample 3. 5.100 / 3. 5.100
 libpostproc 55. 5.100 / 55. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'footage-1-b.mp4':
 Metadata:
 major_brand : isom
 minor_version : 512
 compatible_brands: isomiso2avc1mp41
 title : Session streamed by "nessyMediaServer"
 encoder : Lavf58.29.100
 comment : h264_3
 Duration: 00:59:59.63, start: 0.000000, bitrate: 2099 kb/s
 Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc), 1280x720 [SAR 1:1 DAR 16:9], 2061 kb/s, 24.96 fps, 25 tbr, 12800 tbn, 25 tbc (default)
 Metadata:
 handler_name : VideoHandler
 Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 8000 Hz, mono, fltp, 35 kb/s (default)
 Metadata:
 handler_name : SoundHandler
Stream mapping:
 Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
 Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[aac @ 0x56277bc7f840] Too many bits 8832.000000 > 6144 per frame requested, clamping to max
[libx264 @ 0x56277bbc33c0] using SAR=1/1
[libx264 @ 0x56277bbc33c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x56277bbc33c0] profile High, level 3.1
[libx264 @ 0x56277bbc33c0] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 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=2 keyint=250 keyint_min=5 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, rtsp, to 'rtsp://localhost:8554/compose-rtsp':
 Metadata:
 major_brand : isom
 minor_version : 512
 compatible_brands: isomiso2avc1mp41
 title : Session streamed by "nessyMediaServer"
 comment : h264_3
 encoder : Lavf58.29.100
 Stream #0:0(und): Video: h264 (libx264), yuvj420p(pc), 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 5 fps, 90k tbn, 5 tbc (default)
 Metadata:
 handler_name : VideoHandler
 encoder : Lavc58.54.100 libx264
 Side data:
 cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
 Stream #0:1(und): Audio: aac (LC), 8000 Hz, mono, fltp, 48 kb/s (default)
 Metadata:
 handler_name : SoundHandler
 encoder : Lavc58.54.100 aac
av_interleaved_write_frame(): Broken pipe0:00:09.87 bitrate=N/A speed=0.978x 
[rtsp @ 0x56277bba0640] Packets poorly interleaved, failed to avoid negative timestamp -33660 in stream 0.
Try -max_interleave_delta 0 as a possible workaround.
av_interleaved_write_frame(): Broken pipe
Error writing trailer of rtsp://localhost:8554/compose-rtsp: Broken pipe
frame= 50 fps=4.6 q=23.0 Lsize=N/A time=00:00:10.21 bitrate=N/A speed=0.947x 
video:162kB audio:8kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0x56277bbc33c0] frame I:1 Avg QP:19.85 size:165667
[libx264 @ 0x56277bbc33c0] frame P:13 Avg QP:20.88 size:140481
[libx264 @ 0x56277bbc33c0] frame B:36 Avg QP:24.58 size: 55445
[libx264 @ 0x56277bbc33c0] consecutive B-frames: 4.0% 0.0% 0.0% 96.0%
[libx264 @ 0x56277bbc33c0] mb I I16..4: 4.4% 30.8% 64.8%
[libx264 @ 0x56277bbc33c0] mb P I16..4: 4.1% 10.6% 20.0% P16..4: 24.4% 24.8% 13.3% 0.0% 0.0% skip: 2.6%
[libx264 @ 0x56277bbc33c0] mb B I16..4: 0.8% 2.0% 4.0% B16..8: 40.3% 14.5% 5.2% direct:11.8% skip:21.4% L0:77.1% L1: 7.9% BI:14.9%
[libx264 @ 0x56277bbc33c0] 8x8 transform intra:30.1% inter:11.9%
[libx264 @ 0x56277bbc33c0] coded y,uvDC,uvAC intra: 82.5% 60.9% 26.6% inter: 55.0% 42.4% 2.7%
[libx264 @ 0x56277bbc33c0] i16 v,h,dc,p: 17% 26% 34% 23%
[libx264 @ 0x56277bbc33c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 33% 15% 3% 4% 5% 4% 3% 9%
[libx264 @ 0x56277bbc33c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 22% 13% 3% 17% 11% 5% 3% 6%
[libx264 @ 0x56277bbc33c0] i8c dc,h,v,p: 54% 25% 16% 5%
[libx264 @ 0x56277bbc33c0] Weighted P-Frames: Y:7.7% UV:7.7%
[libx264 @ 0x56277bbc33c0] ref P L0: 33.2% 11.6% 29.0% 23.9% 2.4%
[libx264 @ 0x56277bbc33c0] ref B L0: 79.6% 11.9% 8.5%
[libx264 @ 0x56277bbc33c0] ref B L1: 95.9% 4.1%
[libx264 @ 0x56277bbc33c0] kb/s:3190.34
[aac @ 0x56277bc7f840] Qavg: 65536.000
Conversion failed!



Thank you,
J