Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FromSecond and ToSecond options on ExtractFrames #27

Open
PhilipQuirke opened this issue Oct 10, 2024 · 1 comment
Open

FromSecond and ToSecond options on ExtractFrames #27

PhilipQuirke opened this issue Oct 10, 2024 · 1 comment

Comments

@PhilipQuirke
Copy link

PhilipQuirke commented Oct 10, 2024

The ExtractFrames function pulls all frames for a video. For long videos this is slow. Also for my application the ability to pull selected portions of the video is necessary.

FFMPeg supports efficient from/to second selection

I'd like the existing function ExtractFrames to support optional FromSecond / ToSecond parameters

@PhilipQuirke
Copy link
Author

PhilipQuirke commented Oct 10, 2024

The existing code can be updated as follows (assuming new int _videoSettings.FromSecond and _videoSettings.ToSecond params):

    /// <summary>
    /// Execute command to extract all/some frames from video
    /// </summary>
    private void ExtractFrames()
    {
        var (w, h) = (_videoSettings.Width, _videoSettings.Height);

        var vfOptions = string.Empty;

        // Check if the time range is specified
        if ((_videoSettings.FromSecond > 0) && (_videoSettings.ToSecond > 0))
        {
            // Add the (optional) time selection range using -ss (seek) and -t (duration)
            var duration = Math.Max( 1, _videoSettings.ToSecond - _videoSettings.FromSecond + 1 ); // Minimum duration is 1 second
            vfOptions = $"-ss {_videoSettings.FromSecond.ToString(CultureInfo.InvariantCulture)} -t {duration.ToString(CultureInfo.InvariantCulture)}";
        }

        vfOptions += $" -vf fps={FormatedFps},scale={w}:{h}";

        Execute($@"-i ""{_videoSettings.VideoFile}"" -vsync vfr {vfOptions} ""{Path.Combine(_videoSettings.TempFolder, $"%d.{FRAME_FORMAT}")}""");
    }

@PhilipQuirke PhilipQuirke changed the title FromFrame and ToFrame options on ExtractFrames FromSecond and ToSecond options on ExtractFrames Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant