Skip to content

Commit

Permalink
Make horizontal disparity adjustment optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
sturmen committed Jan 30, 2024
1 parent 6d7f516 commit 35286a9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -53,10 +53,10 @@ OPTIONS:
```text
OVERVIEW: Merge two video files into a single MV-HEVC file.
USAGE: spatial-media-kit-tool merge [--debug] --left-file <left-file> --right-file <right-file> --quality <quality> [--left-is-primary] [--right-is-primary] --horizontal-field-of-view <horizontal-field-of-view> --horizontal-disparity-adjustment <horizontal-disparity-adjustment> --output-file <output-file>
USAGE: spatial-media-kit-tool merge [--debug] --left-file <left-file> --right-file <right-file> --quality <quality> [--left-is-primary] [--right-is-primary] --horizontal-field-of-view <horizontal-field-of-view> [--horizontal-disparity-adjustment <horizontal-disparity-adjustment>] --output-file <output-file>
OPTIONS:
--debug
--debug Optional. Pause execution at start to allow for time to attach a debugger.
-l, --left-file <left-file>
The left eye media file to merge.
-r, --right-file <right-file>
Expand All @@ -65,9 +65,9 @@ OPTIONS:
--left-is-primary Set the left file as the "hero" stream that is displayed when viewing in 2D.
--right-is-primary Set the right file as the "hero" stream that is displayed when viewing in 2D.
--horizontal-field-of-view <horizontal-field-of-view>
The field of view of the output video, in degrees. Output will be rounded to the nearest thousandth of a degree. 90 is a good default value.
The field of view of the output video, in degrees. Output will be rounded to the nearest thousandth of a degree. 90.000 is a good default value.
--horizontal-disparity-adjustment <horizontal-disparity-adjustment>
The horizontal disparity adjustment. 200 is a good default value.
Optional. The horizontal disparity adjustment. The value is a 32-bit integer, measured over the range of -10000 to 10000. Only specify a disparity adjustment, including 0, when you know the specific value.
-o, --output-file <output-file>
The output file to write to. Expects a .MOV extension.
--version Show the version.
Expand Down
53 changes: 32 additions & 21 deletions Sources/SpatialMediaKit/SpatialVideoMerger.swift
Expand Up @@ -49,7 +49,7 @@ public class SpatialVideoMerger {
transferFunction: String,
colorMatrix: String,
hFov: Int,
hDisparityAdj: Int,
hDisparityAdj: Int?,
leftIsPrimary: Bool
)
-> (
Expand All @@ -63,28 +63,39 @@ public class SpatialVideoMerger {
)

let mvHevcViewIds = leftIsPrimary ? [0, 1] : [1, 0]
let heroEye =
leftIsPrimary ? kCMFormatDescriptionHeroEye_Left : kCMFormatDescriptionHeroEye_Right

let outputSettingsDict: [String: Any] = [
AVVideoWidthKey: outputWidth,
AVVideoHeightKey: outputHeight,
AVVideoColorPropertiesKey: [
AVVideoColorPrimariesKey: colorPrimaries,
AVVideoTransferFunctionKey: transferFunction,
AVVideoYCbCrMatrixKey: colorMatrix,
],
AVVideoCompressionPropertiesKey: [
kVTCompressionPropertyKey_HDRMetadataInsertionMode: kVTHDRMetadataInsertionMode_Auto,
kVTCompressionPropertyKey_ProfileLevel: kVTProfileLevel_HEVC_Main10_AutoLevel,
kVTCompressionPropertyKey_Quality: videoQuality,
kVTCompressionPropertyKey_MVHEVCVideoLayerIDs: [0, 1] as CFArray,
kVTCompressionPropertyKey_MVHEVCViewIDs: [0, 1] as CFArray,
kCMFormatDescriptionExtension_HorizontalFieldOfView: hFov, // asset-specific, in thousandths of a degree
kVTCompressionPropertyKey_MVHEVCLeftAndRightViewIDs: mvHevcViewIds, // asset-specific
kVTCompressionPropertyKey_HeroEye: heroEye,
],
AVVideoCodecKey: AVVideoCodecType.hevc,
]

if let hDisparityAdj = hDisparityAdj {
let compressionProps =
outputSettingsDict[AVVideoCompressionPropertiesKey] as! NSMutableDictionary
compressionProps[kVTCompressionPropertyKey_HorizontalDisparityAdjustment] = hDisparityAdj
}

let assetWriterInput = AVAssetWriterInput(
mediaType: .video,
outputSettings: [
AVVideoWidthKey: outputWidth,
AVVideoHeightKey: outputHeight,
AVVideoColorPropertiesKey: [
AVVideoColorPrimariesKey: colorPrimaries,
AVVideoTransferFunctionKey: transferFunction,
AVVideoYCbCrMatrixKey: colorMatrix,
],
AVVideoCompressionPropertiesKey: [
kVTCompressionPropertyKey_HDRMetadataInsertionMode: kVTHDRMetadataInsertionMode_Auto,
kVTCompressionPropertyKey_ProfileLevel: kVTProfileLevel_HEVC_Main10_AutoLevel,
kVTCompressionPropertyKey_Quality: videoQuality,
kVTCompressionPropertyKey_MVHEVCVideoLayerIDs: [0, 1] as CFArray,
kCMFormatDescriptionExtension_HorizontalFieldOfView: hFov, // asset-specific, in thousandths of a degree
kVTCompressionPropertyKey_HorizontalDisparityAdjustment: hDisparityAdj, // asset-specific
kVTCompressionPropertyKey_MVHEVCLeftAndRightViewIDs: mvHevcViewIds, // asset-specific
],
AVVideoCodecKey: AVVideoCodecType.hevc,
]
outputSettings: outputSettingsDict
)

let adaptor = AVAssetWriterInputTaggedPixelBufferGroupAdaptor(
Expand Down Expand Up @@ -223,7 +234,7 @@ public class SpatialVideoMerger {
outputFilePath: String,
quality: Float,
horizontalFieldOfView: Int,
horizontalDisparityAdjustment: Int,
horizontalDisparityAdjustment: Int?,
leftIsPrimary: Bool
) {
do {
Expand Down
7 changes: 4 additions & 3 deletions Sources/SpatialMediaKitTool/SpatialMediaKitTool.swift
Expand Up @@ -62,7 +62,8 @@ extension SpatialMediaKitTool {
CommandConfiguration(
abstract: "Merge two video files into a single MV-HEVC file.")

@Flag(help: "Pause execution at start to allow for time to attach a debugger.") var debug =
@Flag(help: "Optional. Pause execution at start to allow for time to attach a debugger.")
var debug =
false

@Option(name: .shortAndLong, help: "The left eye media file to merge.")
Expand All @@ -89,9 +90,9 @@ extension SpatialMediaKitTool {
@Option(
name: .long,
help:
"The horizontal disparity adjustment. 200 is a good default value."
"Optional. The horizontal disparity adjustment. The value is a 32-bit integer, measured over the range of -10000 to 10000. Only specify a disparity adjustment, including 0, when you know the specific value."
)
var horizontalDisparityAdjustment: Int
var horizontalDisparityAdjustment: Int?

@Option(
name: .shortAndLong,
Expand Down

0 comments on commit 35286a9

Please sign in to comment.