'How to make audio track optional for Google Transcoder API
Issue
What I'm trying to do is simply convert and compress a video file from the storage bucket in node.js using @google-cloud/video-transcoder
(TranscoderServiceClient v1
). Single input file and a single output. The input file may or may not have an audio track. Everything works as expected when the file includes an audio track, but when it doesn't, I'll get an error with code 3:
\atom atom0 does not have any inputs (input0) with an audio track
Only options I can think of currently, are:
- Use
pubsub
to listen for job errors and run failed jobs again, but without the audio stream (got this working). - Use something like
ffprobe
before starting the job to determine if there is an audio track in the file.
However, I would prefer not reading the file twice: once for determining available tracks and then for transcoding. And I wouldn't like to run the job twice. I found nothing in docs about how to only include the audio track if it exists (or replace it with an empty audio track if it does not exist).
Current config:
config: {
elementaryStreams: [
{
key: 'video-stream0',
videoStream: {...},
},
{
key: 'audio-stream0',
audioStream: {...},
},
],
muxStreams: [
{
key: 'hd',
container: 'mp4',
elementaryStreams: ['video-stream0', 'audio-stream0'],
},
],
}
Documentation used:
- Setup - Transcoder API Node.js Client reference (my implementation is near identical with the ad-hoc example in googleapis git)
- Config - JobConfig
- Call options - CallOptions
Update
@Betjens suggested to use CallOptions
to retry the job without pubsub
, but I can't get it to work in node.js. The job does not retry, with or without backOffSettings. The official example for pubsub retry is an example for another API that uses CallOptions, but it does not seem to work in my case.
const callOptions = {
retry: {
retryCodes: [3], // 'INVALID_ARGUMENT', error code if audio missing
backoffSettings: {...}
},
retryRequestOptions: {
request: requestWithoutAudio // request without audio streams to retry
}
}
// Run request
const [response] = await transcoderServiceClient.createJob(request, callOptions);
Solution 1:[1]
I will post this to recap what I have found of your case. And the suggest the actions based on the comment exchange.
Configuration tips:
- Make sure your configuration elementaryStreams keys match the muxStreams elementaryStreams match else you may have issues with the transcoder service.
In you configuration you are making reference of 'video-stream1'
muxStreams: [
{
key: 'hd',
container: 'mp4',
elementaryStreams: ['video-stream1', 'audio-stream0'],
},
],
which do not exist in your elementaryStreams
elementaryStreams: [
{
key: 'video-stream0',
videoStream: {...},
},
{
key: 'audio-stream0',
audioStream: {...},
},
],
Retry tips:
- Client for
Node.js
I have not see this kind of implementation as described on transcoderserviceclient. - Client for Python, there is an option to set a retry operation when you create a job which you can use to pass a retry [
google.api.retry
] on the client.
Python Sample (from Google API Retry)
@retry.Retry(predicate=if_exception_type(exceptions.NotFound))
def check_if_exists():
return client.does_thing_exist()
is_available = check_if_exists()
** update 05/09: I have refreshed my answer with the latest updates.
retries helpful links:
Summarize:
- You can use the client retry and pass a google retry to perform the retry operation with the exception you want to handle.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |