Search code examples
pythonaudiogoogle-cloud-platformvideogoogle-cloud-transcoder

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 :)


Solution

  • 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"
       }
    ]