Created
August 18, 2015 01:46
-
-
Save atdt/2c2779387a77c76e9680 to your computer and use it in GitHub Desktop.
Generate a side-by-side comparison video from two WebPageTest runs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # wpt-side-by-side | |
| # ~~~~~~~~~~~~~~~~ | |
| # Generate a side-by-side comparison video from two WebPageTest runs. | |
| # | |
| # Usage: | |
| # wpt-side-by-side WEBPAGETEST_URL_1 WEBPAGETEST_URL_2 | |
| # | |
| # Requirements: | |
| # * ffmpeg | |
| # * ffmpeg2theora | |
| # | |
| # Example: | |
| # wpt-side-by-side \ | |
| # http://www.webpagetest.org/result/150731_4N_16RK/ \ | |
| # http://www.webpagetest.org/result/150817_EJ_1DZW/ | |
| # | |
| # This will generate combined_150731_4N_16RK_150817_EJ_1DZW.{mp4,ogv} | |
| # | |
| # Copyright (C) 2015 Ori Livneh <ori@wikimedia.org> | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| # | |
| set -e | |
| usage() { | |
| echo >&2 "Usage: $0 TEST_URL_1 TEST_URL_2" | |
| } | |
| get_test_id() { | |
| # Extract the WebPageTest test ID from a WebPageTest URL | |
| grep -Po '\d{6}_\w{2}_\w{4}' <<<"$*" | |
| } | |
| get_video() { | |
| # Download the video for a given WebPageTest run | |
| local test_id="$(get_test_id "$1")" | |
| curl -s "http://www.webpagetest.org/video/download.php?id=${test_id}.1.0" -o "${test_id}.mp4" | |
| echo "${test_id}.mp4" | |
| } | |
| combine_videos() { | |
| # Combine two WebPageTest run videos into a single OGV file | |
| local target_name="combined_$(basename "$1" .mp4)_$(basename "$2" .mp4)" | |
| ffmpeg -i "$1" -i "$2" -filter_complex \ | |
| "[0:v] setpts=PTS-STARTPTS, pad=iw*2:ih [left]; \ | |
| [1:v] setpts=PTS-STARTPTS [right]; \ | |
| [left][right] overlay=w" "${target_name}.mp4" | |
| ffmpeg2theora "${target_name}.mp4" --noaudio -v 10 | |
| echo "${target_name}.ogv" | |
| } | |
| if [[ $# -ne 2 ]] || ! get_test_id $1 >/dev/null || ! get_test_id $2 >/dev/null ; then | |
| usage | |
| exit 1 | |
| fi | |
| left="$(get_video "$1")" | |
| right="$(get_video "$2")" | |
| combine_videos "$left" "$right" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment