简体   繁体   English

如何使用 Windows 脚本设置手刹默认预设

[英]How to set Handbrake default preset using Windows script

Hello and thanks for reading.您好,感谢您的阅读。

So I'm using Handbrake (video encoding) GUI version (not the CLI version).所以我使用的是 Handbrake(视频编码)GUI 版本(不是 CLI 版本)。

I have a script that configures the settings for the GUI version.我有一个配置 GUI 版本设置的脚本。 But I want to specify the default preset.但我想指定默认预设。 Unfortunately, the default preset is not in the settings.json file.不幸的是,默认预设不在 settings.json 文件中。

The default preset is stored in the presets.json file.默认预设存储在 presets.json 文件中。

The presets.json file contains all the presets (such as Very Fast 1080p30 and Fast 720p30, etc). presets.json 文件包含所有预设(例如非常快 1080p30 和快速 720p30 等)。 I want to set Fast 720p30 as the default preset.我想将 Fast 720p30 设置为默认预设。

So I can find this in presets.json:所以我可以在 presets.json 中找到它:

"PresetName": "Fast 720p30",

And just above that, I see this:就在这之上,我看到了这一点:

"Default": false,

Then I also look for this:然后我也寻找这个:

"PresetName": "Fast 1080p30",

And just above that I see this:就在上面,我看到了这个:

"Default": true,

So obviously 'Fast 1080p30' is the current default.所以很明显“Fast 1080p30”是当前的默认设置。 I want to change that to 'Fast 720p30'.我想将其更改为“快速 720p30”。

To do that manually, I need to set 'Default' to true for 'Fast 720p30' and set 'Default' to false (or just remove the line) for 'Fast 1080p30'.要手动执行此操作,我需要将“Fast 720p30”的“默认”设置为 true,并将“Fast 1080p30”的“默认”设置为 false(或仅删除该行)。

How can I do this using script?如何使用脚本执行此操作? I am using Windows 7 SP1 so can use any scripting language that runs on Windows 7 (Batch, VBScript, PowerShell, JavaScript, maybe even R, etc).我使用的是 Windows 7 SP1,因此可以使用在 Windows 7 上运行的任何脚本语言(Batch、VBScript、PowerShell、JavaScript,甚至可能是 R 等)。

My main problem is that I cannot find a way to access the '"Default": false,' line for any given preset because the JSON elements don't seem to have names.我的主要问题是我找不到访问任何给定预设的 '"Default": false,' 行的方法,因为 JSON 元素似乎没有名称。 So I'm thinking maybe I need to find '"PresetName": "Fast 720p30",' then find the '"Default": false,' above that and change it, all using script.所以我在想也许我需要找到 '"PresetName": "Fast 720p30",然后找到上面的 '"Default": false,' 并更改它,全部使用脚本。 But I don't know how to do that.但我不知道该怎么做。

I cannot paste the full presets.json file here because it's nearly 9000 lines long.我无法在此处粘贴完整的 presets.json 文件,因为它将近 9000 行。 But here is an edited version featuring the main parts:但这是一个包含主要部分的编辑版本:

{
  "PresetList": [
    {
      "ChildrenArray": [
        {
          "AlignAVStart": true,
          "AudioCopyMask": [
            "copy:aac"
          ],
          "AudioEncoderFallback": "ac3",
          "AudioLanguageList": [],
          "AudioList": [
            {
              "AudioBitrate": 160
            }
          ],
          "AudioSecondaryEncoderMode": true,
          "AudioTrackSelectionBehavior": "first",
          "ChapterMarkers": true,
          "ChildrenArray": [],
          "Default": false,
          "PresetName": "Very Fast 1080p30",
          "Type": 0
        },
        {
          "AlignAVStart": true,
          "AudioCopyMask": [
            "copy:aac"
          ],
          "AudioEncoderFallback": "ac3",
          "AudioLanguageList": [],
          "AudioList": [
            {
              "AudioBitrate": 160
            }
          ],
          "Default": false,
          "PresetName": "Very Fast 720p30",
          "Type": 0
        },
        {
          "AlignAVStart": true,
          "AudioCopyMask": [
            "copy:aac"
          ],
          "AudioEncoderFallback": "ac3",
          "AudioLanguageList": [],
          "AudioList": [
            {
              "AudioBitrate": 160
            }
          ],
          "AudioSecondaryEncoderMode": true,
          "AudioTrackSelectionBehavior": "first",
          "ChapterMarkers": true,
          "ChildrenArray": [],
          "Default": false,
          "PresetName": "Very Fast 576p25",
          "Type": 0,
        },
        {
          "AlignAVStart": true,
          "AudioCopyMask": [
            "copy:aac",
            "copy:ac3",
            "copy:dtshd",
            "copy:dts",
            "copy:mp3",
            "copy:truehd",
            "copy:flac",
            "copy:eac3"
          ],
          "AudioEncoderFallback": "ac3",
          "AudioLanguageList": [],
          "AudioList": [
            {
              "AudioBitrate": 160,
              "AudioCompressionLevel": 0.0,
              "AudioDitherMethod": null,
              "AudioEncoder": "av_aac",
              "AudioMixdown": "stereo",
              "AudioNormalizeMixLevel": false,
              "AudioSamplerate": "auto",
              "AudioTrackQualityEnable": false,
              "AudioTrackQuality": -1.0,
              "AudioTrackGainSlider": 0.0,
              "AudioTrackDRCSlider": 0.0
            }
          ],
          "AudioSecondaryEncoderMode": true,
          "AudioTrackSelectionBehavior": "first",
          "ChapterMarkers": true,
          "ChildrenArray": [],
          "Default": false,
          "PresetName": "Very Fast 480p30",
          "Type": 0
        },
        {
          "AlignAVStart": true,
          "AudioCopyMask": [
            "copy:aac",
            "copy:ac3",
            "copy:dtshd",
            "copy:dts",
            "copy:mp3",
            "copy:truehd",
            "copy:flac",
            "copy:eac3"
          ],
          "AudioEncoderFallback": "ac3",
          "AudioLanguageList": [],
          "AudioList": [
            {
              "AudioBitrate": 160,
              "AudioCompressionLevel": 0.0,
              "AudioDitherMethod": null,
              "AudioEncoder": "av_aac",
              "AudioMixdown": "stereo",
              "AudioNormalizeMixLevel": false,
              "AudioSamplerate": "auto",
              "AudioTrackQualityEnable": false,
              "AudioTrackQuality": -1.0,
              "AudioTrackGainSlider": 0.0,
              "AudioTrackDRCSlider": 0.0
            }
          ],
          "AudioSecondaryEncoderMode": true,
          "AudioTrackSelectionBehavior": "first",
          "ChapterMarkers": true,
          "ChildrenArray": [],
          "Default": true,
          "PresetName": "Fast 1080p30",
          "Type": 0
        },
        {
          "AlignAVStart": true,
          "AudioCopyMask": [
            "copy:aac",
            "copy:ac3",
            "copy:dtshd",
            "copy:dts",
            "copy:mp3",
            "copy:truehd",
            "copy:flac",
            "copy:eac3"
          ],
          "AudioEncoderFallback": "ac3",
          "AudioLanguageList": [],
          "AudioList": [
            {
              "AudioBitrate": 160,
              "AudioCompressionLevel": 0.0,
              "AudioDitherMethod": null,
              "AudioEncoder": "av_aac",
              "AudioMixdown": "stereo",
              "AudioNormalizeMixLevel": false,
              "AudioSamplerate": "auto",
              "AudioTrackQualityEnable": false,
              "AudioTrackQuality": -1.0,
              "AudioTrackGainSlider": 0.0,
              "AudioTrackDRCSlider": 0.0
            }
          ],
          "AudioSecondaryEncoderMode": true,
          "AudioTrackSelectionBehavior": "first",
          "ChapterMarkers": true,
          "ChildrenArray": [],
          "Default": false,
          "PresetName": "Fast 720p30",
          "Type": 0
        }
      ],
      "Folder": true,
      "PresetName": "Production",
      "PresetDescription": null,
      "Type": 0
    }
  ],
  "VersionMajor": 40,
  "VersionMicro": 0,
  "VersionMinor": 0
}

Many thanks.非常感谢。

Using PowerShell and JSON is not too difficult.使用 PowerShell 和 JSON 并不太难。

In this case, you can do:在这种情况下,您可以执行以下操作:

$jsonPath = Join-Path -Path $env:APPDATA -ChildPath 'HandBrake\presets.json'
# load the file and convert from json to get an array of objects
$json = Get-Content -Path $jsonPath | ConvertFrom-Json
# look for the item where the PresetName property is 'Fast 1080p30' and set its Default property to $false
$json.PresetList.ChildrenArray | Where-Object { $_.PresetName -eq 'Fast 1080p30' } | ForEach-Object { $_.Default = $false }

# look for the item where the PresetName property is 'Fast 720p30' and set its Default property to $true
$json.PresetList.ChildrenArray | Where-Object { $_.PresetName -eq 'Fast 720p30' } | ForEach-Object { $_.Default = $true }

# next save the updated data as json file.
# for demo, I'm using a new name so the original file is not overwritten.
# if you have inspected the output file and all is correct, remove or comment out the next line:
$jsonPath = Join-Path -Path $env:APPDATA -ChildPath 'HandBrake\presets2.json'

$json | ConvertTo-Json -Depth 99 | Set-Content -Path $jsonPath

Hope that helps希望有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM