11# Source Configuration
22SOURCE_URL = https://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_720p_h264.mov
3- INPUT_VIDEO = BigBuckBunny_720p.mov
3+ # INPUT_VIDEO = driving.webm
4+ INPUT_VIDEO = BigBuckBunny_720p.mov
45
56INPUT_H264 = full_f_cbr.h264
67OUT_DIR = .
@@ -22,11 +23,17 @@ BASE_COMMON = tune=zerolatency \
2223 aud=false \
2324 rc-lookahead=0 \
2425 sliced-threads=false \
25- threads=1 \
26- option-string="repeat-headers=1:open-gop=0:scenecut=0:intra-refresh=0"
26+ threads=1 \
27+ # intra-refresh allows ammortizing complex scenes to a series of slightly larger P-frames instead of
28+ # generating a big IDR frame. This means much more stable bitrate and lower latency.
29+ #
30+ # https://news.ycombinator.com/item?id=25970843
31+ # http://www.chaneru.com/Roku/HLS/X264_Settings.htm#intra-refresh
32+ intra-refresh=true \
33+ option-string="repeat-headers=1:open-gop=0:scenecut=0"
2734
2835# Specific rate-control modifiers
29- CBR_FLAGS = pass=cbr nal-hrd=cbr vbv-buf-capacity=1000
36+ CBR_FLAGS = pass=cbr nal-hrd=cbr vbv-buf-capacity=200
3037VBR_FLAGS = # Intentionally blank. x264enc defaults to VBR/ABR when pass=cbr is omitted.
3138
3239.PHONY : all clean prepare estimate download distclean
@@ -145,41 +152,6 @@ estimate:
145152 grep -oP ' \(\K[0-9]+(?=\s*bytes)' || \
146153 { echo " Error: no frame sizes captured — check gst-launch output format." >&2 ; exit 1; }
147154
148- # Same as estimate, but also prints stdev/CV, and separates the largest frame
149- # (likely a keyframe) from the steady-state P-frames for a cleaner
150- # apples-to-apples "tightness" comparison against Chrome's trace.
151- estimate-summary :
152- @if [ ! -f " $( INPUT_H264) " ]; then \
153- echo " Error: Input file '$( INPUT_H264) ' not found." >&2 ; \
154- exit 1; \
155- fi
156- @gst-launch-1.0 -v \
157- filesrc location=$(INPUT_H264 ) ! \
158- h264parse ! \
159- fakesink silent=false 2>&1 | \
160- grep -oP ' \(\K[0-9]+(?=\s*bytes)' | \
161- awk ' { \
162- print; \
163- sizes[n]=$$ 1; sum+=$$ 1; n++; \
164- if ($$ 1 > max) { max=$$ 1; maxidx=n-1 } \
165- } \
166- END { \
167- if (! n) { print " no frames captured" > " /dev/stderr" ; exit 1 } \
168- mean = sum/n; \
169- for (i=0; i< n; i++) { d=sizes[i]-mean; ss+=d* d } \
170- stdev = sqrt(ss/n); \
171- sum2=0; n2=0; \
172- for (i=0; i< n; i++) { if (i! =maxidx) { sum2+=sizes[i]; n2++ } } \
173- mean2 = n2 ? sum2/n2 : 0; \
174- ss2=0; \
175- for (i=0; i< n; i++) { if (i! =maxidx) { d=sizes[i]-mean2; ss2+=d* d } } \
176- stdev2 = n2 ? sqrt(ss2/n2) : 0; \
177- printf " ---\n" ; \
178- printf " frames=%d mean=%.1f stdev=%.1f cv=%.1f%%\n" , n, mean, stdev, (stdev/mean)* 100; \
179- printf " largest frame: idx=%d size=%d (likely keyframe)\n" , maxidx, max; \
180- printf " excl. largest: frames=%d mean=%.1f stdev=%.1f cv=%.1f%%\n" , n2, mean2, stdev2, n2? (stdev2/mean2)* 100:0; \
181- }'
182-
183155clean :
184156 rm -f $(OUT_DIR ) /trimmed.mp4 \
185157 $(OUT_DIR ) /* _vbr.h264 \
0 commit comments