使用FFMPEG(C#)从视频中获取特定帧

时间:2018-06-06 11:07:16

标签: c# video ffmpeg frames

我想使用ffmpeg从视频中获取每个指定的帧。 从现在开始我有这个代码:

function Add-ControlVariables {

New-Variable -Name 'Login' -Value $window.FindName('Login') -Scope 1 -Force 
New-Variable -Name 'AvailableSubscriptions' -Value $window.FindName('AvailableSubscriptions') -Scope 1 -Force   
New-Variable -Name 'AvailableResourceGroups' -Value $window.FindName('AvailableResourceGroups') -Scope 1 -Force 
New-Variable -Name 'AvailablLogicApps' -Value $window.FindName('AvailablLogicApps') -Scope 1 -Force
}

function Load-Xaml {
    [xml]$xaml = Get-Content -Path $PSScriptRoot\Azure.xaml
    $manager = New-Object System.Xml.XmlNamespaceManager -ArgumentList $xaml.NameTable
    $manager.AddNamespace("x", "http://schemas.microsoft.com/winfx/2006/xaml");
    $xaml.SelectNodes("//*[@x:Name='Login']", $manager)[0].RemoveAttribute('Click')
    $xaml.SelectNodes("//*[@x:Name='AvailableSubscriptions']", $manager)[0].RemoveAttribute('SelectionChanged')
    $xaml.SelectNodes("//*[@x:Name='AvailableResourceGroups']", $manager)[0].RemoveAttribute('SelectionChanged')
    $xaml.SelectNodes("//*[@x:Name='AvailablLogicApps']", $manager)[0].RemoveAttribute('SelectionChanged')
    $xamlReader = New-Object System.Xml.XmlNodeReader $xaml
    [Windows.Markup.XamlReader]::Load($xamlReader)
}

function Set-EventHandlers {

    $Login.add_Click({
        param([System.Object]$sender,[System.Windows.RoutedEventArgs]$e)
        Login($sender,$e)
        Connect-AzureRmAccount
        $AvailableSubscriptions.ItemsSource = Get-AzureRmSubscription | Select-Object -ExpandProperty Name
    })
    $AvailableSubscriptions.add_SelectionChanged({
        param([System.Object]$sender,[System.Windows.Controls.SelectionChangedEventArgs]$e)
        AvailableSubscriptions_SelectionChanged($sender,$e)
    })
    $AvailableResourceGroups.add_SelectionChanged({
        param([System.Object]$sender,[System.Windows.Controls.SelectionChangedEventArgs]$e)
        $resourceGroupName = $sender.SelectedItem
        $AvailablLogicApps.ItemsSource = Get-AzureRmResource -ResourceType "Microsoft.Logic/workflows" -ResourceGroupName $resourceGroupName | Select-Object -ExpandProperty Name
    })
    $AvailablLogicApps.add_SelectionChanged({
        param([System.Object]$sender,[System.Windows.Controls.SelectionChangedEventArgs]$e)
    })

}
$window = Load-Xaml
Add-ControlVariables
Set-EventHandlers

function AvailableSubscriptions_SelectionChanged
{
    param($sender, $e)
    $subscription = $sender.SelectedItem
    Select-AzureRmSubscription -SubscriptionName $subscription
    $AvailableResourceGroups.ItemsSource = Get-AzureRmResourceGroup | Select-Object -ExpandProperty ResourceGroupName
}

$window.ShowDialog()

它在指定的secounds之间生成帧,但是我想通过它们的数字来获取帧,例如:每3帧,每帧或每10帧。

有没有办法做到这一点?

1 个答案:

答案 0 :(得分:1)

使用

"-i example.mp4 -vf select='not(mod(n,5))' -vsync 0 image%d.bmp"

这将产生每第5帧(0,5,10,15 ......)

(删除了fps过滤器..复制或删除源中的帧)。