Thomas Spycher
Thomas Spycher

Reputation: 976

How to mix Video and Audio together in GCS Transcoder API

I have two mp4 files. One contains only video and the other only audio. Both have exactly the same length (some seconds extracted from a HLS Stream).

I want them now to get mixed together trough a GCS Transcoder API Job which gets triggered by a Dataflow Pipeline. Digging trough the documentation did not yet result in a solution.

My current Job Config looks like that:

gcs_video = "gcs://abc/video.mp4"
gcs_audio = "gcs://abc/audio.mp4"
video_input = transcoder_v1.types.Input(key="input0", uri=gcs_video)
audio_input = transcoder_v1.types.Input(key="input1", uri=gcs_audio)

job.config = transcoder_v1.types.JobConfig(
            inputs=[video_input, audio_input],
            elementary_streams=[
                transcoder_v1.types.ElementaryStream(
                    key="video-stream0",
                    video_stream=transcoder_v1.types.VideoStream(
                        h264=transcoder_v1.types.VideoStream.H264CodecSettings(
                            height_pixels=720,
                            width_pixels=1280,
                            bitrate_bps=2500000,
                            frame_rate=30,
                        ),
                    ),
                ),
                transcoder_v1.types.ElementaryStream(
                    key="audio-stream0",
                    audio_stream=transcoder_v1.types.AudioStream(
                        codec="aac", bitrate_bps=64000
                    ),
                ),
            ],
            mux_streams=[
                transcoder_v1.types.MuxStream(
                    key="hd",
                    container="mp4",
                    elementary_streams=["video-stream0", "audio-stream0"],
                ),
            ],
        )

At a later point we will add some overlays and convert it to different formats. But for now i'm already happy if i can get them together :)

Upvotes: 3

Views: 489

Answers (2)

Thomas Spycher
Thomas Spycher

Reputation: 976

Thanks to the Answer of @TJ Liu i was able to figure out the correct config for my transcoding job. The End Config looks like this:

gcs_video = "gcs://abc/video.mp4"
gcs_audio = "gcs://abc/audio.mp4"
video_input = transcoder_v1.types.Input(key="input0", uri=gcs_video)
audio_input = transcoder_v1.types.Input(key="input1", uri=gcs_audio)
clip_duration = 9

job.config = transcoder_v1.types.JobConfig(
            inputs=[video_input, audio_input],
            edit_list=[
                transcoder_v1.types.EditAtom(
                    key="atom0",
                    inputs=["input0", "input1"],
                    end_time_offset = Duration(seconds=clip_duration)

            )
            ],
            elementary_streams=[
                transcoder_v1.types.ElementaryStream(
                    key="video-stream0",
                    video_stream=transcoder_v1.types.VideoStream(
                        h264=transcoder_v1.types.VideoStream.H264CodecSettings(
                            height_pixels=720,
                            width_pixels=1280,
                            bitrate_bps=2500000,
                            frame_rate=30,
                        ),
                    ),
                ),
                transcoder_v1.types.ElementaryStream(
                    key="audio-stream0",
                    audio_stream=transcoder_v1.types.AudioStream(
                        codec="aac", bitrate_bps=64000
                    ),
                ),
            ],
            mux_streams=[
                transcoder_v1.types.MuxStream(
                    key="hd",
                    container="mp4",
                    elementary_streams=["video-stream0", "audio-stream0"],
                ),
            ],
        )

Upvotes: 0

TJ Liu
TJ Liu

Reputation: 176

There are some defaults not listed in the documentation. Try adding the following to your config and see whether it works

"editList":[
   {
      "key":"atom0",
      "inputs":[
         "video_input_key",
         "audio_input_key"
      ],
      "startTimeOffset":"0s"
   }
]

Upvotes: 2

Related Questions