Xabe.FFmpeg icon indicating copy to clipboard operation
Xabe.FFmpeg copied to clipboard

Image to video conversion leaves temporary files

Open eric649 opened this issue 4 years ago • 3 comments

When I convert jpeg images to videos, a subdirectory is created with a copy of the source images. This directory isn't removed when processing is complete. For example, one run created a folder C:\Users\User\AppData\Local\Temp\704d7805-ffd3-4484-97f3-68b87be20322\ which contains sequentially named images from "img_001.jpg" through "img_100.jpg" Is there a method that needs to be called to delete these files? I've looked over the code but I can't find one.

-- the code: -- await FFmpeg.Conversions.New() .BuildVideoFromImages(imageFilenames) .SetFrameRate(15) .SetOverwriteOutput(true) .SetOutputFormat(Format.mp4) .SetVideoBitrate(2600000) .SetPixelFormat(PixelFormat.yuv420p) .SetOutput(outputPath).Start();

eric649 avatar Feb 16 '21 16:02 eric649

Hi, Right now you cannot do anything with that but that would be a nice thing to clean up these files. Added to TODO list.

tomaszzmuda avatar Feb 17 '21 21:02 tomaszzmuda

Ok. I am using a workaround where the code looks for new folders with images in the temp directory after processing and deletes them.

eric649 avatar Feb 18 '21 16:02 eric649

Hi, it work

        /// <summary>
        /// Auto Delete Temp Images (by zh3305)
        /// </summary>
        /// <param name="conversion"></param>
        /// <param name="imageFiles"></param>
        /// <returns></returns>
        public static IConversion BuildVideoFromImagesDelTemp(this Xabe.FFmpeg.IConversion conversion, IEnumerable<string> imageFiles)
        {
            var builder = new InputBuilder();
            conversion.BuildVideoFromImages(0, builder.PrepareInputFiles(imageFiles.ToList(), out var tempDirectory));
            conversion.OnProgress += async (sender, args) =>
            {
                if (args.Percent==100)
                {
                    Directory.Delete(tempDirectory, true);
                }
            };

            return conversion;
        }

zh3305 avatar Apr 13 '22 10:04 zh3305