I’d like to merge an audio url and mp4 files. However, I’d like to add some codes to use the alias to create caption. How to do?
This is my current code:
{
"timeline": {
"soundtrack": {
"src": "{{ $('Map Public Link').item.json['Audio URL'] }}"
},
"tracks": [
{
"clips": {{ JSON.stringify($("Aggregate").item.json.list.map((item, i) => ({
"asset": {
"type": "video",
"src": item.generations_by_pk.generated_images[0].motionMP4URL
},
"start": $("split the scenes").item.json.groups[i].start,
"length": $("split the scenes").item.json.groups[i].end - $("split the scenes").item.json.groups[i].start
}))) }}
}
]
},
"output": {
"format": "mp4",
"size": {
"width": 720,
"height": 1280
}
}
}
I use n8n to set workflow. “Map Public Link”, “Aggregate” and “split the scenes” are some nodes.
This is my latest json code:
{
"timeline": {
"soundtrack": {
"src": "{{ $('Map Public Link').item.json['Audio URL'] }}"
},
"alias": "speech",
"asset": {
"type": "audio",
"src": "{{ $('Map Public Link').item.json['Audio URL'] }}"
},
"start": 0,
"length": "{{ $('Transcribe').item.json.duration }}",
"tracks": [
{
"clips":{{ JSON.stringify($('Aggregate').item.json.list.map((item, i) => ({
'asset': {
'type': 'video',
'src': item.generations_by_pk.generated_images[0].motionMP4URL
},
'start': $('split the scenes').item.json.groups[i].start,
'length': $('split the scenes').item.json.groups[i].end - $('split the scenes').item.json.groups[i].start
}))) }}
},
{
"clips": [
{
"asset": {
"type": "caption",
"src": "alias://speech"
},
"start": 0,
"length": "end"
}
]
}
]
},
"output": {
"format": "mp4",
"size": {
"width": 720,
"height": 1280
}
}
}
but i get “Bad Request” answer.
To add captions and link this to your audio url you’ll have to use an audio
asset instead of the soundtrack
.
This is how you would do it:
{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "caption",
"src": "alias://audioClip"
},
"start": 0,
"length": "auto"
}
]
},
{
"clips": [
{
"asset": {
"type": "video",
"src": "https://shotstack-assets.s3.amazonaws.com/footage/night-sky.mp4"
},
"start": 0,
"length": "auto"
}
]
},
{
"clips": [
{
"alias": "audioClip",
"asset": {
"type": "audio",
"src": "https://voiceage.com/wbsamples/in_mono/Television.wav"
},
"start": 0,
"length": "auto"
}
]
}
]
},
"output": {
"format": "mp4",
"size": {
"width": 720,
"height": 1280
}
}
}
You can style the captions further in the captions asset.
1 Like