sourcey / libsourcey

C++14 evented IO libraries for high performance networking and media based applications
https://sourcey.com/libsourcey
GNU Lesser General Public License v2.1
1.31k stars 344 forks source link

multiplexencoder.cpp updateStreamPts() Invalid pts for both streams #281

Open niaz925 opened 4 years ago

niaz925 commented 4 years ago

Tried to build the av module from source and tested the devicerecorder sample using ubuntu 18.04 and ffmpeg 3.4.6 The audio recording seems to be fine but there is no video due to the next pts being calculated as Invalid all the time in the updateStreamPts ()

if (next < _pts) {
    LWarn("Invalid pts (", next ,") <= last (", _pts, ")")
    return false;
}
else if (next == _pts) {
    LWarn("Dropping frame at duplicate PTS: ", next)
    return false;
}

Due to this the data is not passed to the video encoder

if (!updateStreamPts(_video->stream, &time)) {
    return false; // duplicate PTS
}

Similar issue has been raised previously https://github.com/sourcey/libsourcey/issues/241

Where its been suggested to remove the realtime pts calculation as the av_read_frame() sets up the pts.

I have tried to comment out that line in the mediacapture.cpp but still I am getting the invalid pts and there is no video recording. if (_realtime) { // ipacket.pts = time::hrtime() - startTime; }

Any ideas why is this occurring, the only difference I can see is that I am using a newer version of ffmpeg 3.4.6 compared to 3.0 as in https://github.com/sourcey/libsourcey/issues/241

niaz925 commented 4 years ago

ffprobe version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2007-2019 the FFmpeg developers built with gcc 7 (Ubuntu 7.3.0-16ubuntu3) configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared 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 libavresample 3. 7. 0 / 3. 7. 0 libswscale 4. 8.100 / 4. 8.100 libswresample 2. 9.100 / 2. 9.100 libpostproc 54. 7.100 / 54. 7.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'deviceoutput.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.83.100 Duration: 00:00:01.05, start: 1581967508.790998, bitrate: 73 kb/s Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 63 kb/s (default) Metadata: handler_name : SoundHandler

niaz925 commented 4 years ago

Console output:

Input #0, video4linux2,v4l2, from '/dev/video0': Duration: N/A, start: 1463657.924827, bitrate: 147456 kb/s Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 147456 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc Input #0, alsa, from 'default': Duration: N/A, start: 1581967508.793217, bitrate: 1411 kb/s Stream #0:0: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s [libx264 @ 0x560703f91980] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 [libx264 @ 0x560703f91980] profile High, level 2.1 [libx264 @ 0x560703f91980] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=2 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=9 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=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=50 rc=abr mbtree=1 bitrate=128 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 [mp4 @ 0x560703fd53a0] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead. [mp4 @ 0x560703fd53a0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead. [mp4 @ 0x560703fd53a0] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead. [mp4 @ 0x560703fd53a0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead. Output #0, mp4, to 'deviceoutput.mp4': Metadata: encoder : Lavf57.83.100 Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 400x300, q=-1--1, 128 kb/s, 12800 tbn, 25 tbc Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 64 kb/s Read video frame: pts=1463657924827, dts=1463657924827 Aud: Invalid pts: next=69764767137780<= last 0 curr pts 1581967508793217 Aud: Invalid pts: next=69764767137834<= last 69764767137780 curr pts 1581967508794438 Aud: Invalid pts: next=69764767137903<= last 69764767137834 curr pts 1581967508796001 Aud: Invalid pts: next=69764767137964<= last 69764767137903 curr pts 1581967508797390 Aud: Invalid pts: next=69764767138031<= last 69764767137964 curr pts 1581967508798910 Aud: Invalid pts: next=69764767138094<= last 69764767138031 curr pts 1581967508800333 Aud: Invalid pts: next=69764767138161<= last 69764767138094 curr pts 1581967508801842 Aud: Invalid pts: next=69764767138224<= last 69764767138161 curr pts 1581967508803277 Aud: Invalid pts: next=69764767138290<= last 69764767138224 curr pts 1581967508804777 Vid: Invalid pts: next=353<= last 69764767138290 curr pts 27587 Read video frame: pts=1463657960827, dts=1463657960827 Vid: Invalid pts: next=20959<= last 69764767138290 curr pts 1637465 Aud: Invalid pts: next=69764767138354<= last 69764767138290 curr pts 1581967508806228 Aud: Invalid pts: next=69764767138416<= last 69764767138354 curr pts 1581967508807634 Aud: Invalid pts: next=69764767138481<= last 69764767138416 curr pts 1581967508809095 Aud: Invalid pts: next=69764767138543<= last 69764767138481 curr pts 1581967508810519 Aud: Invalid pts: next=69764767138608<= last 69764767138543 curr pts 1581967508811987 Aud: Invalid pts: next=69764767138671<= last 69764767138608 curr pts 1581967508813421 Read video frame: pts=1463657992828, dts=1463657992828 Aud: Invalid pts: next=69764767138736<= last 69764767138671 curr pts 1581967508814890