【问题标题】:Azure Media Services - v3 Overlay position issueAzure 媒体服务 - v3 覆盖位置问题
【发布时间】:2021-03-30 03:50:01
【问题描述】:

我正在研究一种将叠加图像添加到视频的编码流程。我希望这个水印在右下角。无论我尝试使用位置参数,水印都位于左上角。

谁能给我指出一个涵盖该场景的示例? Microsoft 文档和示例在定位叠加层和设置不透明度方面含糊不清。

这是一段包含我的转换定义的代码。无论覆盖设置如何,我都可以为矩形位置元素使用任何值,并且没有任何变化。水印最终出现在视频的右上角。它就像位置和不透明度属性被忽略了。

 new AMSModels.TransformOutput(
            new AMSModels.StandardEncoderPreset(
                 filters: new AMSModels.Filters
                        {
                            Overlays = new List<AMSModels.Overlay>
                            {
                                new AMSModels.VideoOverlay()
                                {
                                    InputLabel =  "tbvvideooverlay",
                                    Opacity = .5,
                                    Position = new AMSModels.Rectangle(){ Left = "100", Top = "100", Width = "100", Height = "100"} //**I've tried all types of values here including percentages, nothing changes when I reencode the video.**


                                }
                            }
                        },
                codecs: new AMSModels.Codec[]
                {
                    // Add an AAC Audio layer for the audio encoding
                    new AMSModels.AacAudio(
                        channels: 2,
                        samplingRate: 48000,
                        bitrate: 128000,
                        profile: AMSModels.AacAudioProfile.AacLc
                    ),
                    // Next, add a H264Video for the video encoding
                   new AMSModels.H264Video (
                        // Set the GOP interval to 2 seconds for all H264Layers
                        keyFrameInterval:TimeSpan.FromSeconds(2),
                         // Add H264Layers. Assign a label that you can use for the output filename
                        layers:  new AMSModels.H264Layer[]
                        {
                            new AMSModels.H264Layer (
                                bitrate: 3600000, // Units are in bits per second and not kbps or Mbps - 3.6 Mbps or 3,600 kbps
                                width: "1280",
                                height: "720",
                                label: "3600" // This label is used to modify the file name in the output formats
                            ),
                            new AMSModels.H264Layer (
                                bitrate: 1600000, // Units are in bits per second and not kbps or Mbps - 1.6 Mbps or 1600 kbps
                                width: "960",
                                height: "540",
                                label: "1600" // This label is used to modify the file name in the output formats
                            ),
                            new AMSModels.H264Layer (
                                bitrate: 600000, // Units are in bits per second and not kbps or Mbps - 0.6 Mbps or 600 kbps
                                width: "640",
                                height: "360",
                                label: "600" // This label is used to modify the file name in the output formats
                            ),
                        }
                    ),
                    // Also generate a set of PNG thumbnails
                    new AMSModels.PngImage(
                        start: "10%",
                        step: "10%",
                        range: "90%",
                        layers: new Microsoft.Azure.Management.Media.Models.PngLayer[]{
                            new AMSModels.PngLayer(
                                width: "100%",
                                height: "100%"
                            )
                        }
                    ),
                    new AMSModels.JpgImage(
                        start: "10%",
                        step: "10%",
                        range: "90%",
                        layers: new Microsoft.Azure.Management.Media.Models.JpgLayer[]{
                            new AMSModels.JpgLayer(
                                quality: 100,
                                width: "100%",
                                height: "100%"
                            )
                        }
                    )
                },
                // Specify the format for the output files - one for video+audio, and another for the thumbnails
                formats: new AMSModels.Format[]
                {
                    // Mux the H.264 video and AAC audio into MP4 files, using basename, label, bitrate and extension macros
                    // Note that since you have multiple H264Layers defined above, you have to use a macro that produces unique names per H264Layer
                    // Either {Label} or {Bitrate} should suffice
                     
                    new AMSModels.Mp4Format(
                        filenamePattern:"{Basename}_{Resolution}_{Bitrate}{Extension}"
                    ),
                    new AMSModels.PngFormat(
                        filenamePattern:"Thumbnail-{Basename}-{Index}{Extension}"
                    ),

                      new AMSModels.JpgFormat(
                        filenamePattern:"Thumbnail-{Basename}-{Index}{Extension}"
                    )
                }
            ),
            onError: AMSModels.OnErrorType.StopProcessingJob,
            relativePriority: AMSModels.Priority.Normal
        )
        };

            string description = "A simple custom encoding transform with 2 MP4 bitrates";
            // Create the custom Transform with the outputs defined above
            transform = await client.Transforms.CreateOrUpdateAsync(resourceGroupName, accountName, transformName, outputs, description);
        }

谢谢!

【问题讨论】:

    标签: azure-media-services


    【解决方案1】:

    非常感谢您发现并指出这一问题。我们对此进行了查看并确认确实存在您在这里发现的错误!首先,感谢您发现并报告此问题。

    现在是坏消息,现在我们将不得不考虑修复该问题并将修复程序重新部署到生产环境中。这对我们来说可能需要一些时间,所以如果您需要一个快速的解决方案,我唯一可以建议的是使用较旧的 v2 API(是的,我们宣布弃用的 API)来解决这个问题,直到我们可以将代码修复到生产环境中。

    如果适合您,这里是 v2 中较旧的方法 - https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-advanced-encoding-with-mes#overlay

    【讨论】:

    • 快速更新 - 我们在 V3 API 中针对叠加层的绝对像素定位进行了修复,它将在我们的 4 月有效负载中,直到 4 月底才会投入生产。当它上线时,我会尽量在这里回复你。
    • 更新 - 针对绝对像素位置的修复正在生产中
    • 谢谢!我还有一个问题...此功能的最佳文档在哪里。它现在似乎正在定位,我似乎无法将它放在右下角。我会有不同分辨率的视频。我尝试将矩形的 left 和 top 属性分别设置为 90%,但它仍然显示在左上角……但在左上角并不完全合理。所以我可以告诉位置属性正在做某事。如果您有一个示例说明如何在右下角放置 75 x 75 像素的徽标,那将非常有帮助。再次感谢!
    • 如上所述,修复仅适用于“绝对像素定位” - 而不是相对的。所以使用基于百分比的定位还行不通。您必须知道将其以像素为单位的确切位置,以使其此时降落在右下角的正确位置。
    【解决方案2】:

    感谢您确认这一点。我已经迁移并致力于 v3,所以回头会很麻烦。

    我仍在努力,但我确实有一个解决方法可以让我度过难关。如果我制作和图像的尺寸与我最大的视频尺寸相同,那么我可以将水印放置在该图像的右下角。只要它是透明的 PNG,它“看起来”就像水印是右下对齐的。

    我必须在我拥有的所有视频资产中测试这个解决方案,但到目前为止,我认为它会一直有效,直到上面的补丁生效。一旦解决了这个问题,我计划允许我们的用户从各种水印中进行选择。

    再次感谢!

    埃里克

    【讨论】:

    • 在下面分享,但在这里再做一次。绝对像素定位的修复程序已签入,但要到 4 月底才能投入生产。到时候我会在这里更新。
    • 感谢您的更新!我期待着它。我的解决方法有点不稳定。当我有不同大小的输入视频时,叠加位置会有所不同。我假设它的设置相对于视频大小。我会坐等补丁正式上线。
    • 所以...它是四月底:) 我们如何看待这个修复?谢谢!!
    • 从本周开始,现在应该在所有区域部署修复程序。该修复程序目前支持以绝对像素为单位的叠加位置。我们仍计划在后续修复中添加对基于百分比的定位的支持。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-30
    • 1970-01-01
    • 2015-11-18
    • 1970-01-01
    相关资源
    最近更新 更多