Javacv: Video streaming via RTMP results in stuttering

Created on 18 Dec 2019  路  7Comments  路  Source: bytedeco/javacv

Hello again,
I am using RecordActivity.java to stream live via RTMP.
The video quality is as expecetd. However the video is not smooth. There are minor stutters (freezes) for less then a seconds periodically throughout the stream.When the video resumes, it looks like it loses some frames

Some of the modifications in initRecorder() are :

        recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
        recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);
        // Set in the surface changed method
        recorder.setFrameRate(30);
        recorder.setVideoOption("maxrate", "2.5M");
        recorder.setVideoOption("minrate", "2.5M");
        recorder.setVideoOption("bufsize", "5M");
        recorder.setVideoOption("vsync", "0");
        recorder.setGopSize(60);

and the filter command is :

String filterString =String.format("movie=" + absolutePathToLogoImage + "[img];" +
                "[in][img]overlay=120,format=pix_fmts=bgr24," +
                "drawtext=fontfile=" + fontFilePath + ":text='%s'" + ":fontsize=30:fontcolor=black:x=405:y=25," +
                "drawtext=fontfile=" + fontFilePath + ":text='%s'" + ":fontsize=30:fontcolor=white:x=190:y=25," +
                "drawtext=fontfile=" + fontFilePath + ":text='%s'" + ":fontsize=30:fontcolor=white:x=520:y=25", displayText1, displayText2, displayText3);

Nothing wrong in the logs:

2019-12-18 15:33:14.469 2914-2914/com.example.examplebrodcast I/RecordActivity: create yuvImage
2019-12-18 15:33:14.469 2914-2914/com.example.examplebrodcast I/RecordActivity: recorder initialize success
2019-12-18 15:33:14.785 2914-2914/com.example.examplebrodcast I/System.out: [libx264 @ 0x771d71fb00] using mv_range_thread = 24
2019-12-18 15:33:14.786 2914-2914/com.example.examplebrodcast I/System.out: [libx264 @ 0x771d71fb00] using cpu capabilities: ARMv8 NEON
2019-12-18 15:33:14.792 2914-2914/com.example.examplebrodcast I/System.out: [libx264 @ 0x771d71fb00] profile High, level 3.1, 4:2:0, 8-bit
2019-12-18 15:33:14.792 2914-2914/com.example.examplebrodcast I/System.out: [libx264 @ 0x771d71fb00] 264 - core 157 - 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=60 keyint_min=6 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=400 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=5000 vbv_bufsize=5000 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00
2019-12-18 15:33:14.931 2914-2914/com.example.examplebrodcast I/System.out: [rtmp @ 0x770f4ae8e0] No default whitelist set
2019-12-18 15:33:14.931 2914-2914/com.example.examplebrodcast I/System.out: [tcp @ 0x770f51a680] No default whitelist set
2019-12-18 15:33:15.080 2914-2914/com.example.examplebrodcast I/System.out: [tcp @ 0x770f51a680] Original list of addresses:
2019-12-18 15:33:15.081 2914-2914/com.example.examplebrodcast I/System.out: [tcp @ 0x770f51a680] Address 2404:6800:4010:c::7 port 1935
2019-12-18 15:33:15.081 2914-2914/com.example.examplebrodcast I/System.out: [tcp @ 0x770f51a680] Address 173.194.154.10 port 1935
2019-12-18 15:33:15.081 2914-2914/com.example.examplebrodcast I/System.out: [tcp @ 0x770f51a680] Interleaved list of addresses:
2019-12-18 15:33:15.081 2914-2914/com.example.examplebrodcast I/System.out: [tcp @ 0x770f51a680] Address 2404:6800:4010:c::7 port 1935
2019-12-18 15:33:15.081 2914-2914/com.example.examplebrodcast I/System.out: [tcp @ 0x770f51a680] Address 173.194.154.10 port 1935
2019-12-18 15:33:15.081 2914-2914/com.example.examplebrodcast I/System.out: [tcp @ 0x770f51a680] Starting connection attempt to 2404:6800:4010:c::7 port 1935
2019-12-18 15:33:15.133 2914-2914/com.example.examplebrodcast I/System.out: [tcp @ 0x770f51a680] Successfully connected to 2404:6800:4010:c::7 port 1935
2019-12-18 15:33:15.133 2914-2914/com.example.examplebrodcast I/System.out: [rtmp @ 0x770f4ae8e0] Handshaking...
2019-12-18 15:33:15.416 2914-2914/com.example.examplebrodcast I/System.out: [rtmp @ 0x770f4ae8e0] Type answer 3
2019-12-18 15:33:15.416 2914-2914/com.example.examplebrodcast I/System.out: [rtmp @ 0x770f4ae8e0] Server version 4.0.0.1
2019-12-18 15:33:15.417 2914-2914/com.example.examplebrodcast I/System.out: [rtmp @ 0x770f4ae8e0] Proto = rtmp, path = /live2/d367-k9kw-kw89-0uba, app = live2, fname = d367-k9kw-kw89-0uba
2019-12-18 15:33:15.602 2914-2914/com.example.examplebrodcast I/System.out: [rtmp @ 0x770f4ae8e0] Window acknowledgement size = 2500000
2019-12-18 15:33:15.603 2914-2914/com.example.examplebrodcast I/System.out: [rtmp @ 0x770f4ae8e0] Max sent, unacked = 10000000
2019-12-18 15:33:15.604 2914-2914/com.example.examplebrodcast I/System.out: [rtmp @ 0x770f4ae8e0] New incoming chunk size = 256
2019-12-18 15:33:15.812 2914-2914/com.example.examplebrodcast I/System.out: [rtmp @ 0x770f4ae8e0] Releasing stream...
2019-12-18 15:33:15.813 2914-2914/com.example.examplebrodcast I/System.out: [rtmp @ 0x770f4ae8e0] FCPublish stream...
2019-12-18 15:33:15.814 2914-2914/com.example.examplebrodcast I/System.out: [rtmp @ 0x770f4ae8e0] Creating stream...
2019-12-18 15:33:15.989 2914-2914/com.example.examplebrodcast I/System.out: [rtmp @ 0x770f4ae8e0] Sending publish command for 'd367-k9kw-kw89-0uba'
2019-12-18 15:33:16.600 2914-2914/com.example.examplebrodcast I/System.out: Output #0, flv, to 'rtmp://a.rtmp.youtube.com/live2/d367-k9kw-kw89-0uba':
2019-12-18 15:33:16.600 2914-2914/com.example.examplebrodcast I/System.out:   Metadata:
2019-12-18 15:33:16.600 2914-2914/com.example.examplebrodcast I/System.out:     encoder         : 
2019-12-18 15:33:16.601 2914-2914/com.example.examplebrodcast I/System.out: Lavf58.29.100
2019-12-18 15:33:16.602 2914-2914/com.example.examplebrodcast I/System.out:     Stream #0:0
2019-12-18 15:33:16.602 2914-2914/com.example.examplebrodcast I/System.out: , 0, 1/1000
2019-12-18 15:33:16.602 2914-2914/com.example.examplebrodcast I/System.out: : Video: h264 (Constrained Baseline), 1 reference frame ([7][0][0][0] / 0x0007), yuv420p, 864x480 (0x0), 0/1, q=2-31, 400 kb/s
2019-12-18 15:33:16.603 2914-2914/com.example.examplebrodcast I/System.out: , 
2019-12-18 15:33:16.603 2914-2914/com.example.examplebrodcast I/System.out: 30 fps, 
2019-12-18 15:33:16.603 2914-2914/com.example.examplebrodcast I/System.out: 1k tbn, 
2019-12-18 15:33:16.608 2914-2914/com.example.examplebrodcast I/System.out: 30 tbc
2019-12-18 15:33:16.609 2914-2914/com.example.examplebrodcast I/System.out:     Stream #0:1
2019-12-18 15:33:16.610 2914-2914/com.example.examplebrodcast I/System.out: , 0, 1/1000
2019-12-18 15:33:16.610 2914-2914/com.example.examplebrodcast I/System.out: : Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, mono, fltp, delay 1024, 64 kb/s
2019-12-18 15:33:16.624 2914-2914/com.example.examplebrodcast I/System.out: [libx264 @ 0x770f4b8100] using mv_range_thread = 24
2019-12-18 15:33:16.647 2914-2914/com.example.examplebrodcast I/System.out: [libx264 @ 0x770f4b8100] using cpu capabilities: ARMv8 NEON
2019-12-18 15:33:16.661 2914-2914/com.example.examplebrodcast I/System.out: [libx264 @ 0x770f4b8100] profile Constrained Baseline, level 3.1, 4:2:0, 8-bit
2019-12-18 15:33:16.661 2914-2914/com.example.examplebrodcast I/System.out: [libx264 @ 0x770f4b8100] 264 - core 157 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=60 keyint_min=6 scenecut=0 intra_refresh=0 rc_lookahead=0 rc=crf mbtree=0 crf=17.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=5000 vbv_bufsize=5000 crf_max=0.0 nal_hrd=none filler=0 ip_ratio=1.40 aq=0
2019-12-18 15:33:16.665 2914-2914/com.example.examplebrodcast I/System.out: [file @ 0x770f4545c0] Setting default whitelist 'file,crypto'
2019-12-18 15:33:16.678 2914-2914/com.example.examplebrodcast I/System.out: Output #0, flv, to '/storage/emulated/0/exampleBroadcast/offlined367-k9kw-kw89-0uba.flv':
2019-12-18 15:33:16.679 2914-2914/com.example.examplebrodcast I/System.out:   Metadata:
2019-12-18 15:33:16.679 2914-2914/com.example.examplebrodcast I/System.out:     encoder         : 
2019-12-18 15:33:16.679 2914-2914/com.example.examplebrodcast I/System.out: Lavf58.29.100
2019-12-18 15:33:16.679 2914-2914/com.example.examplebrodcast I/System.out:     Stream #0:0
2019-12-18 15:33:16.679 2914-2914/com.example.examplebrodcast I/System.out: , 0, 1/1000
2019-12-18 15:33:16.679 2914-2914/com.example.examplebrodcast I/System.out: : Video: h264 (Constrained Baseline), 1 reference frame ([7][0][0][0] / 0x0007), yuv420p, 1280x720 (0x0), 0/1, q=2-31, 400 kb/s
2019-12-18 15:33:16.679 2914-2914/com.example.examplebrodcast I/System.out: , 
2019-12-18 15:33:16.680 2914-2914/com.example.examplebrodcast I/System.out: 30 fps, 
2019-12-18 15:33:16.680 2914-2914/com.example.examplebrodcast I/System.out: 1k tbn, 
2019-12-18 15:33:16.680 2914-2914/com.example.examplebrodcast I/System.out: 30 tbc
2019-12-18 15:33:16.680 2914-2914/com.example.examplebrodcast I/System.out:     Stream #0:1
2019-12-18 15:33:16.680 2914-2914/com.example.examplebrodcast I/System.out: , 0, 1/1000
2019-12-18 15:33:16.680 2914-2914/com.example.examplebrodcast I/System.out: : Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, mono, fltp, delay 1024, 64 kb/s
2019-12-18 15:33:16.727 2914-3262/com.example.examplebrodcast D/RecordActivity: audioRecord.startRecording()
2019-12-18 15:33:17.010 2914-3262/com.example.examplebrodcast V/RecordActivity: bufferReadResult: 3584
2019-12-18 15:33:17.013 2914-3262/com.example.examplebrodcast I/System.out: [SWR @ 0x770e9b6000] Using s16p internally between filters
2019-12-18 15:33:17.022 2914-3262/com.example.examplebrodcast I/System.out: [SWR @ 0x770e9cf000] Using s16p internally between filters
2019-12-18 15:33:17.089 2914-3262/com.example.examplebrodcast V/RecordActivity: bufferReadResult: 3584
2019-12-18 15:33:17.089 2914-2914/com.example.examplebrodcast I/System.out: detected 8 logical cores
2019-12-18 15:33:17.092 2914-2914/com.example.examplebrodcast I/System.out: [in @ 0x770f454740] Setting 'video_size' to value '864x480'
2019-12-18 15:33:17.092 2914-2914/com.example.examplebrodcast I/System.out: [in @ 0x770f454740] Setting 'pix_fmt' to value '24'
2019-12-18 15:33:17.092 2914-2914/com.example.examplebrodcast I/System.out: [in @ 0x770f454740] Setting 'time_base' to value '1/30'
2019-12-18 15:33:17.093 2914-2914/com.example.examplebrodcast I/System.out: [in @ 0x770f454740] Setting 'pixel_aspect' to value '1/1'
2019-12-18 15:33:17.093 2914-2914/com.example.examplebrodcast I/System.out: [in @ 0x770f454740] w:864 h:480 pixfmt:nv21 tb:1/30 fr:0/1 sar:1/1 sws_param:
2019-12-18 15:33:17.093 2914-2914/com.example.examplebrodcast I/System.out: [setpts @ 0x770f4548c0] Setting 'expr' to value 'N'
2019-12-18 15:33:17.095 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_movie_0 @ 0x770f454b00] Setting 'filename' to value '/storage/emulated/0/exampleBroadcast/score_background.png'
2019-12-18 15:33:17.096 2914-2914/com.example.examplebrodcast I/System.out: [NULL @ 0x7706deec00] Opening '/storage/emulated/0/exampleBroadcast/score_background.png' for reading
2019-12-18 15:33:17.096 2914-2914/com.example.examplebrodcast I/System.out: [file @ 0x770f4aef20] Setting default whitelist 'file,crypto'
2019-12-18 15:33:17.097 2914-2914/com.example.examplebrodcast I/System.out: [png_pipe @ 0x7706deec00] Format png_pipe probed with size=2048 and score=99
2019-12-18 15:33:17.097 2914-2914/com.example.examplebrodcast I/System.out: [png_pipe @ 0x7706deec00] Before avformat_find_stream_info() pos: 0 bytes read:18237 seeks:0 nb_streams:1
2019-12-18 15:33:17.100 2914-2914/com.example.examplebrodcast I/System.out: [png_pipe @ 0x7706deec00] After avformat_find_stream_info() pos: 18237 bytes read:18237 seeks:0 frames:1
2019-12-18 15:33:17.101 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_movie_0 @ 0x770f454b00] seek_point:0 format_name:(null) file_name:/storage/emulated/0/exampleBroadcast/score_background.png stream_index:-1
2019-12-18 15:33:17.101 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] Setting 'x' to value '120'
2019-12-18 15:33:17.101 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_format_2 @ 0x770f454c80] Setting 'pix_fmts' to value 'bgr24'
2019-12-18 15:33:17.101 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] Setting 'fontfile' to value '/system/fonts/DroidSansMono.ttf'
2019-12-18 15:33:17.101 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] Setting 'text' to value '0-0'
2019-12-18 15:33:17.101 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] Setting 'fontsize' to value '30'
2019-12-18 15:33:17.101 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] Setting 'fontcolor' to value 'black'
2019-12-18 15:33:17.102 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] Setting 'x' to value '405'
2019-12-18 15:33:17.102 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] Setting 'y' to value '25'
2019-12-18 15:33:17.107 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] Setting 'fontfile' to value '/system/fonts/DroidSansMono.ttf'
2019-12-18 15:33:17.107 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] Setting 'text' to value 'TEAM 1'
2019-12-18 15:33:17.107 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] Setting 'fontsize' to value '30'
2019-12-18 15:33:17.107 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] Setting 'fontcolor' to value 'white'
2019-12-18 15:33:17.108 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] Setting 'x' to value '190'
2019-12-18 15:33:17.108 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] Setting 'y' to value '25'
2019-12-18 15:33:17.108 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] Setting 'fontfile' to value '/system/fonts/DroidSansMono.ttf'
2019-12-18 15:33:17.108 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] Setting 'text' to value 'TEAM 2'
2019-12-18 15:33:17.108 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] Setting 'fontsize' to value '30'
2019-12-18 15:33:17.109 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] Setting 'fontcolor' to value 'white'
2019-12-18 15:33:17.109 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] Setting 'x' to value '520'
2019-12-18 15:33:17.109 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] Setting 'y' to value '25'
2019-12-18 15:33:17.111 2914-2914/com.example.examplebrodcast I/System.out: [auto_scaler_0 @ 0x770f4551c0] w:iw h:ih flags:'bilinear' interl:0
2019-12-18 15:33:17.111 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_movie_0' and the filter 'Parsed_overlay_1'
2019-12-18 15:33:17.111 2914-2914/com.example.examplebrodcast I/System.out: [auto_scaler_1 @ 0x770f455340] w:iw h:ih flags:'bilinear' interl:0
2019-12-18 15:33:17.111 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_format_2 @ 0x770f454c80] auto-inserting filter 'auto_scaler_1' between the filter 'Parsed_overlay_1' and the filter 'Parsed_format_2'
2019-12-18 15:33:17.111 2914-2914/com.example.examplebrodcast I/System.out: [AVFilterGraph @ 0x770f414b20] query_formats: 9 queried, 6 merged, 2 already done, 0 delayed
2019-12-18 15:33:17.111 2914-2914/com.example.examplebrodcast I/System.out: [in @ 0x770f454740] TB:0.033333 FRAME_RATE:nan SAMPLE_RATE:nan
2019-12-18 15:33:17.112 2914-2914/com.example.examplebrodcast I/System.out: [auto_scaler_0 @ 0x770f4551c0] w:656 h:83 fmt:rgba sar:1/1 -> w:656 h:83 fmt:yuva420p sar:1/1 flags:0x2
2019-12-18 15:33:17.112 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] main w:864 h:480 fmt:nv21 overlay w:656 h:83 fmt:yuva420p
2019-12-18 15:33:17.112 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] [framesync @ 0x771f164ba8] Selected 1/150 time base
2019-12-18 15:33:17.112 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] [framesync @ 0x771f164ba8] Sync level 2
2019-12-18 15:33:17.113 2914-2914/com.example.examplebrodcast I/System.out: [auto_scaler_1 @ 0x770f455340] w:864 h:480 fmt:nv21 sar:1/1 -> w:864 h:480 fmt:bgr24 sar:1/1 flags:0x2
2019-12-18 15:33:17.114 2914-2914/com.example.examplebrodcast W/RecordActivity: Start Button Pushed
2019-12-18 15:33:17.117 2914-2914/com.example.examplebrodcast I/Choreographer: Skipped 257 frames!  The application may be doing too much work on its main thread.
2019-12-18 15:33:17.126 2914-2914/com.example.examplebrodcast V/RecordActivity: Writing Frame
2019-12-18 15:33:17.128 2914-2955/com.example.examplebrodcast I/OpenGLRenderer: Davey! duration=4305ms; Flags=0, IntendedVsync=1448754147017585, Vsync=1448758430350747, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=1448758442736748, AnimationStart=1448758442805758, PerformTraversalsStart=1448758443204040, DrawStart=1448758447760134, SyncQueued=1448758449213936, SyncStart=1448758449481280, IssueDrawCommandsStart=1448758449643884, SwapBuffers=1448758451400551, FrameCompleted=1448758452847843, DequeueBufferDuration=267000, QueueBufferDuration=674000, 
2019-12-18 15:33:17.132 2914-2914/com.example.examplebrodcast I/System.out: [auto_scaler_0 @ 0x770f4551c0] w:656 h:83 fmt:rgba sar:2834/2834 -> w:656 h:83 fmt:yuva420p sar:1/1 flags:0x2
2019-12-18 15:33:17.135 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] n:1.000000 t:0.000000 pos:nan x:120.000000 xi:120 y:0.000000 yi:0
2019-12-18 15:33:17.137 2914-2914/com.example.examplebrodcast I/System.out: [auto_scaler_1 @ 0x770f455340] w:864 h:480 fmt:nv21 sar:0/1 -> w:864 h:480 fmt:bgr24 sar:0/1 flags:0x2
2019-12-18 15:33:17.146 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] n:0 t:0.000000 text_w:54 text_h:21 x:405 y:25
2019-12-18 15:33:17.147 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] n:0 t:0.000000 text_w:108 text_h:21 x:190 y:25
2019-12-18 15:33:17.147 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] n:0 t:0.000000 text_w:108 text_h:21 x:520 y:25
2019-12-18 15:33:17.169 2914-3262/com.example.examplebrodcast V/RecordActivity: bufferReadResult: 3584
2019-12-18 15:33:17.182 2914-2914/com.example.examplebrodcast V/RecordActivity: Writing Frame
2019-12-18 15:33:17.183 2914-2914/com.example.examplebrodcast W/System.err: Warning: [Parsed_movie_0 @ 0x770f454b00] EOF timestamp not reliable
2019-12-18 15:33:17.183 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] n:2.000000 t:0.033333 pos:nan x:120.000000 xi:120 y:0.000000 yi:0
2019-12-18 15:33:17.193 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] n:1 t:0.033333 text_w:54 text_h:21 x:405 y:25
2019-12-18 15:33:17.193 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] n:1 t:0.033333 text_w:108 text_h:21 x:190 y:25
2019-12-18 15:33:17.193 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] n:1 t:0.033333 text_w:108 text_h:21 x:520 y:25
2019-12-18 15:33:17.251 2914-3262/com.example.examplebrodcast V/RecordActivity: bufferReadResult: 3584
2019-12-18 15:33:17.254 2914-2914/com.example.examplebrodcast V/RecordActivity: Writing Frame
2019-12-18 15:33:17.255 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] n:3.000000 t:0.066667 pos:nan x:120.000000 xi:120 y:0.000000 yi:0
2019-12-18 15:33:17.267 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] n:2 t:0.066667 text_w:54 text_h:21 x:405 y:25
2019-12-18 15:33:17.267 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] n:2 t:0.066667 text_w:108 text_h:21 x:190 y:25
2019-12-18 15:33:17.267 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] n:2 t:0.066667 text_w:108 text_h:21 x:520 y:25
2019-12-18 15:33:17.331 2914-3262/com.example.examplebrodcast V/RecordActivity: bufferReadResult: 3584
2019-12-18 15:33:17.339 2914-2914/com.example.examplebrodcast V/RecordActivity: Writing Frame
2019-12-18 15:33:17.341 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] n:4.000000 t:0.100000 pos:nan x:120.000000 xi:120 y:0.000000 yi:0
2019-12-18 15:33:17.355 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] n:3 t:0.100000 text_w:54 text_h:21 x:405 y:25
2019-12-18 15:33:17.355 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] n:3 t:0.100000 text_w:108 text_h:21 x:190 y:25
2019-12-18 15:33:17.356 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] n:3 t:0.100000 text_w:108 text_h:21 x:520 y:25
2019-12-18 15:33:17.411 2914-3262/com.example.examplebrodcast V/RecordActivity: bufferReadResult: 3584
2019-12-18 15:33:17.417 2914-2914/com.example.examplebrodcast V/RecordActivity: Writing Frame
2019-12-18 15:33:17.418 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] n:5.000000 t:0.133333 pos:nan x:120.000000 xi:120 y:0.000000 yi:0
2019-12-18 15:33:17.428 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] n:4 t:0.133333 text_w:54 text_h:21 x:405 y:25
2019-12-18 15:33:17.428 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] n:4 t:0.133333 text_w:108 text_h:21 x:190 y:25
2019-12-18 15:33:17.428 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] n:4 t:0.133333 text_w:108 text_h:21 x:520 y:25
2019-12-18 15:33:17.500 2914-3262/com.example.examplebrodcast V/RecordActivity: bufferReadResult: 3584
2019-12-18 15:33:17.513 2914-2914/com.example.examplebrodcast V/RecordActivity: Writing Frame
2019-12-18 15:33:17.515 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] n:6.000000 t:0.166667 pos:nan x:120.000000 xi:120 y:0.000000 yi:0
2019-12-18 15:33:17.528 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] n:5 t:0.166667 text_w:54 text_h:21 x:405 y:25
2019-12-18 15:33:17.529 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] n:5 t:0.166667 text_w:108 text_h:21 x:190 y:25
2019-12-18 15:33:17.529 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] n:5 t:0.166667 text_w:108 text_h:21 x:520 y:25
2019-12-18 15:33:17.576 2914-2914/com.example.examplebrodcast V/RecordActivity: Writing Frame
2019-12-18 15:33:17.578 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] n:7.000000 t:0.200000 pos:nan x:120.000000 xi:120 y:0.000000 yi:0
2019-12-18 15:33:17.581 2914-3262/com.example.examplebrodcast V/RecordActivity: bufferReadResult: 3584
2019-12-18 15:33:17.589 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] n:6 t:0.200000 text_w:54 text_h:21 x:405 y:25
2019-12-18 15:33:17.589 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] n:6 t:0.200000 text_w:108 text_h:21 x:190 y:25
2019-12-18 15:33:17.590 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] n:6 t:0.200000 text_w:108 text_h:21 x:520 y:25
2019-12-18 15:33:17.654 2914-2914/com.example.examplebrodcast V/RecordActivity: Writing Frame
2019-12-18 15:33:17.655 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] n:8.000000 t:0.233333 pos:nan x:120.000000 xi:120 y:0.000000 yi:0
2019-12-18 15:33:17.660 2914-3262/com.example.examplebrodcast V/RecordActivity: bufferReadResult: 3584
2019-12-18 15:33:17.666 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] n:7 t:0.233333 text_w:54 text_h:21 x:405 y:25
2019-12-18 15:33:17.667 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] n:7 t:0.233333 text_w:108 text_h:21 x:190 y:25
2019-12-18 15:33:17.667 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] n:7 t:0.233333 text_w:108 text_h:21 x:520 y:25
2019-12-18 15:33:17.741 2914-2914/com.example.examplebrodcast V/RecordActivity: Writing Frame
2019-12-18 15:33:17.741 2914-3262/com.example.examplebrodcast V/RecordActivity: bufferReadResult: 3584
2019-12-18 15:33:17.743 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] n:9.000000 t:0.266667 pos:nan x:120.000000 xi:120 y:0.000000 yi:0
2019-12-18 15:33:17.760 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] n:8 t:0.266667 text_w:54 text_h:21 x:405 y:25
2019-12-18 15:33:17.761 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] n:8 t:0.266667 text_w:108 text_h:21 x:190 y:25
2019-12-18 15:33:17.762 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] n:8 t:0.266667 text_w:108 text_h:21 x:520 y:25
2019-12-18 15:33:17.819 2914-2914/com.example.examplebrodcast V/RecordActivity: Writing Frame
2019-12-18 15:33:17.820 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_overlay_1 @ 0x770f454bc0] n:10.000000 t:0.300000 pos:nan x:120.000000 xi:120 y:0.000000 yi:0
2019-12-18 15:33:17.821 2914-3262/com.example.examplebrodcast V/RecordActivity: bufferReadResult: 3584
2019-12-18 15:33:17.833 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_3 @ 0x770f454d40] n:9 t:0.300000 text_w:54 text_h:21 x:405 y:25
2019-12-18 15:33:17.833 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_4 @ 0x770f454ec0] n:9 t:0.300000 text_w:108 text_h:21 x:190 y:25
2019-12-18 15:33:17.833 2914-2914/com.example.examplebrodcast I/System.out: [Parsed_drawtext_5 @ 0x770f455040] n:9 t:0.300000 text_w:108 text_h:21 x:520 y:25
2019-12-18 15:33:17.896 2914-2914/com.example.examplebrodcast V/RecordActivity: Writing Frame

and so on...

question

All 7 comments

You'll probably need to use a thread to smooth out the varying encoding time...

Will try it out in some days and let you know if it works

What exactly should I use a seperate thread for ?
Could you please elaborate
Is it the onPreviewFrame ?
[UPDATE]
Even though the frame rate is 30, onPreviewFrame is being called at a lower rate, 12-15 times per second

Hey, so I used a different thread based on this answer I got on StackOverflow.
But even as I used another ThreadHandler, the video was more laggy. So I went ahead with Hardware Acceleration , which reduced the lagginess, but it's still stutters a little.
However my app crashes sometimes when I try to change the filter, I get errors similiar to this, so I thinks its a thread safty issue.
Will try to fix the thread safey issue and notify if any updates.

Hi again, is there anyways to access Ffmpeg logs in the Java layer?
I want to catch this log :

[flv @ 0x77eedbd800] Delay between the first packet and last packet in the muxing queue is 10033000 > 10000000: forcing output

and execute something when this log appears

Sure, you could implement your own log callback as shown in this class:
https://github.com/bytedeco/javacv/blob/master/src/main/java/org/bytedeco/javacv/FFmpegLogCallback.java

Putting the processing of each frame on a seperate thread + hardware acceleration for the activity + baseline profile reduced the stuttering drastically. It hardly ever occurs now for 480p streaming that has various video overlays.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kongqw picture kongqw  路  4Comments

Maleandr picture Maleandr  路  3Comments

SenudaJayalath picture SenudaJayalath  路  3Comments

newstarbka picture newstarbka  路  5Comments

cansik picture cansik  路  4Comments