Recherche avancée

Médias (91)

Autres articles (81)

Sur d’autres sites (13988)

  • How to send libmmpeg AVPacket through WebRTC (using libdatachannel)

    29 mars 2022, par mike

    I'm encoding a video frame with the ffmpeg libraries, generating an AVPacket with compressed data.

    


    Thanks to some recent advice here on S/O, I am trying to send that frame over a network using the WebRTC library libdatachannel, specifically by adapting the example here :

    


    https://github.com/paullouisageneau/libdatachannel/tree/master/examples/streamer

    


    I am seeing problems inside h264rtppacketizer.cpp (part of the library, not the example) which are almost certainly to do with how I'm providing the sample data.
(I don't think that this is anything to do with libdatachannel specifically, it will be an issue with what I'm sending)

    


    The example code reads each encoded frame from a file, and populates a sample by setting the content of the file to the contents of the file :

    


    sample = *reinterpret_cast *>(&fileContents);

    


    sample is just a std::vector<byte>;</byte>

    &#xA;

    I have naively copied the contents of an AVPacket->data pointer into the sample vector :

    &#xA;

    sample.resize(pkt->size);&#xA;memcpy(sample.data(), pkt->data, pkt->size * sizeof(std::byte));    &#xA;

    &#xA;

    but the packetizer is falling over when trying to get length values out of that data.&#xA;Specifically, in the following code, the first iteration gets a length of 1, but the second, looking up index 5, gives 1119887324. This is way too big for my data, which is only 3526 bytes (the whole frame is a single colour so likely to be small once encoded) :

    &#xA;

    while (index &lt; message->size()) {&#xA;assert(index &#x2B; 4 &lt; message->size());&#xA;auto lengthPtr = (uint32_t *)(message->data() &#x2B; index);&#xA;uint32_t length = ntohl(*lengthPtr);&#xA;auto naluStartIndex = index &#x2B; 4;&#xA;auto naluEndIndex = naluStartIndex &#x2B; length;&#xA;assert(naluEndIndex &lt;= message->size());    &#xA;        &#xA;auto begin = message->begin() &#x2B; naluStartIndex;&#xA;auto end = message->begin() &#x2B; naluEndIndex;&#xA;nalus->push_back(std::make_shared<nalunit>(begin, end));&#xA;index = naluEndIndex;&#xA;}&#xA;</nalunit>

    &#xA;

    Here is a dump of

    &#xA;

    uint32_t length = ntohl(*lengthPtr);&#xA;

    &#xA;

    for the first few elements of the message (*lengthPtr in parentheses) :

    &#xA;

    [2022-03-29 15:12:01.182] [info] index 0: 1  (16777216)&#xA;[2022-03-29 15:12:01.183] [info] index 1: 359  (1728118784)&#xA;[2022-03-29 15:12:01.184] [info] index 2: 91970  (1114046720)&#xA;[2022-03-29 15:12:01.186] [info] index 3: 23544512  (3225577217)&#xA;[2022-03-29 15:12:01.186] [info] index 4: 1732427807  (532693607)&#xA;[2022-03-29 15:12:01.187] [info] index 5: 1119887324  (3693068354)&#xA;[2022-03-29 15:12:01.188] [info] index 6: 3223313413  (98312128)&#xA;[2022-03-29 15:12:01.188] [info] index 7: 534512896  (384031)&#xA;[2022-03-29 15:12:01.188] [info] index 8: 3691315291  (1526728156)&#xA;[2022-03-29 15:12:01.189] [info] index 9: 83909537  (2707095557)&#xA;[2022-03-29 15:12:01.189] [info] index 10: 6004992  (10574592)&#xA;[2022-03-29 15:12:01.190] [info] index 11: 1537277952  (41307)&#xA;[2022-03-29 15:12:01.190] [info] index 12: 2701131779  (50331809)&#xA;[2022-03-29 15:12:01.192] [info] index 13: 768  (196608)&#xA;

    &#xA;

    (I know I should post a complete sample, I am working on it)

    &#xA;

      &#xA;
    • I am fairly sure I am just missing something basic. E.g. am I supposed to do something with the AVPacket side_data, does AVPacket have or miss some header info ?

      &#xA;

    • &#xA;

    • If I just fwrite the pkt->data for a single frame to disk, I can read the codec information with ffprobe :

      &#xA;

    • &#xA;

    &#xA;

    Input #0, h264, from &#x27;encodedOut.h264&#x27;:&#xA;Duration: N/A, bitrate: N/A&#xA;Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive), 1280x720, 30 tbr, 1200k tbn&#xA;

    &#xA;

      &#xA;
    • whereas the same for the example input files (again a single frame) gives the following :
    • &#xA;

    &#xA;

    [h264 @ 000001c88d1135c0] Format h264 detected only with low score of 1, misdetection possible!&#xA;[h264 @ 000001c88f337400] missing picture in access unit with size 85306&#xA;[extract_extradata @ 000001c88d11ee40] No start code is found.&#xA;sample-0.h264: Invalid data found when processing input&#xA;

    &#xA;

  • obs-studio build fails on Debian distros

    24 août 2021, par Fabian Druschke

    Ahoy ahoy.&#xA;Currently i am trying to compile obs-studio on my Debian machine (Debian Bullseye).&#xA;I have compiled FFMpeg myself in order to enable nvenc support for NVIDIA hardware acceleration.&#xA;Now i try to compile obs-studio but it always breaks at this error :

    &#xA;

    [ 41%] Built target obs-x264&#xA;[ 42%] Built target obs-libfdk&#xA;[ 43%] Building C object plugins/obs-ffmpeg/CMakeFiles/obs-ffmpeg.dir/obs-ffmpeg-audio-encoders.c.o&#xA;In file included from /tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:27:&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-formats.h:3:47: error: unknown type name ‘AVCodecContext’; did you mean ‘AVFormatContext’?&#xA;    3 | static inline int64_t rescale_ts(int64_t val, AVCodecContext *context,&#xA;      |                                               ^~~~~~~~~~~~~~&#xA;      |                                               AVFormatContext&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c: In function ‘convert_speaker_layout’:&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:65:10: error: ‘AV_CH_LAYOUT_MONO’ undeclared (first use in this function)&#xA;   65 |   return AV_CH_LAYOUT_MONO;&#xA;      |          ^~~~~~~~~~~~~~~~~&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:65:10: note: each undeclared identifier is reported only once for each function it appears in&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:67:10: error: ‘AV_CH_LAYOUT_STEREO’ undeclared (first use in this function)&#xA;   67 |   return AV_CH_LAYOUT_STEREO;&#xA;      |          ^~~~~~~~~~~~~~~~~~~&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:69:10: error: ‘AV_CH_LAYOUT_SURROUND’ undeclared (first use in this function)&#xA;   69 |   return AV_CH_LAYOUT_SURROUND;&#xA;      |          ^~~~~~~~~~~~~~~~~~~~~&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:71:10: error: ‘AV_CH_LAYOUT_4POINT0’ undeclared (first use in this function)&#xA;   71 |   return AV_CH_LAYOUT_4POINT0;&#xA;      |          ^~~~~~~~~~~~~~~~~~~~&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:73:10: error: ‘AV_CH_LAYOUT_4POINT1’ undeclared (first use in this function)&#xA;   73 |   return AV_CH_LAYOUT_4POINT1;&#xA;      |          ^~~~~~~~~~~~~~~~~~~~&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:75:10: error: ‘AV_CH_LAYOUT_5POINT1_BACK’ undeclared (first use in this function)&#xA;   75 |   return AV_CH_LAYOUT_5POINT1_BACK;&#xA;      |          ^~~~~~~~~~~~~~~~~~~~~~~~~&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:77:10: error: ‘AV_CH_LAYOUT_7POINT1’ undeclared (first use in this function)&#xA;   77 |   return AV_CH_LAYOUT_7POINT1;&#xA;      |          ^~~~~~~~~~~~~~~~~~~~&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c: In function ‘convert_ff_channel_layout’:&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:88:7: error: ‘AV_CH_LAYOUT_MONO’ undeclared (first use in this function)&#xA;   88 |  case AV_CH_LAYOUT_MONO:&#xA;      |       ^~~~~~~~~~~~~~~~~&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:90:7: error: ‘AV_CH_LAYOUT_STEREO’ undeclared (first use in this function)&#xA;   90 |  case AV_CH_LAYOUT_STEREO:&#xA;      |       ^~~~~~~~~~~~~~~~~~~&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:92:7: error: ‘AV_CH_LAYOUT_SURROUND’ undeclared (first use in this function)&#xA;   92 |  case AV_CH_LAYOUT_SURROUND:&#xA;      |       ^~~~~~~~~~~~~~~~~~~~~&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:94:7: error: ‘AV_CH_LAYOUT_4POINT0’ undeclared (first use in this function)&#xA;   94 |  case AV_CH_LAYOUT_4POINT0:&#xA;      |       ^~~~~~~~~~~~~~~~~~~~&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:96:7: error: ‘AV_CH_LAYOUT_4POINT1’ undeclared (first use in this function)&#xA;   96 |  case AV_CH_LAYOUT_4POINT1:&#xA;      |       ^~~~~~~~~~~~~~~~~~~~&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:98:7: error: ‘AV_CH_LAYOUT_5POINT1_BACK’ undeclared (first use in this function)&#xA;   98 |  case AV_CH_LAYOUT_5POINT1_BACK:&#xA;      |       ^~~~~~~~~~~~~~~~~~~~~~~~~&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:100:7: error: ‘AV_CH_LAYOUT_7POINT1’ undeclared (first use in this function)&#xA;  100 |  case AV_CH_LAYOUT_7POINT1:&#xA;      |       ^~~~~~~~~~~~~~~~~~~~&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c: In function ‘enc_create’:&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:205:13: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]&#xA;  205 |  enc->codec = avcodec_find_encoder_by_name(type);&#xA;      |             ^&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:209:14: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]&#xA;  209 |   enc->codec = avcodec_find_encoder_by_name(alt);&#xA;      |              ^&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c: In function ‘do_encode’:&#xA;/tmp/obs-studio/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c:343:16: error: implicit declaration of function ‘rescale_ts’ [-Werror=implicit-function-declaration]&#xA;  343 |  packet->pts = rescale_ts(avpacket.pts, enc->context, time_base);&#xA;      |                ^~~~~~~~~~&#xA;cc1: some warnings being treated as errors&#xA;make[2]: *** [plugins/obs-ffmpeg/CMakeFiles/obs-ffmpeg.dir/build.make:95: plugins/obs-ffmpeg/CMakeFiles/obs-ffmpeg.dir/obs-ffmpeg-audio-encoders.c.o] Error 1&#xA;make[1]: *** [CMakeFiles/Makefile2:1381: plugins/obs-ffmpeg/CMakeFiles/obs-ffmpeg.dir/all] Error 2&#xA;make: *** [Makefile:171: all] Error 2&#xA;

    &#xA;

    I didn't find any fixes yet. So i thought i was clever, so i set up a Debian Sid virtual machine and instead of using the git, i used apt source obs-studio and apt build-dep obs-studio. Unfortunately the result was the same, dpkg-buildpackage -rfakeroot -b -uc -us had the same result, in the same file : obs-ffmpeg-audio-encoders.c&#xA;What might be the issue here ? Did i miss something fundamental ? Thanks in advance friends !

    &#xA;

  • Can't play rtp stream from ffmpeg/avconv, no data received

    6 mars 2014, par Foo Barazz

    I started avserver on my Raspberry Pi, webcam attached I read from /dev/video0 with

    pi@raspberrypi $ avconv -f video4linux2 -i /dev/video0 -vcodec mpeg2video -r 25 - pix_fmt yuv420p -me_method epzs -b 2600k -bt 256k -f rtp rtp://192.168.0.124:8090

    avconv version 0.8.6-6:0.8.6-1+rpi1, Copyright (c) 2000-2013 the Libav developers
     built on Mar 31 2013 13:58:10 with gcc 4.6.3
    [video4linux2 @ 0x17c1720] Estimating duration from bitrate, this may be inaccurate
    Input #0, video4linux2, from &#39;/dev/video0&#39;:
     Duration: N/A, start: 615.594215, bitrate: 36864 kb/s
       Stream #0.0: Video: rawvideo, yuyv422, 320x240, 36864 kb/s, 30 tbr, 1000k tbn, 30 tbc
    [buffer @ 0x17c16e0] w:320 h:240 pixfmt:yuyv422
    [avsink @ 0x17c2f00] auto-inserting filter &#39;auto-inserted scaler 0&#39; between the filter &#39;src&#39; and the filter &#39;out&#39;
    [scale @ 0x17c34c0] w:320 h:240 fmt:yuyv422 -> w:320 h:240 fmt:yuv420p flags:0x4
    Output #0, rtp, to &#39;rtp://192.168.0.124:8090&#39;:
     Metadata:
       encoder         : Lavf53.21.1
       Stream #0.0: Video: mpeg2video, yuv420p, 320x240, q=2-31, 2600 kb/s, 90k tbn, 25 tbc
    Stream mapping:
     Stream #0:0 -> #0:0 (rawvideo -> mpeg2video)
    SDP:
    v=0
    o=- 0 0 IN IP4 127.0.0.1
    s=No Name
    c=IN IP4 192.168.0.124
    t=0 0
    a=tool:libavformat 53.21.1
    m=video 8090 RTP/AVP 32
    b=AS:2600

    Press ctrl-c to stop encoding
    frame=  576 fps= 25 q=2.0 size=    2133kB time=23.00 bitrate= 759.8kbits/s dup=390 drop=0    
    frame=  590 fps= 25 q=2.0 size=    2191kB time=23.56 bitrate= 762.0kbits/s dup=400 drop=0    
    frame= 1320 fps= 25 q=2.0 size=    4932kB time=52.76 bitrate= 765.8kbits/s dup=908 drop=0
    ...

    Seems to work fine, it reads data from the webcam.

    Now I'm trying to simply play with ffplay from my Mac with

    $ ffplay rtp://192.168.0.124:8090
    ffplay version 1.2.4 Copyright (c) 2003-2013 the FFmpeg developers
     built on Mar  1 2014 15:18:21 with Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
     configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libvpx --enable-librtmp --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-aacenc --enable-libass --enable-ffplay --enable-libspeex --enable-libschroedinger --enable-libfdk-aac --enable-libopus --enable-frei0r --enable-libopenjpeg --extra-cflags=&#39;-I/usr/local/Cellar/openjpeg/1.5.1/include/openjpeg-1.5 &#39;
     libavutil      52. 18.100 / 52. 18.100
     libavcodec     54. 92.100 / 54. 92.100
     libavformat    54. 63.104 / 54. 63.104
     libavdevice    54.  3.103 / 54.  3.103
     libavfilter     3. 42.103 /  3. 42.103
     libswscale      2.  2.100 /  2.  2.100
     libswresample   0. 17.102 /  0. 17.102
     libpostproc    52.  2.100 / 52.  2.100
       nan A-V:  0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0  
       nan A-V:  0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0  
       nan A-V:  0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0
       ...

    The video doesn't open and it seems to not reading any data from the Raspberry Pi.

    I use the default configuration for avserver.
    The webcam is definitely working as I managed to just write out images with avconv from it.

    What did I miss ?