1

I am currently trying to create streaming content for testing and I must create CMAF content. I have this code, but I do not really know it this is creating real CMAF content:

IN_VIDEO="$1"
FILENAME=$(echo "$IN_VIDEO" | cut -f 1 -d '.')
DIR=./$FILENAME

 if [ -z "$IN_VIDEO" ];then
    echo "Must input a file"
    $SHELL
    exit
 fi

FILENAME=$(echo "$IN_VIDEO" | cut -f 1 -d '.')
DIR=//opt/lampp/htdocs/streamingtest/$FILENAME
OUTDIR=//opt/lampp/htdocs/streamingtest/$FILENAME/CMAF
mkdir -p -v $DIR
mkdir -p -v $OUTDIR

# Assuming that input video is 1080p
ffmpeg -i $IN_VIDEO -vn -acodec copy $DIR/$FILENAME-AUD.mp4 \
-i $IN_VIDEO -vf scale=1920:1080,setsar=1 -an $DIR/$FILENAME-1080.mp4 \
-i $IN_VIDEO -vf scale=1280:720,setsar=1 -an $DIR/$FILENAME-720.mp4 \
-i $IN_VIDEO -vf scale=854:480,setsar=1 -an $DIR/$FILENAME-480.mp4 \
-i $IN_VIDEO -vf scale=640:360,setsar=1 -an $DIR/$FILENAME-360.mp4 \
-i $IN_VIDEO -vf scale=426:240,setsar=1 -an $DIR/$FILENAME-240.mp4 \

rm -R $OUTDIR

packager \
input=$DIR/$FILENAME-AUD.mp4,stream=audio,init_segment=$OUTDIR/aud_init.mp4,segment_template=$OUTDIR/aud_\$Number\$.mp4,playlist_name=audio.m3u8,hls_group_id=audio \
input=$DIR/$FILENAME-1080.mp4,stream=video,init_segment=$OUTDIR/vid_init-1080.mp4,segment_template=$OUTDIR/vid-1080_\$Number\$.mp4,playlist_name=video-1080.m3u8 \
input=$DIR/$FILENAME-720.mp4,stream=video,init_segment=$OUTDIR/vid_init-720.mp4,segment_template=$OUTDIR/vid-720_\$Number\$.mp4,playlist_name=video-720.m3u8 \
input=$DIR/$FILENAME-480.mp4,stream=video,init_segment=$OUTDIR/vid_init-480.mp4,segment_template=$OUTDIR/vid-480_\$Number\$.mp4,playlist_name=video-480.m3u8 \
input=$DIR/$FILENAME-360.mp4,stream=video,init_segment=$OUTDIR/vid_init-360.mp4,segment_template=$OUTDIR/vid-360_\$Number\$.mp4,playlist_name=video-360.m3u8 \
input=$DIR/$FILENAME-240.mp4,stream=video,init_segment=$OUTDIR/vid_init-240.mp4,segment_template=$OUTDIR/vid-240_\$Number\$.mp4,playlist_name=video-240.m3u8 \
--hls_master_playlist_output $OUTDIR/master.m3u8 \
--generate_static_mpd \
--mpd_output $OUTDIR/manifest.mpd

This generates a DASH manifest and a HLS master playlist from only 1 set of mp4 video. Is this considered CMAF compliant or am I going wrong?

Thanks!

slhck
  • 235,242

1 Answers1

2

Some observations:

  • You should make sure that your different representations have keyframes at the same locations and somewhat regular GOP sizes. This is not the case now. See this question for more info.

  • Make sure your individual segment lengths are restricted to at most 8–10 seconds, and that fragments are not longer than 2 seconds.

  • You have not specified any bitrate limitations or quality settings. Your bitrate will vary widely within and between representations. Use two-pass encoding or capped CRF encoding to limit the bitrate variablity per stream.

  • You have not set any H.264 profiles or levels, or forced a certain frame rate, pixel format, or bit depth. If your input is not within the correct specifications, you may end up producing video with features that not all players will support (e.g., 4:4:4 subsampling, too high framerates, 10-Bit content, ...)

  • You are only copying audio without enforcing a particular codec or bitrate. Same comment as above applies.

Other than that, using fragmented MP4 segments for HLS is part of the CMAF specification, so it should be fine.

I am not aware of any tool that gives you compliance checks. But if you don't want to verify manually against the official ISO spec, you can find Apple Developer documentation with example playlists to compare with.

slhck
  • 235,242