#9199 closed defect (duplicate)

While making an MKV/FLAC/ALSA screencast, FFMPEG cuts off the last 15 s of audio

Reported by: Neven Sajko Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords:
Cc: Neven Sajko Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description (last modified by Neven Sajko)

This may be a duplicate of https://trac.ffmpeg.org/ticket/4703

Note: the ffreport.log is attached

Summary of the bug

What I was trying to accomplish

This is on a Linux machine with Alsa and X11. I was making screencasts in the MKV container with FLAC audio.

The problem I encountered

The MKV file that FFMPEG outputs doesn't contain the last 15 seconds of audio. I.e., the audio is just replaced by silence after some point. I didn't analyze the output file in any way, except playing it with ffplay.

Another interesting thing is that if I record a screencast with a duration of just circa 5 seconds (so, the audio is just silence), ffplay just says "nan" in the place in its output on the terminal where there is usually a timestamp in the format SSS.CC.

What's the workaround

The workaround is to record for an extra 15 seconds, and then cut the extra video at the end.

How to reproduce

g=1920x1080
fr=4
d=$DISPLAY

audioCaptureDevice=hw:0
audioSampleFormat=pcm_s32le
audioNumChannels=2
audioRate=44100

f=/tmp/output.mkv

ffmpeg  -probesize 50M  -f x11grab -video_size "$g" -framerate "$fr" -i "$d"                    \
       -thread_queue_size 8192 -f alsa -channels "$audioNumChannels" -sample_rate "$audioRate" \
       -c:a "$audioSampleFormat" -ar "$audioRate" -i "$audioCaptureDevice"                     \
       -c:a flac -c:v libx264 -crf 17          "$f"

ffmpeg stdout/stderr:

ffmpeg started on 2021-04-24 at 19:56:38
Report written to "/tmp/ffreport.log"
Log level: 48
ffmpeg version N-102027-ge448a4b4ea Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.2.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librav1e --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-shared --enable-version3
  libavutil      56. 74.100 / 56. 74.100
  libavcodec     58.136.101 / 58.136.101
  libavformat    58. 78.100 / 58. 78.100
  libavdevice    58. 14.100 / 58. 14.100
  libavfilter     7.111.100 /  7.111.100
  libswscale      5. 10.100 /  5. 10.100
  libswresample   3. 10.100 /  3. 10.100
  libpostproc    55. 10.100 / 55. 10.100
Input #0, x11grab, from ':0':
  Duration: N/A, start: 1619294198.400763, bitrate: 265420 kb/s
  Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1920x1080, 265420 kb/s, 4 fps, 4 tbr, 1000k tbn, 1000k tbc
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, alsa, from 'hw:0':
  Duration: N/A, start: 1619294200.086137, bitrate: 2822 kb/s
  Stream #1:0: Audio: pcm_s32le, 44100 Hz, stereo, s32, 2822 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
  Stream #1:0 -> #0:1 (pcm_s32le (native) -> flac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x55b4c33b75c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x55b4c33b75c0] profile High 4:4:4 Predictive, level 4.0, 4:4:4, 8-bit
[libx264 @ 0x55b4c33b75c0] 264 - core 161 r3039 544c61f - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - 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=4 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=4 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=17.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[flac @ 0x55b4c33b9300] encoding as 24 bits-per-sample
Output #0, matroska, to '/tmp/output.mkv':
  Metadata:
    encoder         : Lavf58.78.100
  Stream #0:0: Video: h264 (H264 / 0x34363248), yuv444p(tv, progressive), 1920x1080, q=2-31, 4 fps, 1k tbn
    Metadata:
      encoder         : Lavc58.136.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
  Stream #0:1: Audio: flac ([172][241][0][0] / 0xF1AC), 44100 Hz, stereo, s32 (24 bit), 128 kb/s
    Metadata:
      encoder         : Lavc58.136.101 flac
frame=   32 fps=4.8 q=-1.0 Lsize=     266kB time=00:00:07.25 bitrate= 300.3kbits/s speed=1.09x
video:265kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.416215%
[libx264 @ 0x55b4c33b75c0] frame I:2     Avg QP: 5.68  size:133587
[libx264 @ 0x55b4c33b75c0] frame P:8     Avg QP:13.19  size:   170
[libx264 @ 0x55b4c33b75c0] frame B:22    Avg QP:19.36  size:    81
[libx264 @ 0x55b4c33b75c0] consecutive B-frames:  6.2%  6.2%  0.0% 87.5%
[libx264 @ 0x55b4c33b75c0] mb I  I16..4: 45.3% 39.3% 15.4%
[libx264 @ 0x55b4c33b75c0] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  0.1%  0.0%  0.0%  0.0%  0.0%    skip:99.9%
[libx264 @ 0x55b4c33b75c0] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.1%  0.0%  0.0%  direct: 0.0%  skip:99.9%  L0:36.5% L1:61.4% BI: 2.1%
[libx264 @ 0x55b4c33b75c0] 8x8 transform intra:39.3% inter:6.9%
[libx264 @ 0x55b4c33b75c0] coded y,u,v intra: 10.8% 0.6% 0.6% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x55b4c33b75c0] i16 v,h,dc,p: 82% 17%  0%  0%
[libx264 @ 0x55b4c33b75c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 89%  5%  6%  0%  0%  0%  0%  0%  0%
[libx264 @ 0x55b4c33b75c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 32% 41% 11%  1%  2%  1%  5%  1%  6%
[libx264 @ 0x55b4c33b75c0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x55b4c33b75c0] ref P L0: 70.7%  0.0% 17.6% 11.7%
[libx264 @ 0x55b4c33b75c0] ref B L0: 71.3% 16.7% 12.0%
[libx264 @ 0x55b4c33b75c0] ref B L1: 96.7%  3.3%
[libx264 @ 0x55b4c33b75c0] kb/s:270.33

Attachments (1)

ffreport.log (282.2 KB ) - added by Neven Sajko 16 months ago.

Download all attachments as: .zip

Change History (4)

by Neven Sajko, 16 months ago

Attachment: ffreport.log added

comment:1 by Neven Sajko, 16 months ago

Description: modified (diff)

comment:2 by Neven Sajko, 16 months ago

Description: modified (diff)

comment:3 by Carl Eugen Hoyos, 16 months ago

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.