Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#6336 closed defect (invalid)

No Way to Cleanly Terminate ffmpeg.exe while capturing screen

Reported by: dbareis Owned by:
Priority: normal Component: ffmpeg
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

This is on Windows 7/10 64 bit (but would at least be the same on all Windows computers), using this command line:

ffmpeg -y -f gdigrab -i desktop -r 10 -vcodec libx264 -pix_fmt yuv420p 10fps.mp4

You can manually terminate the program with CTRL+BREAK which is better than nothing but if you use the command (in a batch/automated process):

TaskKill /im ffmpeg.exe /F

then the result is an unusable and corrupted video.

The program already handles CTRL+BREAK, it should probably be simple to enhance this for the sigterm signal. But it would be nice to be able to cleanly do this with something like:

ffmpeg.exe /STOP 

or perhaps:

ffmpeg.exe /STOP [AliasDefinedOnExistingCommandLineToAllowSpecificTaskTermination]

Change History (15)

comment:1 Changed 5 months ago by cehoyos

  • Component changed from undetermined to ffmpeg
  • Keywords ffmpeg terminate close automate batch removed
  • Type changed from enhancement to defect

What's wrong with pressing "q"?
Please provide the complete, uncut console output for the case when you get an "unusable and corrupted video" to make this a valid ticket.

comment:2 Changed 5 months ago by dbareis

The main point is I'm trying to AUTOMATE the task (no user interaction) with the "ffmpeg.exe" task or its window.

The console output follows:

ffmpeg\bin> ffmpeg -y -f gdigrab -i desktop -r 10 -vcodec libx264 -pix_fmt yuv420p  -metadata "title=AIR Recording on CN-DENNIS-MBOX by CN-DENNIS-MBOX\Dennis @ Fri 21/04/2017 17:25:45.89"  -metadata "genre=AIR TRIAGE CAPTURE" -metadata "composer=AIR TRIAGE PROGRAM v99.111 by DENNIS BAREIS" -metadata "album=AIR TRIAGE PROGRAM v99.111 by DENNIS BAREIS" -metadata "author=CN-DENNIS-MBOX\Dennis on CN-DENNIS-MBOX" -metadata "album_artist=CN-DENNIS-MBOX\Dennis on CN-DENNIS-MBOX" -metadata "comment=User comment that was entered into a dialog"  10fps.mp4
ffmpeg version N-85469-gf1d80bc Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
  libavutil      55. 61.100 / 55. 61.100
  libavcodec     57. 92.100 / 57. 92.100
  libavformat    57. 72.100 / 57. 72.100
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 84.101 /  6. 84.101
  libswscale      4.  7.100 /  4.  7.100
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
[gdigrab @ 037c0f80] Capturing whole desktop as 3840x1080x32 at (-1920,0)
[gdigrab @ 037c0f80] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, gdigrab, from 'desktop':
  Duration: N/A, start: 1492759547.171207, bitrate: 3977347 kb/s
    Stream #0:0: Video: bmp, bgra, 3840x1080, 3977347 kb/s, 29.97 fps, 1000k tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (bmp (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 03671220] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 03671220] profile High, level 5.0
[libx264 @ 03671220] 264 - core 148 r2762 90a61ec - 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 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=10 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 '10fps.mp4':
  Metadata:
    title           : AIR Recording on CN-DENNIS-MBOX by CN-DENNIS-MBOX\Dennis @ Fri 21/04/2017 17:25:45.89
    genre           : yyy
    composer        : xxx
    album           : zzz
    author          : aaa
    album_artist    : bbb
    comment         : ccc
    encoder         : Lavf57.72.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 3840x1080, q=-1--1, 10 fps, 10240 tbn, 10 tbc
    Metadata:
      encoder         : Lavc57.92.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=    8 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   14 fps= 13 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A dup=0 droframe=   19 fps= 12 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A dup=0 droframe=   25 fps= 11 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A dup=0 droframe=   30 fps= 11 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A dup=0 droframe=   35 fps= 11 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A dup=0 droframe=   41 fps= 11 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A dup=0 droframe=   46 fps= 11 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A dup=0 drop=18 speed=   0x
ffmpeg\bin>

As you'd expect nothing to see...

comment:3 Changed 5 months ago by heleppkes

Sending a "q" character to your running ffmpeg through some script is definitely not impossible, so you could investigate that solution.

Otherwise, encoding into a streaming container like mpegts would also allow the process to be hard-interrupted without leaving a broken file. mp4 does not work like that, as you found out the hard way.

comment:4 Changed 5 months ago by cehoyos

I wonder why TaskKill doesn't work: Does it possibly never work for programs running in a cmd window?

comment:5 Changed 5 months ago by heleppkes

TaskKill? works, but he forced a forcefull shutdown (like a SIGKILL), so it doesn't "finish" the file and write the MP4 header (which is at the end of the file for MP4, hence using somehting like mpegts would likely yield a usable file).

Last edited 5 months ago by heleppkes (previous) (diff)

comment:6 Changed 5 months ago by cehoyos

Why doesn't TaskKill /im ffmpeg.exe work?

comment:7 Changed 5 months ago by Cigaes

Why do you not send the correct signal to ffmpeg? The point of having different signals is to cause different kinds of termination. If all signals are handled the same way, it serves no purpose.

comment:8 Changed 5 months ago by dbareis

TaskKill? returned a message saying I needed "/F" and after waiting a while, the processed wasn't terminating. I know sending "Q" to the processes is not impossible, just not easy or reliable and a major hack to workaround a deficiency in the app which should be corrected.

comment:9 Changed 5 months ago by dbareis

ffmpeg\bin> taskkill /im ffmpeg.exe
ERROR: The process "ffmpeg.exe" with PID 10808 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).

If my command line can be altered to not corrupt the file, I can live with that, what is the new command line? I tried adding "-f mpegts" from a google but that made no difference and neither did replacing "gdigrab".

comment:10 Changed 5 months ago by Cigaes

On Unix systems, that would be kill -INT, but kill would work just as well. This is an OS question rather than a ffmpeg question.

comment:11 Changed 5 months ago by heleppkes

The non-forced method of TaskKill? doesn't work for console applications, it only works for UI applications which receive window messages.

The only way to cleanly close a running ffmpeg instance on Windows is to actually interact with it, send it "q", Ctrl+C or Ctrl+Break

comment:12 Changed 5 months ago by cehoyos

  • Resolution set to invalid
  • Status changed from new to closed

Thank you for the explanation!

comment:13 Changed 5 months ago by dbareis

I'm disappointed but not that surprised that the app won't be enhanced, this is definitely not an OS question as it's not possible to terminate the application cleanly on Windows and the fact that you can do so (relatively) cleanly on Unix is irrelevant.

As part of the bug report I was required to supply a command line, its a pity that the same requirement isn't required for responders. Eventually I may work out the "mpegts/mp4" comment meant...

comment:14 Changed 5 months ago by richardpl

What way would you prefer to close ffmpeg?

comment:15 Changed 5 months ago by dbareis

I'd like it to work as per my suggestion in the description of this enhancement request.

Note: See TracTickets for help on using tickets.