ffmpegdirectshow

ffmpeg unexpected exit code 1 for -list_devices and -list_options


Description

If I run any of the following commands from the examples in the documentation, using ffmpeg 4.2.2 on Windows 10, the requested information is successfully displayed in the console, but the process exits with exit code 1, instead of the expected 0 (success).

ffmpeg -list_devices true -f dshow -i dummy

ffmpeg -list_options true -f dshow -i video="MyCamera"

As far as I know, exit code 1 on Windows implies "Incorrect function", so I consider this behavior to be unexpected.

If I stream camera input to disk, using e.g. ffmpeg -f dshow -i video="MyCamera" "myfile.mp4", then stop using q, the exit code is 0, as expected.

Question

Does the exit code 1 constitute normal behavior for ffmpeg, or am I doing something wrong?

Relevance

When running the commands manually, from the command line, the exit code does not make much difference, as long as the requested information is displayed.

However, when running the commands programmatically, it may cause trouble. For example, using Python's subprocess.run(..., check=True), the nonzero exit code causes a CalledProcessError.

Of course there are ways around this, e.g. use check=False, but the point is that a workaround would not be necessary if ffmpeg behaved as expected, i.e. returned 0.


Solution

  • Exit code 1 while listing devices with dshow is the expected output since the code goes for an immediate exit in this case by using AVERROR_EXIT and no media output is produced.

    if (ctx->list_devices) {
        av_log(avctx, AV_LOG_INFO, "DirectShow video devices (some may be both video and audio devices)\n");
        dshow_cycle_devices(avctx, devenum, VideoDevice, VideoSourceDevice, NULL, NULL);
        av_log(avctx, AV_LOG_INFO, "DirectShow audio devices\n");
        dshow_cycle_devices(avctx, devenum, AudioDevice, AudioSourceDevice, NULL, NULL);
        ret = AVERROR_EXIT;
        goto error;
    }
    

    You should see a dummy: Immediate exit requested in the logs.

    You can of course easily modify libavdevice/dshow.c and make a clean exit instead but you will have to compile your own version.