Opened 8 months ago

Closed 8 months ago

Last modified 8 months ago

#6331 closed defect (invalid)

FFmpeg command exits before processing is complete

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

Description

I'm running the following FFmpeg command in a C# process like so:

var origFilePath = "C:/input.webm";
var processedFilePath = "C:/output.webm";

RunFfmpeg($"-i \"{origFilePath}\" -af \"silenceremove=1:0.1:0.001, areverse, silenceremove=1:0.1:0.001, areverse\" \"{processedFilePath}\" -y");

// fails with IOException as the file has presumably not been released by FFmpeg
System.IO.File.Delete(origFilePath);

For completeness, the RunFfmpeg command looks like this:

private List<string> RunFfmpeg(string arguments)
{
    using (var process = new Process())
    {
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardError = true;
        process.StartInfo.FileName = _hostingEnvironment.ContentRootPath + _settings.FfmpegPath;
        process.StartInfo.Arguments = arguments;
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.CreateNoWindow = true;

        // ffmpeg only uses strerr for its output
        var output = new List<string>();
        process.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { 
            if (e.Data != null)
                output.Add(e.Data);
        });

        process.Start();
        process.BeginErrorReadLine();
        process.WaitForExit();
        return output;
    }
}

As you can see the process is supposed to wait till the command exits and then deletes the input file given to FFmpeg. Unfortunately about 20% of the time, deleting that file fails as it appear FFmpeg is still processing the input file or has otherwise not released it.

I've posted a question about this here on StackOverflow, hoping that there was something silly I was doing, however it seems that this is seen as acceptable behaviour?

I would argue that a process should only exit when all processing has been complete and any relevant files, both input and output, are no longer being used by said process.

Here is an the uncut console output of the same command:

ffmpeg -v 9 -loglevel 99 -i input.webm -af "silenceremove=1:0.1:0.001, areverse, silenceremove=1:0.1:0.001, areverse" output.webm
ffmpeg version N-83882-g58f0bbc Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.9.4 (GCC)
  configuration: --arch=x86_64 --target-os=mingw32 --cross-prefix=/cygdrive/d/Users/Andrew/Documents/GitHub/ffmpeg-windows-build-helpers/native_build/windows/ffmpeg_local_builds/sandbox/cross_compilers/mingw-w64-x86_64/bin/x86_64-w64-mingw32- --pkg-config=pkg-config --disable-w32threads --enable-libsoxr --enable-fontconfig --enable-libass --enable-libbluray --enable-iconv --enable-libtwolame --extra-cflags=-DLIBTWOLAME_STATIC --enable-libzvbi --enable-libcaca --enable-libmodplug --extra-libs=-lstdc++ --extra-libs=-lpng --enable-decklink --extra-libs=-loleaut32 --enable-libmp3lame --enable-version3 --enable-zlib --enable-librtmp --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libopenjpeg --enable-gnutls --enable-libgsm --enable-libfreetype --enable-libopus --enable-bzlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-libschroedinger --enable-libvpx --enable-libilbc --enable-libwavpack --enable-libwebp --enable-libgme --enable-dxva2 --enable-avisynth --enable-gray --enable-libopenh264 --enable-netcdf --enable-libflite --enable-lzma --enable-libsnappy --enable-libzimg --enable-gpl --enable-libx264 --enable-libx265 --enable-frei0r --enable-filter=frei0r --enable-librubberband --enable-libvidstab --enable-libxavs --enable-libxvid --enable-libmfx --enable-avresample --extra-libs=-lpsapi --extra-libs=-lspeexdsp --extra-cflags='-mtune=core2' --extra-cflags=-O3 --enable-static --disable-shared --prefix=/cygdrive/d/Users/Andrew/Documents/GitHub/ffmpeg-windows-build-helpers/native_build/windows/ffmpeg_local_builds/sandbox/cross_compilers/mingw-w64-x86_64/x86_64-w64-mingw32 --enable-runtime-cpudetect
  libavutil      55. 48.100 / 55. 48.100
  libavcodec     57. 83.100 / 57. 83.100
  libavformat    57. 66.104 / 57. 66.104
  libavdevice    57.  3.100 / 57.  3.100
  libavfilter     6. 76.100 /  6. 76.100
  libavresample   3.  2.  0 /  3.  2.  0
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with argument '9'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument '99'.
Reading option '-i' ... matched as input url with argument 'input.webm'.
Reading option '-af' ... matched as option 'af' (set audio filters) with argument 'silenceremove=1:0.1:0.001, areverse, silenceremove=1:0.1:0.001, areverse'.
Reading option 'output.webm' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument 9.
Successfully parsed a group of options.
Parsing a group of options: input url input.webm.
Successfully parsed a group of options.
Opening an input file: input.webm.
[file @ 000001dce8d45180] Setting default whitelist 'file,crypto'
Probing matroska,webm score:100 size:2048
Probing mp3 score:1 size:2048
[matroska,webm @ 000001dce8d488a0] Format matroska,webm probed with size=2048 and score=100
st:0 removing common factor 1000000 from timebase
[matroska,webm @ 000001dce8d488a0] Before avformat_find_stream_info() pos: 146 bytes read:15842 seeks:0 nb_streams:1
[matroska,webm @ 000001dce8d488a0] All info found
[matroska,webm @ 000001dce8d488a0] stream 0: start_time: 0.000 duration: -9223372036854776.000
[matroska,webm @ 000001dce8d488a0] format: start_time: 0.000 duration: -9223372036854.775 bitrate=0 kb/s
[matroska,webm @ 000001dce8d488a0] After avformat_find_stream_info() pos: 678 bytes read:15842 seeks:0 frames:1
Input #0, matroska,webm, from 'input.webm':
  Metadata:
    encoder         : Chrome
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0(eng), 1, 1/1000: Audio: opus, 48000 Hz, mono, fltp (default)
Successfully opened the file.
Parsing a group of options: output url output.webm.
Applying option af (set audio filters) with argument silenceremove=1:0.1:0.001, areverse, silenceremove=1:0.1:0.001, areverse.
Successfully parsed a group of options.
Opening an output file: output.webm.
File 'output.webm' already exists. Overwrite ? [y/N] y
[file @ 000001dce8d45e00] Setting default whitelist 'file,crypto'
Successfully opened the file.
Stream mapping:
  Stream #0:0 -> #0:0 (opus (native) -> opus (libopus))
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
detected 4 logical cores
[Parsed_silenceremove_0 @ 000001dce8d9fc20] Setting 'start_periods' to value '1'
[Parsed_silenceremove_0 @ 000001dce8d9fc20] Setting 'start_duration' to value '0.1'
[Parsed_silenceremove_0 @ 000001dce8d9fc20] Setting 'start_threshold' to value '0.001'
[Parsed_silenceremove_2 @ 000001dce8da1b80] Setting 'start_periods' to value '1'
[Parsed_silenceremove_2 @ 000001dce8da1b80] Setting 'start_duration' to value '0.1'
[Parsed_silenceremove_2 @ 000001dce8da1b80] Setting 'start_threshold' to value '0.001'
[graph_0_in_0_0 @ 000001dce8da4040] Setting 'time_base' to value '1/48000'
[graph_0_in_0_0 @ 000001dce8da4040] Setting 'sample_rate' to value '48000'
[graph_0_in_0_0 @ 000001dce8da4040] Setting 'sample_fmt' to value 'fltp'
[graph_0_in_0_0 @ 000001dce8da4040] Setting 'channel_layout' to value '0x4'
[graph_0_in_0_0 @ 000001dce8da4040] tb:1/48000 samplefmt:fltp samplerate:48000 chlayout:0x4
[format_out_0_0 @ 000001dce8da55e0] Setting 'sample_fmts' to value 's16|flt'
[format_out_0_0 @ 000001dce8da55e0] Setting 'sample_rates' to value '48000|24000|16000|12000|8000'
[Parsed_silenceremove_0 @ 000001dce8d9fc20] auto-inserting filter 'auto_resampler_0' between the filter 'graph_0_in_0_0' and the filter 'Parsed_silenceremove_0'
[Parsed_areverse_1 @ 000001dce8da02c0] auto-inserting filter 'auto_resampler_1' between the filter 'Parsed_silenceremove_0' and the filter 'Parsed_areverse_1'
[Parsed_silenceremove_2 @ 000001dce8da1b80] auto-inserting filter 'auto_resampler_2' between the filter 'Parsed_areverse_1' and the filter 'Parsed_silenceremove_2'
[Parsed_areverse_3 @ 000001dce8da2840] auto-inserting filter 'auto_resampler_3' between the filter 'Parsed_silenceremove_2' and the filter 'Parsed_areverse_3'
[format_out_0_0 @ 000001dce8da55e0] auto-inserting filter 'auto_resampler_4' between the filter 'Parsed_areverse_3' and the filter 'format_out_0_0'
[AVFilterGraph @ 000001dce8d8e520] query_formats: 7 queried, 3 merged, 15 already done, 0 delayed
[auto_resampler_1 @ 000001dce8dbcb60] picking s64p out of 6 ref:dbl
[auto_resampler_3 @ 000001dce8de8040] picking s64p out of 6 ref:dbl
[auto_resampler_4 @ 000001dce8dfd2e0] picking flt out of 2 ref:s64p
[auto_resampler_0 @ 000001dce8da77e0] [SWR @ 000001dce8da7a20] Using fltp internally between filters
[auto_resampler_0 @ 000001dce8da77e0] ch:1 chl:mono fmt:fltp r:48000Hz -> ch:1 chl:mono fmt:dbl r:48000Hz
[auto_resampler_1 @ 000001dce8dbcb60] [SWR @ 000001dce8dbdcc0] Using dblp internally between filters
[auto_resampler_1 @ 000001dce8dbcb60] ch:1 chl:mono fmt:dbl r:48000Hz -> ch:1 chl:mono fmt:s64p r:48000Hz
[auto_resampler_2 @ 000001dce8dd2e20] [SWR @ 000001dce8dd2ee0] Using dblp internally between filters
[auto_resampler_2 @ 000001dce8dd2e20] ch:1 chl:mono fmt:s64p r:48000Hz -> ch:1 chl:mono fmt:dbl r:48000Hz
[auto_resampler_3 @ 000001dce8de8040] [SWR @ 000001dce8de81a0] Using dblp internally between filters
[auto_resampler_3 @ 000001dce8de8040] ch:1 chl:mono fmt:dbl r:48000Hz -> ch:1 chl:mono fmt:s64p r:48000Hz
[auto_resampler_4 @ 000001dce8dfd2e0] [SWR @ 000001dce8dfd440] Using dblp internally between filters
[auto_resampler_4 @ 000001dce8dfd2e0] ch:1 chl:mono fmt:s64p r:48000Hz -> ch:1 chl:mono fmt:flt r:48000Hz
[libopus @ 000001dce8d4d160] No bit rate set. Defaulting to 64000 bps.
Output #0, webm, to 'output.webm':
  Metadata:
    encoder         : Lavf57.66.104
    Stream #0:0(eng), 0, 1/1000: Audio: opus (libopus), 48000 Hz, mono, flt, delay 312, 64 kb/s (default)
    Metadata:
      encoder         : Lavc57.83.100 libopus
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 40 times
[webm @ 000001dce8d4b600] get_metadata_duration returned: 0
[webm @ 000001dce8d4b600] Writing block at offset 3, size 298, pts 0, dts 0, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 308, size 279, pts 21, dts 21, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 594, size 184, pts 41, dts 41, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 785, size 221, pts 61, dts 61, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 1013, size 211, pts 81, dts 81, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 1231, size 121, pts 101, dts 101, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 1358, size 293, pts 121, dts 121, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 1658, size 180, pts 141, dts 141, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 1845, size 138, pts 161, dts 161, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 1990, size 128, pts 181, dts 181, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 2125, size 128, pts 201, dts 201, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 2260, size 160, pts 221, dts 221, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 2427, size 175, pts 241, dts 241, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 2609, size 173, pts 261, dts 261, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 2789, size 178, pts 281, dts 281, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 2974, size 253, pts 301, dts 301, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 3234, size 176, pts 321, dts 321, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 3417, size 167, pts 341, dts 341, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 3591, size 223, pts 361, dts 361, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 3821, size 280, pts 381, dts 381, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 4108, size 182, pts 401, dts 401, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 4297, size 132, pts 421, dts 421, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 4436, size 132, pts 441, dts 441, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 4575, size 132, pts 461, dts 461, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 4714, size 316, pts 481, dts 481, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 5037, size 135, pts 501, dts 501, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 5179, size 131, pts 521, dts 521, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 5317, size 150, pts 541, dts 541, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 5474, size 294, pts 561, dts 561, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 5775, size 129, pts 581, dts 581, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 5911, size 195, pts 601, dts 601, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 6113, size 146, pts 621, dts 621, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 6266, size 165, pts 641, dts 641, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 6438, size 158, pts 661, dts 661, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 6603, size 150, pts 681, dts 681, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 6760, size 179, pts 701, dts 701, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 6946, size 145, pts 721, dts 721, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 7098, size 169, pts 741, dts 741, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 7274, size 130, pts 761, dts 761, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 7411, size 138, pts 781, dts 781, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 7556, size 134, pts 801, dts 801, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 7697, size 126, pts 821, dts 821, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 7830, size 131, pts 841, dts 841, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 7968, size 133, pts 861, dts 861, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 8108, size 123, pts 881, dts 881, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 8238, size 125, pts 901, dts 901, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 8370, size 127, pts 921, dts 921, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 8504, size 127, pts 941, dts 941, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 8638, size 236, pts 961, dts 961, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 8881, size 113, pts 981, dts 981, duration 20, keyframe 1
[webm @ 000001dce8d4b600] Writing block at offset 9000, size 287, pts 1001, dts 1001, duration 20, keyframe 1
[libopus @ 000001dce8d4d160] Trying to remove 343 more samples than there are in the queue
[webm @ 000001dce8d4b600] Writing block at offset 9294, size 124, pts 1021, dts 1021, duration 20, keyframe 1
No more output streams to write to, finishing.
[webm @ 000001dce8d4b600] Writing block at offset 9425, size 236, pts 1041, dts 1041, duration 13, keyframe 1
[webm @ 000001dce8d4b600] end duration = 1054
size=      10kB time=00:00:01.05 bitrate=  77.0kbits/s speed=4.82x
video:0kB audio:9kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 9.197504%
Input file #0 (input.webm):
  Input stream #0:0 (audio): 40 packets read (15405 bytes); 40 frames decoded (115200 samples);
  Total: 40 packets (15405 bytes) demuxed
Output file #0 (output.webm):
  Output stream #0:0 (audio): 53 frames encoded (50225 samples); 53 packets muxed (9296 bytes);
  Total: 53 packets (9296 bytes) muxed
40 frames successfully decoded, 0 decoding errors
[AVIOContext @ 000001dce8d4db80] Statistics: 15 seeks, 12 writeouts
[AVIOContext @ 000001dce8d51960] Statistics: 15842 bytes read, 0 seeks

Attachments (1)

input.webm (15.5 KB) - added by ajbeaven 8 months ago.

Download all attachments as: .zip

Change History (7)

Changed 8 months ago by ajbeaven

comment:1 Changed 8 months ago by heleppkes

When a process exists, it by definition is done processing. It cannot do any further processing after it exists, so I'm not sure your reasoning is all that logical.

comment:2 follow-up: Changed 8 months ago by ajbeaven

Sure my reasoning may not be correct, but irregardless there seems to be a problem. I occasionally cannot delete the file immediately after running a command in FFmpeg.

comment:3 in reply to: ↑ 2 Changed 8 months ago by ajbeaven

Replying to ajbeaven:

Sure my reasoning may not be correct, but irregardless there seems to be a problem. I occasionally cannot delete the file immediately after running a command in FFmpeg.

I suppose of course, the problem could lie with the C# Process object.

comment:4 Changed 8 months ago by cehoyos

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

This does not look like a valid ticket.

comment:5 Changed 8 months ago by ajbeaven

Sorry, is this invalid because you cannot reproduce? Or because you assume it's a problem with C#?

comment:6 Changed 8 months ago by cehoyos

It is invalid because your reasoning makes no sense: No process can continue "processing" or use any files after exit.

Note: See TracTickets for help on using tickets.