Skip to content

Instantly share code, notes, and snippets.

@fweller
Created October 16, 2021 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fweller/f17163da66188e52753c472a816db699 to your computer and use it in GitHub Desktop.
Save fweller/f17163da66188e52753c472a816db699 to your computer and use it in GitHub Desktop.
Uses GStreamer to generate a bunch of video files from a single video file. These files are useful for testing embedded microprocessors.
#!/usr/bin/env bash
# generate_test_videos
# Uses GStreamer to generate a bunch of video files from a single video file
# These files are useful for testing embedded microprocessors
# Flint Weller 20211015
# --------------------------------
# IMPORTANT - Choose 1 or 2 below, and comment out the one you don't want
# 1 Specify the name of the input file in this script
#inputfile="sintel.mp4"
# 2 Specify the name of the input file while calling this script
inputfile=$1
# --------------------------------
# makeh264 - Create an mp4 video container file with h264 encoding
makeh264() {
width=$1
height=$2
framerate=$3
outputfile=$4
gst-launch-1.0 filesrc location=$inputfile ! \
decodebin name=decode ! \
videorate ! videoscale ! video/x-raw, format=I420, width=$width, height=$height, framerate=$framerate ! \
x264enc ! video/x-h264,profile=main ! mp4mux name=mp4mux ! filesink location=$outputfile \
decode. ! audioconvert ! lamemp3enc bitrate=128 ! queue ! mp4mux.audio_0
}
# --------------------------------
# makeh265 - Create an mp4 video container file with h265 encoding
makeh265() {
width=$1
height=$2
framerate=$3
outputfile=$4
gst-launch-1.0 filesrc location=$inputfile ! \
decodebin name=decode ! \
videorate ! videoscale ! video/x-raw, format=I420, width=$width, height=$height, framerate=$framerate ! \
x265enc ! video/x-h265,profile=main ! h265parse ! mp4mux name=mp4mux ! filesink location=$outputfile \
decode. ! audioconvert ! lamemp3enc bitrate=128 ! queue ! mp4mux.audio_0
}
# --------------------------------
# makeraw - Create a raw video (RTP RFC 4175) container file
makeraw() {
width=$1
height=$2
framerate=$3
outputfile=$4
gst-launch-1.0 filesrc location=$inputfile ! \
qtdemux name=demux \
demux.video_0 ! queue ! decodebin ! videorate ! videoconvert ! videoscale ! \
video/x-raw, format=I420, width=$width, height=$height, framerate=$framerate ! \
queue ! filesink location=$outputfile
}
# All remaining lines make calls to above functions, one line per output video file
# --------------------------------
# RAW
#QVGA
makeraw "320" "240" "30/1" "$inputfile-qvga-320x240_30fps.raw"
makeraw "320" "240" "15/1" "$inputfile-qvga-320x240_15fps.raw"
#VGA
makeraw "640" "480" "30/1" "$inputfile-vga-640x480_30fps.raw"
makeraw "640" "480" "15/1" "$inputfile-vga-640x480_15fps.raw"
#SHD
makeraw "1280" "720" "30/1" "$inputfile-shd-1280x720_30fps.raw"
makeraw "1280" "720" "15/1" "$inputfile-shd-1280x720_15fps.raw"
#FHD
makeraw "1920" "1080" "30/1" "$inputfile-fhd-1920x1080_30fps.raw"
makeraw "1920" "1080" "15/1" "$inputfile-fhd-1920x1080_30fps.raw"
# --------------------------------
# MPEG-4 h.264
#QVGA
makeh264 "320" "240" "30/1" "$inputfile-qvga-320x240_30fps_h264.mp4"
makeh264 "320" "240" "15/1" "$inputfile-qvga-320x240_15fps_h264.mp4"
#VGA
makeh264 "640" "480" "30/1" "$inputfile-vga-640x480_30fps_h264.mp4"
makeh264 "640" "480" "15/1" "$inputfile-vga-640x480_15fps_h264.mp4"
#SHD
makeh264 "1280" "720" "30/1" "$inputfile-shd-1280x720_30fps_h264.mp4"
makeh264 "1280" "720" "15/1" "$inputfile-shd-1280x720_15fps_h264.mp4"
#FHD
makeh264 "1920" "1080" "30/1" "$inputfile-fhd-1920x1080_30fps_h264.mp4"
makeh264 "1920" "1080" "15/1" "$inputfile-fhd-1920x1080_30fps_h264.mp4"
#QHD
makeh264 "2560" "1440" "30/1" "$inputfile-qhd-2560x1440_30fps_h264.mp4"
#UDH
makeh264 "3840" "2160" "30/1" "$inputfile-uhd-3840x2160_30fps_h264.mp4"
# --------------------------------
# MPEG-4 h.265
#QVGA
makeh265 "320" "240" "30/1" "$inputfile-qvga-320x240_30fps_h265.mp4"
makeh265 "320" "240" "15/1" "$inputfile-qvga-320x240_15fps_h265.mp4"
#VGA
makeh265 "640" "480" "30/1" "$inputfile-vga-640x480_30fps_h265.mp4"
makeh265 "640" "480" "15/1" "$inputfile-vga-640x480_15fps_h265.mp4"
#SHD
makeh265 "1280" "720" "30/1" "$inputfile-shd-1280x720_30fps_h265.mp4"
makeh265 "1280" "720" "15/1" "$inputfile-shd-1280x720_15fps_h265.mp4"
#FHD
makeh265 "1920" "1080" "30/1" "$inputfile-fhd-1920x1080_30fps_h265.mp4"
makeh265 "1920" "1080" "15/1" "$inputfile-fhd-1920x1080_30fps_h265.mp4"
#QHD
makeh265 "2560" "1440" "30/1" "$inputfile-qhd-2560x1440_30fps_h265.mp4"
#UDH
makeh265 "3840" "2160" "30/1" "$inputfile-uhd-3840x2160_30fps_h265.mp4"
# --------------------------------
# End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment