问题
I asked this question on the MSDN forums, but as always - there's no point in waiting on a reply from there.
What I am trying to do for now is to enable users to trim the start and end of their videos using the Media Encoder Standard encoder and a custom preset. However because it is not documented anywhere (despite being the "recommended" encoder), I can't get it to work. Here is what I add to the standard encoding preset JSON object:
customPreset.Sources = [
{
'Clips': [
{
'StartTime': '00:00:10', //sample values
'EndTime': '00:02:03'
}
]
}
];
The rest of the preset is a slightly modified adaptive bitrate preset, that's been tested to work fine:
"Codecs": [
{
"KeyFrameInterval": "00:00:02",
"H264Layers": [
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 5500,
"MaxBitrate": 6000,
"BufferWindow": "00:00:05",
"Width": 1920,
"Height": 1080,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
},
...//and so on, then image layers for thumbnails and audio profile
However when I start an encoding job with this Sources
property being added to the preset, the resulting asset is not trimmed. So I am assuming I am doing someone wrong? Since Microsoft don't seem to want to document this encoder(at least for now), is there anyone who's done something like this who can tell me how to modify the preset to enable this task?
I will most likely need to do more advanced editing, like sub-clipping, stitching and adding custom audio tracks later on so it would be helpful to know where all that goes in the encoding preset(and what of this MES actually supports).
回答1:
I just tried the following preset and successfully trimmed my video on demand. The Sources element is defined at the end.
{
"Version": 1.0,
"Codecs": [
{
"KeyFrameInterval": "00:00:02",
"StretchMode": "AutoSize",
"H264Layers": [
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 3400,
"MaxBitrate": 3400,
"BufferWindow": "00:00:05",
"Width": 1280,
"Height": 720,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
},
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 2250,
"MaxBitrate": 2250,
"BufferWindow": "00:00:05",
"Width": 960,
"Height": 540,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
},
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 1500,
"MaxBitrate": 1500,
"BufferWindow": "00:00:05",
"Width": 960,
"Height": 540,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
},
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 1000,
"MaxBitrate": 1000,
"BufferWindow": "00:00:05",
"Width": 640,
"Height": 360,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
},
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 650,
"MaxBitrate": 650,
"BufferWindow": "00:00:05",
"Width": 640,
"Height": 360,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
},
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 400,
"MaxBitrate": 400,
"BufferWindow": "00:00:05",
"Width": 320,
"Height": 180,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
}
],
"Type": "H264Video"
},
{
"Profile": "AACLC",
"Channels": 2,
"SamplingRate": 48000,
"Bitrate": 128,
"Type": "AACAudio"
}
],
"Outputs": [
{
"FileName": "{Basename}_{Width}x{Height}_{VideoBitrate}.mp4",
"Format": {
"Type": "MP4Format"
}
}
],
"Sources": [
{
"StartTime": "00:00:04",
"Duration": "00:00:16"
}
]
}
来源:https://stackoverflow.com/questions/34076363/how-to-trim-a-video-using-media-encoder-standard-via-rest-api