Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

devops: build ffmpeg for linux (#3880)

Andrey Lushnikov2a66f8a0668f
diff --git a/browser_patches/buildbots/buildbot-ubuntu-20.04.sh b/browser_patches/buildbots/buildbot-ubuntu-20.04.sh
index 496fbe8d73..3880425691 100755
--- a/browser_patches/buildbots/buildbot-ubuntu-20.04.sh
+++ b/browser_patches/buildbots/buildbot-ubuntu-20.04.sh
@@ -70,3 +70,6 @@ git pull origin master
git pull origin master
../checkout_build_archive_upload.sh ffmpeg-cross-compile-win64 >/tmp/$(basename $0)--ffmpeg-cross-compile-win64.log || true
+
+git pull origin master
+../checkout_build_archive_upload.sh ffmpeg-linux >/tmp/$(basename $0)--ffmpeg-linux.log || true
diff --git a/browser_patches/checkout_build_archive_upload.sh b/browser_patches/checkout_build_archive_upload.sh
index 33034efa6f..42f21a52a2 100755
--- a/browser_patches/checkout_build_archive_upload.sh
+++ b/browser_patches/checkout_build_archive_upload.sh
@@ -42,6 +42,12 @@ if [[ "$BUILD_FLAVOR" == "ffmpeg-mac" ]]; then
EXPECTED_HOST_OS="Darwin"
EXPECTED_HOST_OS_VERSION="10.14"
BUILD_BLOB_NAME="ffmpeg-mac.zip"
+elif [[ "$BUILD_FLAVOR" == "ffmpeg-linux" ]]; then
+ BROWSER_NAME="ffmpeg"
+ EXTRA_BUILD_ARGS="--linux"
+ EXPECTED_HOST_OS="Ubuntu"
+ EXPECTED_HOST_OS_VERSION="20.04"
+ BUILD_BLOB_NAME="ffmpeg-linux.zip"
elif [[ "$BUILD_FLAVOR" == "ffmpeg-cross-compile-win32" ]]; then
BROWSER_NAME="ffmpeg"
EXTRA_BUILD_ARGS="--cross-compile-win32"
diff --git a/browser_patches/ffmpeg/README.md b/browser_patches/ffmpeg/README.md
index bca1bbc7f8..c5c886f9e8 100644
--- a/browser_patches/ffmpeg/README.md
+++ b/browser_patches/ffmpeg/README.md
@@ -1,16 +1,30 @@
# Playwright and FFMPEG
-Playwright requires FFMPEG to produce screncast. Playwright relies on stock
-FFMPEG on Ubuntu, and bundles FFMPEG binaries for Mac and Windows.
+Playwright requires FFMPEG to produce screncast and bundles FFMPEG binaries for Mac , Linux and Windows.
## Configuration
We compile `libvpx` and `ffmpeg` only. Their source versions and build
configurations are defined in [`//browser_patches/ffmpeg/CONFIG.sh`](./CONFIG.sh).
+## Building `ffmpeg-linux`
+
+Compilation scripts are based on:
+- https://trac.ffmpeg.org/wiki/CompilationGuide/Generic
+
+Prerequisites:
+- Mac or Linux
+- Docker
+
+Building:
+
+```
+~/playwright$ ./browser_patches/ffmpeg/build.sh --linux
+```
+
## Building `ffmpeg-mac`
-Cross-compilation scripts are based on:
+Compilation scripts are based on:
- https://trac.ffmpeg.org/wiki/CompilationGuide/Generic
- https://trac.ffmpeg.org/wiki/CompilationGuide/macOS
diff --git a/browser_patches/ffmpeg/build-linux.sh b/browser_patches/ffmpeg/build-linux.sh
new file mode 100644
index 0000000000..80eadab37c
--- /dev/null
+++ b/browser_patches/ffmpeg/build-linux.sh
@@ -0,0 +1,82 @@
+#!/bin/bash
+
+# Copyright (c) Microsoft Corporation.
+#
+# 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 -ex
+
+function die() { echo "$@"; exit 1; }
+
+
+PREFIX="${HOME}/prefix"
+
+
+if [[ "$(uname)" != "Linux" ]]; then
+ echo "ERROR: this script is designed to be run on Linux. Can't run on $(uname)"
+ exit 1
+fi
+
+output_path="$1"
+if [[ -z "${output_path}" ]]; then
+ die "ERROR: output path is not specified"
+elif [[ "${output_path}" != /* ]]; then
+ die "ERROR: output path ${output_path} is not absolute"
+elif ! [[ -d $(dirname "${output_path}") ]]; then
+ die "ERROR: folder for output path ${output_path} does not exist."
+fi
+
+function build_libvpx {
+ cd "${HOME}"
+ git clone https://chromium.googlesource.com/webm/libvpx
+ cd libvpx
+ git checkout "${LIBVPX_VERSION}"
+ # Cross-compiling libvpx according to the docs:
+ # - https://chromium.googlesource.com/webm/libvpx/+/master/README
+ ./configure --prefix="${PREFIX}" ${LIBVPX_CONFIG}
+ make && make install
+}
+
+function build_ffmpeg {
+ cd "${HOME}"
+ git clone git://source.ffmpeg.org/ffmpeg.git
+ cd ffmpeg
+ git checkout "${FFMPEG_VERSION}"
+ # Prohibit pkg-config from using linux system installed libs.
+ export PKG_CONFIG_LIBDIR=
+
+ ./configure --pkg-config=pkg-config \
+ --pkg-config-flags="--static" \
+ --extra-cflags="-I/${PREFIX}/include" \
+ --extra-ldflags="-L/${PREFIX}/lib -static" \
+ --prefix="${PREFIX}" \
+ --bindir="${PWD}/bin" \
+ ${FFMPEG_CONFIG}
+ make && make install
+}
+
+trap "cd $(pwd -P)" EXIT
+cd "$(dirname $0)"
+
+source ./CONFIG.sh
+
+apt-get update
+apt-get install -y git make yasm pkg-config
+
+build_libvpx
+build_ffmpeg
+
+# put resulting executable where we were asked to
+cp "${HOME}/ffmpeg/bin/ffmpeg" "${output_path}"
+strip "${output_path}"
+
diff --git a/browser_patches/ffmpeg/build.sh b/browser_patches/ffmpeg/build.sh
index ab5465ade8..ad3310b539 100755
--- a/browser_patches/ffmpeg/build.sh
+++ b/browser_patches/ffmpeg/build.sh
@@ -36,20 +36,27 @@ fi
rm -rf ./output
mkdir -p output
+dockerflags="";
+# Use |-it| to run docker to support Ctrl-C if we run the script inside interactive terminal.
+# Otherwise (e.g. cronjob) - do nothing.
+if [[ -t 0 ]]; then
+ dockerflags="-it"
+fi
+
if [[ "$1" == "--mac" ]]; then
bash ./build-mac.sh
cd output && zip ffmpeg.zip ffmpeg-mac
-elif [[ "$1" == --cross-compile-win* ]]; then
+elif [[ "$1" == "--linux" ]]; then
if ! command -v docker >/dev/null; then
echo "ERROR: docker is required for the script"
exit 1
fi
-
- dockerflags="";
- # Use |-it| to run docker to support Ctrl-C if we run the script inside interactive terminal.
- # Otherwise (e.g. cronjob) - do nothing.
- if [[ -t 0 ]]; then
- dockerflags="-it"
+ time docker run --init --rm -v"${PWD}":/host ${dockerflags} ubuntu:18.04 bash /host/build-linux.sh /host/output/ffmpeg-linux
+ cd output && zip ffmpeg.zip ffmpeg-linux
+elif [[ "$1" == --cross-compile-win* ]]; then
+ if ! command -v docker >/dev/null; then
+ echo "ERROR: docker is required for the script"
+ exit 1
fi
if [[ "$1" == "--cross-compile-win32" ]]; then