Recherche avancée

Médias (91)

Autres articles (27)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-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

  • Selection of projects using MediaSPIP

    2 mai 2011, par

    The examples below are representative elements of MediaSPIP specific uses for specific projects.
    MediaSPIP farm @ Infini
    The non profit organizationInfini develops hospitality activities, internet access point, training, realizing innovative projects in the field of information and communication technologies and Communication, and hosting of websites. It plays a unique and prominent role in the Brest (France) area, at the national level, among the half-dozen such association. Its members (...)

  • Menus personnalisés

    14 novembre 2010, par

    MediaSPIP utilise le plugin Menus pour gérer plusieurs menus configurables pour la navigation.
    Cela permet de laisser aux administrateurs de canaux la possibilité de configurer finement ces menus.
    Menus créés à l’initialisation du site
    Par défaut trois menus sont créés automatiquement à l’initialisation du site : Le menu principal ; Identifiant : barrenav ; Ce menu s’insère en général en haut de la page après le bloc d’entête, son identifiant le rend compatible avec les squelettes basés sur Zpip ; (...)

Sur d’autres sites (5682)

  • FFMPEG - adding a nullsrc causes my script to report "1000 duplicate frames"

    14 juin 2020, par rossmcm

    I'm trying to add coloured rectangle highlights to a video, appearing at different locations and times. The highlights are on a 6x6 grid of 320x180 rectangles.

    



    Originally I didn't have the nullsrc=size=1920x1080 thinking that it would start with an empty image, but it seems that that causes it to make assumptions about where the input is coming from. So I added the nullsrc=size=1920x1080 to start with a transparent 1920x1080 image but this command returns a warning that 1000 duplicate frames have been produced and it keeps going past the end of the input video with no signs of stopping.

    



    ffmpeg -y \       
  -i "Input.mp4" \           
  -filter_complex \ 
 "nullsrc=size=1920x1080, drawbox=x=(3-1)*320:y=(3-1)*180:w=320:h=180:t=7:c=cyan,   fade=in:st=10:d=1:alpha=1, fade=out:st=40:d=1:alpha=1[tmp1]; \
  nullsrc=size=1920x1080, drawbox=x=(4-1)*320:y=(4-1)*180:w=320:h=180:t=7:c=blue,   fade=in:st=20:d=1:alpha=1, fade=out:st=50:d=1:alpha=1[tmp2]; \
  nullsrc=size=1920x1080, drawbox=x=(5-1)*320:y=(5-1)*180:w=320:h=180:t=7:c=green,  fade=in:st=30:d=1:alpha=1, fade=out:st=60:d=1:alpha=1[tmp3]; \
  nullsrc=size=1920x1080, drawbox=x=(6-1)*320:y=(6-1)*180:w=320:h=180:t=7:c=yellow, fade=in:st=40:d=1:alpha=1, fade=out:st=70:d=1:alpha=1[tmp4]; \
  [tmp1][tmp2] overlay=0:0[ovr1]; \ 
  [tmp3][tmp4] overlay=0:0[ovr2]; \ 
  [ovr1][ovr2] overlay=0:0[boxes]; \ 
  [0:v][boxes] overlay=0:0" \        
  "Output.mp4"


    



    The input video is around 01:45 long. Log of run :

    



    ffmpeg -y        -loglevel verbose       -i "Input.mp4"          -filter_complex " nullsrc=size=1920x1080, drawbox=x=(3-1)*320:y=(3-1)*180:w=320:h=180:t=7:c=cyan,   fade=in:st=10:d=1:alpha=1, fade=out:st=40:d=1:alpha=1[tmp1]; nullsrc=size=1920x1080, drawbox=x  =(4-1)*320:y=(4-1)*180:w=320:h=180:t=7:c=blue,   fade=in:st=20:d=1:alpha=1, fade=out:st=50:d=1:alpha=1[tmp2]; nullsrc=size=1920x1080, drawbox=x=(5-1)*320:y=(5-1)*180:w=320:h=180:t=7:c=green,  fa
de=in:st=30:d=1:alpha=1, fade=out:st=60:d=1:alpha=1[tmp3]; nullsrc=size=1920x1080, drawbox=x=(6-1)*320:y=(6-1)*180:w=320:h=180:t=7:c=yellow, fade=in:st=40:d=1:alpha=1, fade=out:st=70:d=1:alpha=1[tmp4]; [tmp1][tmp2] overlay=0:0[ovr1]; [tmp3][tmp4] overlay=0:0[ovr2]; [ovr1][ovr2] overlay=0:0[boxes]; [0:v][boxes] overlay=0:0"      "Output.mp4"
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 7.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvid
stab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
[h264 @ 000001df2b623ea0] Reinit context to 1920x1088, pix_fmt: yuv420p
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:01:48.67, start: 0.000000, bitrate: 1825 kb/s
    Stream #0:0(und): Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuv420p(left), 1920x1080 (1920x1088) [SAR 1:1 DAR 16:9], 1693 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, s16p, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[Parsed_nullsrc_0 @ 000001df2b61af00] size:1920x1080 rate:25/1 duration:-1.000000 sar:1/1
[Parsed_fade_2 @ 000001df2b6a6860] type:in start_time:10.000000 duration:1.000000 alpha:1
[Parsed_fade_3 @ 000001df2b9ddec0] type:out start_time:40.000000 duration:1.000000 alpha:1
[Parsed_nullsrc_4 @ 000001df2bc00560] size:1920x1080 rate:25/1 duration:-1.000000 sar:1/1
[Parsed_fade_6 @ 000001df29fe6780] type:in start_time:20.000000 duration:1.000000 alpha:1
[Parsed_fade_7 @ 000001df29fe6840] type:out start_time:50.000000 duration:1.000000 alpha:1
[Parsed_nullsrc_8 @ 000001df2b642dc0] size:1920x1080 rate:25/1 duration:-1.000000 sar:1/1
[Parsed_fade_10 @ 000001df2b6442a0] type:in start_time:30.000000 duration:1.000000 alpha:1
[Parsed_fade_11 @ 000001df2b6444e0] type:out start_time:60.000000 duration:1.000000 alpha:1
[Parsed_nullsrc_12 @ 000001df2b62d000] size:1920x1080 rate:25/1 duration:-1.000000 sar:1/1
[Parsed_fade_14 @ 000001df2b62d580] type:in start_time:40.000000 duration:1.000000 alpha:1
[Parsed_fade_15 @ 000001df2b62ddc0] type:out start_time:70.000000 duration:1.000000 alpha:1
Stream mapping:
  Stream #0:0 (h264) -> overlay:main (graph 0)
  overlay (graph 0) -> Stream #0:0 (libx264)
  Stream #0:1 -> #0:1 (mp3 (native) -> aac (native))
Press [q] to stop, [?] for help
[h264 @ 000001df2b8e5040] Reinit context to 1920x1088, pix_fmt: yuv420p
[graph_1_in_0_1 @ 000001df2b62e100] tb:1/44100 samplefmt:s16p samplerate:44100 chlayout:0x3
[format_out_0_1 @ 000001df2b62e5e0] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_1'
[auto_resampler_0 @ 000001df2b62dd00] ch:2 chl:stereo fmt:s16p r:44100Hz -> ch:2 chl:stereo fmt:fltp r:44100Hz
[Parsed_nullsrc_0 @ 000001df2b62e440] size:1920x1080 rate:25/1 duration:-1.000000 sar:1/1
[Parsed_fade_2 @ 000001df2b62df60] type:in start_time:10.000000 duration:1.000000 alpha:1
[Parsed_fade_3 @ 000001df2b62e6c0] type:out start_time:40.000000 duration:1.000000 alpha:1
[Parsed_nullsrc_4 @ 000001df2b62d9c0] size:1920x1080 rate:25/1 duration:-1.000000 sar:1/1
[Parsed_fade_6 @ 000001df2b62e520] type:in start_time:20.000000 duration:1.000000 alpha:1
[Parsed_fade_7 @ 000001df2b62d8e0] type:out start_time:50.000000 duration:1.000000 alpha:1
[Parsed_nullsrc_8 @ 000001df2b62e1e0] size:1920x1080 rate:25/1 duration:-1.000000 sar:1/1
[Parsed_fade_10 @ 000001df2b62e2a0] type:in start_time:30.000000 duration:1.000000 alpha:1
[Parsed_fade_11 @ 000001df2b62e380] type:out start_time:60.000000 duration:1.000000 alpha:1
[Parsed_nullsrc_12 @ 000001df2b62dc20] size:1920x1080 rate:25/1 duration:-1.000000 sar:1/1
[Parsed_fade_14 @ 000001df2b816f60] type:in start_time:40.000000 duration:1.000000 alpha:1
[Parsed_fade_15 @ 000001df2b817ac0] type:out start_time:70.000000 duration:1.000000 alpha:1
[graph 0 input from stream 0:0 @ 000001df2b817ba0] w:1920 h:1080 pixfmt:yuv420p tb:1/15360 fr:30/1 sar:1/1 sws_param:flags=2
[Parsed_drawbox_1 @ 000001df2b62da80] x:640 y:360 w:320 h:180 color:0xA9A610FF
[Parsed_drawbox_5 @ 000001df2b62e780] x:960 y:540 w:320 h:180 color:0x29F06EFF
[Parsed_overlay_16 @ 000001df2b817860] main w:1920 h:1080 fmt:yuva420p overlay w:1920 h:1080 fmt:yuva420p
[Parsed_overlay_16 @ 000001df2b817860] [framesync @ 000001df2b815348] Selected 1/25 time base
[Parsed_overlay_16 @ 000001df2b817860] [framesync @ 000001df2b815348] Sync level 2
[Parsed_drawbox_9 @ 000001df2b62db60] x:1280 y:720 w:320 h:180 color:0x515B51FF
[Parsed_drawbox_13 @ 000001df2b818be0] x:1600 y:900 w:320 h:180 color:0xD21092FF
[Parsed_overlay_17 @ 000001df2b816d00] main w:1920 h:1080 fmt:yuva420p overlay w:1920 h:1080 fmt:yuva420p
[Parsed_overlay_17 @ 000001df2b816d00] [framesync @ 000001df2b815e48] Selected 1/25 time base
[Parsed_overlay_17 @ 000001df2b816d00] [framesync @ 000001df2b815e48] Sync level 2
[Parsed_overlay_18 @ 000001df2b8183c0] main w:1920 h:1080 fmt:yuva420p overlay w:1920 h:1080 fmt:yuva420p
[Parsed_overlay_18 @ 000001df2b8183c0] [framesync @ 000001df2b815668] Selected 1/25 time base
[Parsed_overlay_18 @ 000001df2b8183c0] [framesync @ 000001df2b815668] Sync level 2
[Parsed_overlay_19 @ 000001df2b817d40] main w:1920 h:1080 fmt:yuv420p overlay w:1920 h:1080 fmt:yuva420p
[Parsed_overlay_19 @ 000001df2b817d40] [framesync @ 000001df2b816488] Selected 1/76800 time base
[Parsed_overlay_19 @ 000001df2b817d40] [framesync @ 000001df2b816488] Sync level 2
[libx264 @ 000001df2b62cd40] using SAR=1/1
[libx264 @ 000001df2b62cd40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000001df2b62cd40] profile High, level 4.0
[libx264 @ 000001df2b62cd40] 264 - core 152 r2851 ba24899 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - 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 weigh
tb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 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, mp4, to 'Output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.83.100
    Stream #0:0: Video: h264 (libx264), 1 reference frame (avc1 / 0x31637661), yuv420p(left), 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
    Metadata:
      encoder         : Lavc57.107.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) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, delay 1024, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc57.107.100 aac
[Parsed_overlay_19 @ 000001df2b817d40] [framesync @ 000001df2b816488] Sync level 1speed=0.78x
Past duration 0.800774 too large
*** 1 dup!5 fps= 24 q=29.0 size=   21760kB time=00:01:46.86 bitrate=1668.0kbits/s speed=0.78x
    Last message repeated 1 times
*** 1 dup!8 fps= 24 q=29.0 size=   21760kB time=00:01:47.30 bitrate=1661.3kbits/s dup=2 drop=0 speed=0.78x
    Last message repeated 2 times
*** 1 dup!3 fps= 24 q=29.0 size=   21760kB time=00:01:47.80 bitrate=1653.6kbits/s dup=5 drop=0 speed=0.781x
    Last message repeated 1 times

...

    Last message repeated 2 times
*** 1 dup!3 fps= 25 q=29.0 size=   27392kB time=00:05:05.80 bitrate= 733.8kbits/s dup=995 drop=0 speed=0.832x
    Last message repeated 1 times
*** 1 dup!6 fps= 25 q=29.0 size=   27392kB time=00:05:06.23 bitrate= 732.8kbits/s dup=997 drop=0 speed=0.832x
    Last message repeated 1 times
*** 1 dup!0 fps= 25 q=29.0 size=   27392kB time=00:05:06.70 bitrate= 731.6kbits/s dup=999 drop=0 speed=0.832x
    Last message repeated 1 times
More than 1000 frames duplicated
*** 1 dup!3 fps= 25 q=29.0 size=   27392kB time=00:05:07.13 bitrate= 730.6kbits/s dup=1001 drop=0 speed=0.832x
    Last message repeated 2 times
*** 1 dup!8 fps= 25 q=29.0 size=   27392kB time=00:05:07.63 bitrate= 729.4kbits/s dup=1004 drop=0 speed=0.832x
    Last message repeated 1 times
... 
*** 1 dup!9 fps= 25 q=29.0 size=   27904kB time=00:05:18.66 bitrate= 717.3kbits/s dup=1059 drop=0 speed=0.834x
    Last message repeated 1 times
*** 1 dup!3 fps= 25 q=29.0 size=   27904kB time=00:05:19.13 bitrate= 716.3kbits/s dup=1061 drop=0 speed=0.834x
frame= 9635 fps= 25 q=-1.0 Lsize=   28364kB time=00:05:21.06 bitrate= 723.7kbits/s dup=1062 drop=0 speed=0.837x
video:26539kB audio:1637kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.669889%
Input file #0 (Input.mp4):
  Input stream #0:0 (video): 3260 packets read (23006797 bytes); 3260 frames decoded;
  Input stream #0:1 (audio): 4025 packets read (1682285 bytes); 4025 frames decoded (4636800 samples);
  Total: 7285 packets (24689082 bytes) demuxed
Output file #0 (Output.mp4):
  Output stream #0:0 (video): 9635 frames encoded; 9635 packets muxed (27175566 bytes);
  Output stream #0:1 (audio): 4529 frames encoded (4636800 samples); 4530 packets muxed (1676214 bytes);
  Total: 14165 packets (28851780 bytes) muxed
[libx264 @ 000001df2b62cd40] frame I:39    Avg QP:16.49  size:213954
[libx264 @ 000001df2b62cd40] frame P:2446  Avg QP:17.77  size:  6277
[libx264 @ 000001df2b62cd40] frame B:7150  Avg QP:30.38  size:   486
[libx264 @ 000001df2b62cd40] consecutive B-frames:  0.8%  0.8%  0.1% 98.3%
[libx264 @ 000001df2b62cd40] mb I  I16..4: 13.2% 43.0% 43.8%
[libx264 @ 000001df2b62cd40] mb P  I16..4:  0.2%  0.2%  0.1%  P16..4:  7.1%  3.3%  1.7%  0.0%  0.0%    skip:87.5%
[libx264 @ 000001df2b62cd40] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  4.3%  0.1%  0.0%  direct: 0.0%  skip:95.5%  L0:41.9% L1:56.1% BI: 2.0%
[libx264 @ 000001df2b62cd40] 8x8 transform intra:44.1% inter:65.8%
[libx264 @ 000001df2b62cd40] coded y,uvDC,uvAC intra: 71.3% 83.5% 52.5% inter: 1.1% 1.5% 0.0%
[libx264 @ 000001df2b62cd40] i16 v,h,dc,p: 31% 28%  4% 38%
[libx264 @ 000001df2b62cd40] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 20% 10%  6%  6%  7%  7%  8%  8%
[libx264 @ 000001df2b62cd40] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 28%  7%  4%  6%  6%  6%  5%  5%
[libx264 @ 000001df2b62cd40] i8c dc,h,v,p: 34% 27% 28% 11%
[libx264 @ 000001df2b62cd40] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 000001df2b62cd40] ref P L0: 71.1% 14.9% 10.6%  3.4%
[libx264 @ 000001df2b62cd40] ref B L0: 93.3%  5.9%  0.8%
[libx264 @ 000001df2b62cd40] ref B L1: 97.8%  2.2%
[libx264 @ 000001df2b62cd40] kb/s:676.90
[aac @ 000001df2b6a5620] Qavg: 1165.766
Exiting normally, received signal 2.
Terminate batch job (Y/N)? y


    


  • Encoding images to h264 and rtp output : SDP file without sprop-parameter-sets does not play

    14 septembre 2021, par oarfish

    tl ;dr : I try to encode acquired camera frames to h264, send via RTP
and play this back on another device. SDP file generated by ffmpeg for
a sample video has info which my own SDP file misses. My SDP file
plays in ffplay, but not VLC, while both play ffmpeg's SDP file. I am
suspecting missing sprop-parameter-sets in my SDP file.

    


    Ultimately I want to play this back in VLC.

    



    


    I am writing code that encodes images to h264 and outputs to an RTP
server (or client ? anyway the part that is listening). I generate an
SDP file for this.

    


      

    • ffplay plays the stream without problem
    • 


    • mplayer shows a green box embedded in a larger black box, but I read
somewhere it only supports mpegts over RTP, so not sure
    • 


    • VLC does not play the SDP file.
    • 


    


    Now when instead I use some random video and have ffmpeg output an SDP
file like so

    


    ffmpeg     -re     -i some.mp4     -an     -c:v copy -f rtp -sdp_file
video.sdp     "rtp://127.0.0.1:5004"


    


    I can see that the generated SDP file – which plays in both ffplay and
VLC – includes the base64 encoded sprop-parameter-sets field, and
removing this causes the stream to not play.

    


    > cat video.sdp
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 58.76.100
m=video 5004 RTP/AVP 96
b=AS:1034
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;
sprop-parameter-sets=Z2QANKzZQDAA7fiMBagICAoAAAMAAgAAAwDwHjBjLA==,aOvjyyLA;
profile-level-id=640034


    


    My own SDP file on the other hand, does not contain this information,
and VLC hangs for 10s and then stops trying with "no data received".

    


    > cat test.sdp
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 58.76.100
m=video 44499 RTP/AVP 96
b=AS:2000
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1


    


    So my theory is that my custom code must somehow add this SPS
information to the SDP file. But despite hours of searching, I could
not find a structured way to set the extradata field on the AVStream's
AVCodecParams. The code I'm using is roughly this (I'm sure there's
unrelated errors in there) :

    


    // variables&#xA;std::vector imgbuf;&#xA;AVFormatContext *ofmt_ctx = nullptr;&#xA;AVCodec *out_codec = nullptr;&#xA;AVStream *out_stream = nullptr;&#xA;AVCodecContext *out_codec_ctx = nullptr;&#xA;SwsContext *swsctx = nullptr;&#xA;cv::Mat canvas_;&#xA;unsigned int height_;&#xA;unsigned int width_;&#xA;unsigned int fps_;&#xA;AVFrame *frame_ = nullptr;&#xA;&#xA;AVOutputFormat *format = av_guess_format("rtp", nullptr, nullptr);&#xA;const auto url = std::string("rtp://127.0.0.1:5001");&#xA;avformat_alloc_output_context2(ofmt_ctx, format, format->name, url.c_str());&#xA;&#xA;out_codec = avcodec_find_encoder(AV_CODEC_ID_H264);&#xA;stream = avformat_new_stream(ofmt_ctx, out_codec);&#xA;out_codec_ctx = avcodec_alloc_context3(out_codec);&#xA;&#xA;// then, for each incoming image:&#xA;while (receive_image) {&#xA;  static bool first_time = true;&#xA;  if (first_time) {&#xA;    // discover necessary params such as image dimensions from the first&#xA;    // received image&#xA;    first_time = false;&#xA;    height_ = image.rows;&#xA;    width_ = image.cols;&#xA;&#xA;    codec_ctx->codec_tag = 0;&#xA;    codec_ctx->bit_rate = 2e6;&#xA;    // does nothing, unfortunately&#xA;    codec_ctx->thread_count = 1;&#xA;    codec_ctx->codec_id = AV_CODEC_ID_H264;&#xA;    codec_ctx->codec_type = AVMEDIA_TYPE_VIDEO;&#xA;    codec_ctx->width = width_;&#xA;    codec_ctx->height = height_;&#xA;    codec_ctx->gop_size = 6;&#xA;    codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P;&#xA;    codec_ctx->framerate = fps_;&#xA;    codec_ctx->time_base = av_inv_q(fps_);&#xA;&#xA;    avcodec_parameters_from_context(stream, out_codec_ctx);&#xA;&#xA;    // this stuff is empty: is that the problem?&#xA;    stream->codecpar->extradata = codec_ctx->extradata;&#xA;    stream->codecpar->extradata_size = codec_ctx->extradata_size;&#xA;&#xA;    AVDictionary *codec_options = nullptr;&#xA;    av_dict_set(&amp;codec_options, "profile", "high", 0);&#xA;    av_dict_set(&amp;codec_options, "preset", "ultrafast", 0);&#xA;    av_dict_set(&amp;codec_options, "tune", "zerolatency", 0);&#xA;&#xA;    // open video encoder&#xA;    avcodec_open2(codec_ctx, codec, &amp;codec_options);&#xA;&#xA;    stream->time_base.num = 1;&#xA;    stream->time_base.den = fps_;&#xA;    avio_open(&amp;(ofmt_ctx->pb), ofmt_ctx->filename, AVIO_FLAG_WRITE);&#xA;&#xA;    /* Write a file for VLC */&#xA;    char buf[200000];&#xA;    AVFormatContext *ac[] = {ofmt_ctx};&#xA;    av_sdp_create(ac, 1, buf, 20000);&#xA;    printf("sdp:\n%s\n", buf);&#xA;    FILE *fsdp = fopen("test.sdp", "w");&#xA;    fprintf(fsdp, "%s", buf);&#xA;    fclose(fsdp);&#xA;&#xA;    swsctx = sws_getContext(width_, height_, AV_PIX_FMT_BGR24, width_, height_,&#xA;                            out_codec_ctx->pix_fmt, SWS_BICUBIC, nullptr,&#xA;                            nullptr, nullptr);&#xA;  }&#xA;&#xA;  if (!frame_) {&#xA;    frame_ = av_frame_alloc();&#xA;&#xA;    std::uint8_t *framebuf = new uint8_t[av_image_get_buffer_size(&#xA;        codec_ctx->pix_fmt, width_, height_, 1)];&#xA;    av_image_fill_arrays(frame_->data, frame_->linesize, framebuf,&#xA;                         codec_ctx->pix_fmt, width, height, 1);&#xA;    frame_->width = width_;&#xA;    frame_->height = height_;&#xA;    frame_->format = static_cast<int>(codec_ctx->pix_fmt);&#xA;    success = avformat_write_header(ofmt_ctx, nullptr);&#xA;  }&#xA;  if (imgbuf.empty()) {&#xA;    imgbuf.resize(height_ * width_ * 3 &#x2B; 16);&#xA;    canvas_ = cv::Mat(height_, width_, CV_8UC3, imgbuf.data(), width_ * 3);&#xA;  } else {&#xA;    image.copyTo(canvas_);&#xA;  }&#xA;&#xA;  const int stride[] = {static_cast<int>(image.step[0])};&#xA;&#xA;  sws_scale(swsctx, &amp;canvas_.data, stride, 0, canvas_.rows, frame_->data,&#xA;            frame_->linesize);&#xA;  frame_->pts &#x2B;= av_rescale_q(1, out_codec_ctx->time_base, stream->time_base);&#xA;&#xA;  AVPacket pkt = {0};&#xA;  avcodec_send_frame(out_codec_ctx, frame_);&#xA;  avcodec_receive_packet(out_codec_ctx, &amp;pkt);&#xA;  av_interleaved_write_frame(ofmt_ctx, &amp;pkt);&#xA;}&#xA;</int></int>

    &#xA;

    Can anyone offer some advice here ?

    &#xA;

    &#xA;

    Update

    &#xA;

    When setting

    &#xA;

    this->out_codec_ctx->flags |=AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;

    &#xA;

    extradata is actually present in the codec context, but I had to move avcodec_parameters_from_context() after avcodec_open2(), as the extradata is empty before opening the codec. I now get sprop-parameter-sets in the SDP file, but VLC still does not play it.

    &#xA;

  • Encoding images to h264 and rtp output : SDP file without sprop-parameter-sets does not play

    14 septembre 2021, par oarfish

    tl ;dr : I try to encode acquired camera frames to h264, send via RTP&#xA;and play this back on another device. SDP file generated by ffmpeg for&#xA;a sample video has info which my own SDP file misses. My SDP file&#xA;plays in ffplay, but not VLC, while both play ffmpeg's SDP file. I am&#xA;suspecting missing sprop-parameter-sets in my SDP file.

    &#xA;

    Ultimately I want to play this back in VLC.

    &#xA;


    &#xA;

    I am writing code that encodes images to h264 and outputs to an RTP&#xA;server (or client ? anyway the part that is listening). I generate an&#xA;SDP file for this.

    &#xA;

      &#xA;
    • ffplay plays the stream without problem
    • &#xA;

    • mplayer shows a green box embedded in a larger black box, but I read&#xA;somewhere it only supports mpegts over RTP, so not sure
    • &#xA;

    • VLC does not play the SDP file.
    • &#xA;

    &#xA;

    Now when instead I use some random video and have ffmpeg output an SDP&#xA;file like so

    &#xA;

    ffmpeg     -re     -i some.mp4     -an     -c:v copy -f rtp -sdp_file&#xA;video.sdp     "rtp://127.0.0.1:5004"&#xA;

    &#xA;

    I can see that the generated SDP file – which plays in both ffplay and&#xA;VLC – includes the base64 encoded sprop-parameter-sets field, and&#xA;removing this causes the stream to not play.

    &#xA;

    > cat video.sdp&#xA;v=0&#xA;o=- 0 0 IN IP4 127.0.0.1&#xA;s=No Name&#xA;c=IN IP4 127.0.0.1&#xA;t=0 0&#xA;a=tool:libavformat 58.76.100&#xA;m=video 5004 RTP/AVP 96&#xA;b=AS:1034&#xA;a=rtpmap:96 H264/90000&#xA;a=fmtp:96 packetization-mode=1;&#xA;sprop-parameter-sets=Z2QANKzZQDAA7fiMBagICAoAAAMAAgAAAwDwHjBjLA==,aOvjyyLA;&#xA;profile-level-id=640034&#xA;

    &#xA;

    My own SDP file on the other hand, does not contain this information,&#xA;and VLC hangs for 10s and then stops trying with "no data received".

    &#xA;

    > cat test.sdp&#xA;v=0&#xA;o=- 0 0 IN IP4 127.0.0.1&#xA;s=No Name&#xA;c=IN IP4 127.0.0.1&#xA;t=0 0&#xA;a=tool:libavformat 58.76.100&#xA;m=video 44499 RTP/AVP 96&#xA;b=AS:2000&#xA;a=rtpmap:96 H264/90000&#xA;a=fmtp:96 packetization-mode=1&#xA;

    &#xA;

    So my theory is that my custom code must somehow add this SPS&#xA;information to the SDP file. But despite hours of searching, I could&#xA;not find a structured way to set the extradata field on the AVStream's&#xA;AVCodecParams. The code I'm using is roughly this (I'm sure there's&#xA;unrelated errors in there) :

    &#xA;

    // variables&#xA;std::vector imgbuf;&#xA;AVFormatContext *ofmt_ctx = nullptr;&#xA;AVCodec *out_codec = nullptr;&#xA;AVStream *out_stream = nullptr;&#xA;AVCodecContext *out_codec_ctx = nullptr;&#xA;SwsContext *swsctx = nullptr;&#xA;cv::Mat canvas_;&#xA;unsigned int height_;&#xA;unsigned int width_;&#xA;unsigned int fps_;&#xA;AVFrame *frame_ = nullptr;&#xA;&#xA;AVOutputFormat *format = av_guess_format("rtp", nullptr, nullptr);&#xA;const auto url = std::string("rtp://127.0.0.1:5001");&#xA;avformat_alloc_output_context2(ofmt_ctx, format, format->name, url.c_str());&#xA;&#xA;out_codec = avcodec_find_encoder(AV_CODEC_ID_H264);&#xA;stream = avformat_new_stream(ofmt_ctx, out_codec);&#xA;out_codec_ctx = avcodec_alloc_context3(out_codec);&#xA;&#xA;// then, for each incoming image:&#xA;while (receive_image) {&#xA;  static bool first_time = true;&#xA;  if (first_time) {&#xA;    // discover necessary params such as image dimensions from the first&#xA;    // received image&#xA;    first_time = false;&#xA;    height_ = image.rows;&#xA;    width_ = image.cols;&#xA;&#xA;    codec_ctx->codec_tag = 0;&#xA;    codec_ctx->bit_rate = 2e6;&#xA;    // does nothing, unfortunately&#xA;    codec_ctx->thread_count = 1;&#xA;    codec_ctx->codec_id = AV_CODEC_ID_H264;&#xA;    codec_ctx->codec_type = AVMEDIA_TYPE_VIDEO;&#xA;    codec_ctx->width = width_;&#xA;    codec_ctx->height = height_;&#xA;    codec_ctx->gop_size = 6;&#xA;    codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P;&#xA;    codec_ctx->framerate = fps_;&#xA;    codec_ctx->time_base = av_inv_q(fps_);&#xA;&#xA;    avcodec_parameters_from_context(stream, out_codec_ctx);&#xA;&#xA;    // this stuff is empty: is that the problem?&#xA;    stream->codecpar->extradata = codec_ctx->extradata;&#xA;    stream->codecpar->extradata_size = codec_ctx->extradata_size;&#xA;&#xA;    AVDictionary *codec_options = nullptr;&#xA;    av_dict_set(&amp;codec_options, "profile", "high", 0);&#xA;    av_dict_set(&amp;codec_options, "preset", "ultrafast", 0);&#xA;    av_dict_set(&amp;codec_options, "tune", "zerolatency", 0);&#xA;&#xA;    // open video encoder&#xA;    avcodec_open2(codec_ctx, codec, &amp;codec_options);&#xA;&#xA;    stream->time_base.num = 1;&#xA;    stream->time_base.den = fps_;&#xA;    avio_open(&amp;(ofmt_ctx->pb), ofmt_ctx->filename, AVIO_FLAG_WRITE);&#xA;&#xA;    /* Write a file for VLC */&#xA;    char buf[200000];&#xA;    AVFormatContext *ac[] = {ofmt_ctx};&#xA;    av_sdp_create(ac, 1, buf, 20000);&#xA;    printf("sdp:\n%s\n", buf);&#xA;    FILE *fsdp = fopen("test.sdp", "w");&#xA;    fprintf(fsdp, "%s", buf);&#xA;    fclose(fsdp);&#xA;&#xA;    swsctx = sws_getContext(width_, height_, AV_PIX_FMT_BGR24, width_, height_,&#xA;                            out_codec_ctx->pix_fmt, SWS_BICUBIC, nullptr,&#xA;                            nullptr, nullptr);&#xA;  }&#xA;&#xA;  if (!frame_) {&#xA;    frame_ = av_frame_alloc();&#xA;&#xA;    std::uint8_t *framebuf = new uint8_t[av_image_get_buffer_size(&#xA;        codec_ctx->pix_fmt, width_, height_, 1)];&#xA;    av_image_fill_arrays(frame_->data, frame_->linesize, framebuf,&#xA;                         codec_ctx->pix_fmt, width, height, 1);&#xA;    frame_->width = width_;&#xA;    frame_->height = height_;&#xA;    frame_->format = static_cast<int>(codec_ctx->pix_fmt);&#xA;    success = avformat_write_header(ofmt_ctx, nullptr);&#xA;  }&#xA;  if (imgbuf.empty()) {&#xA;    imgbuf.resize(height_ * width_ * 3 &#x2B; 16);&#xA;    canvas_ = cv::Mat(height_, width_, CV_8UC3, imgbuf.data(), width_ * 3);&#xA;  } else {&#xA;    image.copyTo(canvas_);&#xA;  }&#xA;&#xA;  const int stride[] = {static_cast<int>(image.step[0])};&#xA;&#xA;  sws_scale(swsctx, &amp;canvas_.data, stride, 0, canvas_.rows, frame_->data,&#xA;            frame_->linesize);&#xA;  frame_->pts &#x2B;= av_rescale_q(1, out_codec_ctx->time_base, stream->time_base);&#xA;&#xA;  AVPacket pkt = {0};&#xA;  avcodec_send_frame(out_codec_ctx, frame_);&#xA;  avcodec_receive_packet(out_codec_ctx, &amp;pkt);&#xA;  av_interleaved_write_frame(ofmt_ctx, &amp;pkt);&#xA;}&#xA;</int></int>

    &#xA;

    Can anyone offer some advice here ?

    &#xA;

    &#xA;

    Update

    &#xA;

    When setting

    &#xA;

    this->out_codec_ctx->flags |=AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;

    &#xA;

    extradata is actually present in the codec context, but I had to move avcodec_parameters_from_context() after avcodec_open2(), as the extradata is empty before opening the codec. I now get sprop-parameter-sets in the SDP file, but VLC still does not play it.

    &#xA;