MP4¶
This topic describes the MP4 Muxer parameters.
Optimizing for progressive download or streaming¶
Every MP4 file contains a moov atom that acts as an index of the video data. The index enables a player to play and scrub the file. Unfortunately, in an MPEG-4–compliant container, the moov atom is normally stored at the end of the file. To enable progressive download or streaming the moov atom has to be moved to the beginning of the file.
There are three AVBlocks parameters that control the MP4 FastStart muxing. These parameters must be set on the output socket:
FastStart¶
If this parameter is set to True, the MP4 muxer will run a second pass to move the moov atom to the beginning of the file.
FastStartUseTempFile¶
If this parameter is set to True, the MP4 muxer will use a temp file for the second pass.
FastStartTempFileDirectory¶
Specifies a directory for the temp file. If not set, the system temp path is used.
Sample Code¶
Here is how you can set the MP4 FastStart parameters in Python:
from avblocks import (
AudioStreamInfo, MediaPin, MediaSocket, Param, StreamSubType,
StreamType, Transcoder, VideoStreamInfo
)
with Transcoder() as transcoder:
# Transcoder demo mode must be enabled,
# in order to use the production release for testing (without a valid license).
transcoder.allow_demo_mode = True
# Configure output socket
# MP4 container socket
socket = MediaSocket()
socket.stream_type = StreamType.MP4
# The MP4 FastStart parameters must be set on the socket
socket.params[Param.Muxer.MP4.FastStart] = True
socket.params[Param.Muxer.MP4.FastStartUseTempFile] = True
socket.params[Param.Muxer.MP4.FastStartTempFileDirectory] = r"C:\Temp"
# H.264 video pin
video_info = VideoStreamInfo()
video_info.stream_type = StreamType.H264
video_info.stream_sub_type = StreamSubType.AVC1
video_pin = MediaPin()
video_pin.stream_info = video_info
socket.pins.add(video_pin)
# AAC audio pin
audio_info = AudioStreamInfo()
audio_info.stream_type = StreamType.AAC
audio_info.stream_sub_type = StreamSubType.AAC_MP4
audio_pin = MediaPin()
audio_pin.stream_info = audio_info
socket.pins.add(audio_pin)
transcoder.outputs.add(socket)