Skip to content

Add FFmpeg support to open video files #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jan 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8a88f15
Add FFmpeg support to open video files
yongtang Dec 16, 2018
9a500e5
Add python wrapper for video.VideoDataset
yongtang Dec 16, 2018
fdf7499
Add test case for video.VideoDataset
yongtang Dec 16, 2018
cd22417
Add BUILD file for tensorflow_io.video
yongtang Dec 16, 2018
6dcdaa5
Add ffmpeg n3.4.4 dependency
yongtang Dec 16, 2018
15b2c43
Update BUILD file to include video.VideoDataset
yongtang Dec 16, 2018
1df47e2
Disable -//tensorflow_io/video:video_py_test test on Ubuntu 14.04
yongtang Dec 17, 2018
738b8ea
Update ffmpeg to use stub .so files
yongtang Dec 17, 2018
d218d35
Add Travis CI for Ubuntu 18.04, use `docker run` as Travis does not h…
yongtang Dec 18, 2018
a53ddf6
Disable sandboxed mode in bazel and use --spawn_strategy standalone
yongtang Dec 18, 2018
29bb7dc
Use python as base vm image for Travis CI Ubuntu 18.04
yongtang Dec 18, 2018
f26e4ee
Only Enable Video on Travis CI for Ubuntu 18.04, as it is inside cont…
yongtang Dec 18, 2018
a113c69
Add Ubuntu 16.04 support, by build separate so with ffmpeg 2.8
yongtang Dec 18, 2018
bdb85d3
Fix additional issue in ffmpeg 3.4 where cached packet should just ig…
yongtang Dec 18, 2018
f3884ae
Add Ubuntu 14.04 support, with libav 9.20 built in.
yongtang Dec 18, 2018
ccc8a20
Add libav dependency and enable video test on Ubuntu 14.04
yongtang Dec 18, 2018
a5cbf32
Enable Ubuntu 16.04 for video.VideoDataset
yongtang Dec 18, 2018
10a402d
Defined a bazel rule of `cc_import_library` to only accepts system li…
yongtang Jan 5, 2019
4da4dd2
Reduce verbose logging output by bazel
yongtang Jan 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 66 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
dist: trusty
sudo: required

addons:
apt:
update: true

env:
- BAZEL_OS=linux
BAZEL_VERSION=0.17.2
Expand All @@ -14,48 +17,100 @@ before_script:

matrix:
include:
- language: python
- name: "Ubuntu 14.04 Python 2.7"
dist: trusty
language: python
python:
- 2.7
before_install:
- sudo apt-get install -y -qq libav-tools
- bash -x ${TRAVIS_BUILD_DIR}/.travis/python.configure.sh
- pip install pyarrow==0.11.1
script:
- bazel test --show_progress=no -s --verbose_failures --test_output=errors -- //tensorflow_io/...
- language: python
- bazel test --noshow_progress --noshow_loading_progress --spawn_strategy standalone --verbose_failures --test_output=errors -- //tensorflow_io/...
- name: "Ubuntu 14.04 Python 3.4"
dist: trusty
language: python
python:
- 3.4
before_install:
- sudo apt-get install -y -qq libav-tools
- bash -x ${TRAVIS_BUILD_DIR}/.travis/python.configure.sh
script:
- bazel test --show_progress=no -s --verbose_failures --test_output=errors -- //tensorflow_io/...
- language: python
- bazel test --noshow_progress --noshow_loading_progress --spawn_strategy standalone --verbose_failures --test_output=errors -- //tensorflow_io/...
- name: "Ubuntu 14.04 Python 3.5"
dist: trusty
language: python
python:
- 3.5
before_install:
- sudo apt-get install -y -qq libav-tools
- bash -x ${TRAVIS_BUILD_DIR}/.travis/python.configure.sh
- pip install pyarrow==0.11.1
script:
- bazel test --show_progress=no -s --verbose_failures --test_output=errors -- //tensorflow_io/...
- language: python
- bazel test --noshow_progress --noshow_loading_progress --spawn_strategy standalone --verbose_failures --test_output=errors -- //tensorflow_io/...
- name: "Ubuntu 14.04 Python 3.6"
dist: trusty
language: python
python:
- 3.6
before_install:
- sudo apt-get install -y -qq libav-tools
- bash -x ${TRAVIS_BUILD_DIR}/.travis/python.configure.sh
- pip install pyarrow==0.11.1
script:
- bazel test --show_progress=no -s --verbose_failures --test_output=errors -- //tensorflow_io/...
- language: r
- bazel test --noshow_progress --noshow_loading_progress --spawn_strategy standalone --verbose_failures --test_output=errors -- //tensorflow_io/...
- name: "Ubuntu 16.04 Python 2.7 (Video Only)"
dist: xenial
language: python
python:
- 2.7
before_install:
- sudo apt-get install -y -qq libav-tools
- bash -x ${TRAVIS_BUILD_DIR}/.travis/python.configure.sh
script:
- bazel test --noshow_progress --noshow_loading_progress --spawn_strategy standalone --verbose_failures --test_output=errors -- //tensorflow_io/video:video_py_test
- name: "Ubuntu 16.04 Python 3.5 (Video Only)"
dist: xenial
language: python
python:
- 3.5
before_install:
- sudo apt-get install -y -qq libav-tools
- bash -x ${TRAVIS_BUILD_DIR}/.travis/python.configure.sh
script:
- bazel test --noshow_progress --noshow_loading_progress --spawn_strategy standalone --verbose_failures --test_output=errors -- //tensorflow_io/video:video_py_test
- name: "Ubuntu 18.04 Python 2.7 (Video Only)"
dist: trusty
language: python
python:
- 2.7
script:
- docker run -i -t -e PYTHON_VERSION= -e BAZEL_VERSION=0.20.0 -e BAZEL_OS=linux --rm -v $PWD:/workspace -w /workspace --net=host ubuntu:18.04 bash -x -c ".travis/python.ubuntu.18.04.sh && apt-get -y -qq install libavformat57 libavcodec57 libavutil55 libswscale4 && bazel test --noshow_progress --noshow_loading_progress --spawn_strategy standalone --verbose_failures -- //tensorflow_io/video:video_py_test"
- name: "Ubuntu 18.04 Python 3.6 (Video Only)"
dist: trusty
language: python
python:
- 3.6
script:
- docker run -i -t -e PYTHON_VERSION=3 -e BAZEL_VERSION=0.20.0 -e BAZEL_OS=linux --rm -v $PWD:/workspace -w /workspace --net=host ubuntu:18.04 bash -x -c ".travis/python.ubuntu.18.04.sh && apt-get -y -qq install libavformat57 libavcodec57 libavutil55 libswscale4 && bazel test --noshow_progress --noshow_loading_progress --spawn_strategy standalone --verbose_failures -- //tensorflow_io/video:video_py_test"
- name: "Ubuntu 14.04 R 3.2"
dist: trusty
language: r
r:
- 3.2
before_install:
- sudo apt-get install -y -qq libav-tools
- cd R-package
script:
- R -e "devtools::test()"
- language: r
- name: "Ubuntu 14.04 R 3.5"
dist: trusty
language: r
r:
- 3.5
before_install:
- sudo apt-get install -y -qq libav-tools
- cd R-package
script:
- R -e "devtools::test()"
Expand Down
20 changes: 20 additions & 0 deletions .travis/python.ubuntu.18.04.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set -x -e

# Test on Travis inside Ubuntu18.04 docker image
apt-get -y -qq update
apt-get -y -qq install python${PYTHON_VERSION}-pip curl wget unzip make
if [[ "" != "${PYTHON_VERSION}" ]]; then
ln -s /usr/bin/python${PYTHON_VERSION} /usr/bin/python
ln -s /usr/bin/pip${PYTHON_VERSION} /usr/bin/pip
fi
# Show gcc and python version in Travis CI
gcc -v
python --version
# Install bazel
URL="https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-${BAZEL_OS}-x86_64.sh"
wget -O install.sh "${URL}"
chmod +x install.sh
./install.sh
rm -f install.sh
# Configure TensorFlow
./configure.sh
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ sh_binary(
"//tensorflow_io/parquet:parquet_py",
"//tensorflow_io/libsvm:libsvm_py",
"//tensorflow_io/image:image_py",
"//tensorflow_io/video:video_py",
],
)
33 changes: 33 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,36 @@ http_archive(
sha256 = "12a13686cab7ffaf8ea01711b8f55e1dbd3bf059b7c46a25fefa1250bdd9dd23",
strip_prefix = "flatbuffers-b99332efd732e6faf60bb7ce1ce5902ed65d5ba3",
)

http_archive(
name = "ffmpeg_2_8",
urls = [
"https://mirror.bazel.build/github.com/FFmpeg/FFmpeg/archive/n2.8.15.tar.gz",
"https://github.com/FFmpeg/FFmpeg/archive/n2.8.15.tar.gz",
],
sha256 = "8ba1b91a14431fe37091936c3a34469d7473965ab9edde0343c88f2d920bd918",
strip_prefix = "FFmpeg-n2.8.15",
build_file = "//third_party:ffmpeg_2_8.BUILD",
)

http_archive(
name = "ffmpeg_3_4",
urls = [
"https://mirror.bazel.build/github.com/FFmpeg/FFmpeg/archive/n3.4.4.tar.gz",
"https://github.com/FFmpeg/FFmpeg/archive/n3.4.4.tar.gz",
],
sha256 = "bbccc87cd031498728bcc2dba5596a47e6fd92b2cec060a71feef65617a261fe",
strip_prefix = "FFmpeg-n3.4.4",
build_file = "//third_party:ffmpeg_3_4.BUILD",
)

http_archive(
name = "libav_9_20",
urls = [
"https://mirror.bazel.build/github.com/libav/libav/archive/v9.20.tar.gz",
"https://github.com/libav/libav/archive/v9.20.tar.gz",
],
sha256 = "ecc2389bc857602450196c9240e1ebc59066980f5d42e977efe0f498145775d4",
strip_prefix = "libav-9.20",
build_file = "//third_party:libav_9_20.BUILD",
)
2 changes: 1 addition & 1 deletion configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function write_action_env_to_bazelrc() {
write_to_bazelrc "build --action_env $1=\"$2\""
}

rm .bazelrc
rm -f .bazelrc
if python -c "import tensorflow" &> /dev/null; then
echo 'using installed tensorflow'
else
Expand Down
103 changes: 103 additions & 0 deletions tensorflow_io/video/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
licenses(["notice"]) # Apache 2.0

package(default_visibility = ["//visibility:public"])

filegroup(
name = "test_data",
srcs = glob(["python/kernel_tests/testdata/*"]),
)

cc_binary(
name = 'python/ops/_video_ops_ffmpeg_3.4.so',
srcs = [
"kernels/ffmpeg_3_4.cc",
"kernels/video_reader.h",
"kernels/video_dataset_ops.cc",
"ops/dataset_ops.cc",
],
includes = ["."],
linkshared = 1,
deps = [
"@local_config_tf//:libtensorflow_framework",
"@local_config_tf//:tf_header_lib",
"@ffmpeg_3_4//:ffmpeg",
],
copts = ["-pthread", "-std=c++11", "-D_GLIBCXX_USE_CXX11_ABI=0", "-DNDEBUG"]
)

cc_binary(
name = 'python/ops/_video_ops_ffmpeg_2.8.so',
srcs = [
"kernels/ffmpeg_2_8.cc",
"kernels/video_reader.h",
"kernels/video_dataset_ops.cc",
"ops/dataset_ops.cc",
],
includes = ["."],
linkshared = 1,
deps = [
"@local_config_tf//:libtensorflow_framework",
"@local_config_tf//:tf_header_lib",
"@ffmpeg_2_8//:ffmpeg",
],
copts = ["-pthread", "-std=c++11", "-D_GLIBCXX_USE_CXX11_ABI=0", "-DNDEBUG"]
)

cc_binary(
name = 'python/ops/_video_ops_libav_9.20.so',
srcs = [
"kernels/libav_9_20.cc",
"kernels/video_reader.h",
"kernels/video_dataset_ops.cc",
"ops/dataset_ops.cc",
],
includes = ["."],
linkshared = 1,
deps = [
"@local_config_tf//:libtensorflow_framework",
"@local_config_tf//:tf_header_lib",
"@libav_9_20//:libav",
],
copts = ["-pthread", "-std=c++11", "-D_GLIBCXX_USE_CXX11_ABI=0", "-DNDEBUG"]
)

py_library(
name = "video_ops_py",
srcs = ([
"python/ops/video_dataset_ops.py",
]),
data = [
":python/ops/_video_ops_ffmpeg_3.4.so",
":python/ops/_video_ops_ffmpeg_2.8.so",
":python/ops/_video_ops_libav_9.20.so",
],
srcs_version = "PY2AND3",
)

py_test(
name = "video_py_test",
srcs = [
"python/kernel_tests/video_test.py"
],
main = "python/kernel_tests/video_test.py",
data = [
":test_data",
],
deps = [
":video_ops_py",
],
srcs_version = "PY2AND3",
)

py_library(
name = "video_py",
srcs = ([
"__init__.py",
"python/__init__.py",
"python/ops/__init__.py",
]),
deps = [
":video_ops_py"
],
srcs_version = "PY2AND3",
)
32 changes: 32 additions & 0 deletions tensorflow_io/video/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# 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.
# ==============================================================================
"""Video Dataset.

@@VideoDataset
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorflow_io.video.python.ops.video_dataset_ops import VideoDataset

from tensorflow.python.util.all_util import remove_undocumented

_allowed_symbols = [
"VideoDataset",
]

remove_undocumented(__name__)
Loading