Skip to content

Commit 5fac290

Browse files
authored
Merge pull request #30 from yongtang/ffmpeg
Add FFmpeg support to open video files
2 parents 5c9e973 + 4da4dd2 commit 5fac290

22 files changed

+1403
-12
lines changed

.travis.yml

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
dist: trusty
21
sudo: required
32

3+
addons:
4+
apt:
5+
update: true
6+
47
env:
58
- BAZEL_OS=linux
69
BAZEL_VERSION=0.17.2
@@ -14,48 +17,100 @@ before_script:
1417

1518
matrix:
1619
include:
17-
- language: python
20+
- name: "Ubuntu 14.04 Python 2.7"
21+
dist: trusty
22+
language: python
1823
python:
1924
- 2.7
2025
before_install:
26+
- sudo apt-get install -y -qq libav-tools
2127
- bash -x ${TRAVIS_BUILD_DIR}/.travis/python.configure.sh
2228
- pip install pyarrow==0.11.1
2329
script:
24-
- bazel test --show_progress=no -s --verbose_failures --test_output=errors -- //tensorflow_io/...
25-
- language: python
30+
- bazel test --noshow_progress --noshow_loading_progress --spawn_strategy standalone --verbose_failures --test_output=errors -- //tensorflow_io/...
31+
- name: "Ubuntu 14.04 Python 3.4"
32+
dist: trusty
33+
language: python
2634
python:
2735
- 3.4
2836
before_install:
37+
- sudo apt-get install -y -qq libav-tools
2938
- bash -x ${TRAVIS_BUILD_DIR}/.travis/python.configure.sh
3039
script:
31-
- bazel test --show_progress=no -s --verbose_failures --test_output=errors -- //tensorflow_io/...
32-
- language: python
40+
- bazel test --noshow_progress --noshow_loading_progress --spawn_strategy standalone --verbose_failures --test_output=errors -- //tensorflow_io/...
41+
- name: "Ubuntu 14.04 Python 3.5"
42+
dist: trusty
43+
language: python
3344
python:
3445
- 3.5
3546
before_install:
47+
- sudo apt-get install -y -qq libav-tools
3648
- bash -x ${TRAVIS_BUILD_DIR}/.travis/python.configure.sh
3749
- pip install pyarrow==0.11.1
3850
script:
39-
- bazel test --show_progress=no -s --verbose_failures --test_output=errors -- //tensorflow_io/...
40-
- language: python
51+
- bazel test --noshow_progress --noshow_loading_progress --spawn_strategy standalone --verbose_failures --test_output=errors -- //tensorflow_io/...
52+
- name: "Ubuntu 14.04 Python 3.6"
53+
dist: trusty
54+
language: python
4155
python:
4256
- 3.6
4357
before_install:
58+
- sudo apt-get install -y -qq libav-tools
4459
- bash -x ${TRAVIS_BUILD_DIR}/.travis/python.configure.sh
4560
- pip install pyarrow==0.11.1
4661
script:
47-
- bazel test --show_progress=no -s --verbose_failures --test_output=errors -- //tensorflow_io/...
48-
- language: r
62+
- bazel test --noshow_progress --noshow_loading_progress --spawn_strategy standalone --verbose_failures --test_output=errors -- //tensorflow_io/...
63+
- name: "Ubuntu 16.04 Python 2.7 (Video Only)"
64+
dist: xenial
65+
language: python
66+
python:
67+
- 2.7
68+
before_install:
69+
- sudo apt-get install -y -qq libav-tools
70+
- bash -x ${TRAVIS_BUILD_DIR}/.travis/python.configure.sh
71+
script:
72+
- bazel test --noshow_progress --noshow_loading_progress --spawn_strategy standalone --verbose_failures --test_output=errors -- //tensorflow_io/video:video_py_test
73+
- name: "Ubuntu 16.04 Python 3.5 (Video Only)"
74+
dist: xenial
75+
language: python
76+
python:
77+
- 3.5
78+
before_install:
79+
- sudo apt-get install -y -qq libav-tools
80+
- bash -x ${TRAVIS_BUILD_DIR}/.travis/python.configure.sh
81+
script:
82+
- bazel test --noshow_progress --noshow_loading_progress --spawn_strategy standalone --verbose_failures --test_output=errors -- //tensorflow_io/video:video_py_test
83+
- name: "Ubuntu 18.04 Python 2.7 (Video Only)"
84+
dist: trusty
85+
language: python
86+
python:
87+
- 2.7
88+
script:
89+
- 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"
90+
- name: "Ubuntu 18.04 Python 3.6 (Video Only)"
91+
dist: trusty
92+
language: python
93+
python:
94+
- 3.6
95+
script:
96+
- 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"
97+
- name: "Ubuntu 14.04 R 3.2"
98+
dist: trusty
99+
language: r
49100
r:
50101
- 3.2
51102
before_install:
103+
- sudo apt-get install -y -qq libav-tools
52104
- cd R-package
53105
script:
54106
- R -e "devtools::test()"
55-
- language: r
107+
- name: "Ubuntu 14.04 R 3.5"
108+
dist: trusty
109+
language: r
56110
r:
57111
- 3.5
58112
before_install:
113+
- sudo apt-get install -y -qq libav-tools
59114
- cd R-package
60115
script:
61116
- R -e "devtools::test()"

.travis/python.ubuntu.18.04.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
set -x -e
2+
3+
# Test on Travis inside Ubuntu18.04 docker image
4+
apt-get -y -qq update
5+
apt-get -y -qq install python${PYTHON_VERSION}-pip curl wget unzip make
6+
if [[ "" != "${PYTHON_VERSION}" ]]; then
7+
ln -s /usr/bin/python${PYTHON_VERSION} /usr/bin/python
8+
ln -s /usr/bin/pip${PYTHON_VERSION} /usr/bin/pip
9+
fi
10+
# Show gcc and python version in Travis CI
11+
gcc -v
12+
python --version
13+
# Install bazel
14+
URL="https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-${BAZEL_OS}-x86_64.sh"
15+
wget -O install.sh "${URL}"
16+
chmod +x install.sh
17+
./install.sh
18+
rm -f install.sh
19+
# Configure TensorFlow
20+
./configure.sh

BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ sh_binary(
1313
"//tensorflow_io/parquet:parquet_py",
1414
"//tensorflow_io/libsvm:libsvm_py",
1515
"//tensorflow_io/image:image_py",
16+
"//tensorflow_io/video:video_py",
1617
],
1718
)

WORKSPACE

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,36 @@ http_archive(
144144
sha256 = "12a13686cab7ffaf8ea01711b8f55e1dbd3bf059b7c46a25fefa1250bdd9dd23",
145145
strip_prefix = "flatbuffers-b99332efd732e6faf60bb7ce1ce5902ed65d5ba3",
146146
)
147+
148+
http_archive(
149+
name = "ffmpeg_2_8",
150+
urls = [
151+
"https://mirror.bazel.build/github.com/FFmpeg/FFmpeg/archive/n2.8.15.tar.gz",
152+
"https://github.com/FFmpeg/FFmpeg/archive/n2.8.15.tar.gz",
153+
],
154+
sha256 = "8ba1b91a14431fe37091936c3a34469d7473965ab9edde0343c88f2d920bd918",
155+
strip_prefix = "FFmpeg-n2.8.15",
156+
build_file = "//third_party:ffmpeg_2_8.BUILD",
157+
)
158+
159+
http_archive(
160+
name = "ffmpeg_3_4",
161+
urls = [
162+
"https://mirror.bazel.build/github.com/FFmpeg/FFmpeg/archive/n3.4.4.tar.gz",
163+
"https://github.com/FFmpeg/FFmpeg/archive/n3.4.4.tar.gz",
164+
],
165+
sha256 = "bbccc87cd031498728bcc2dba5596a47e6fd92b2cec060a71feef65617a261fe",
166+
strip_prefix = "FFmpeg-n3.4.4",
167+
build_file = "//third_party:ffmpeg_3_4.BUILD",
168+
)
169+
170+
http_archive(
171+
name = "libav_9_20",
172+
urls = [
173+
"https://mirror.bazel.build/github.com/libav/libav/archive/v9.20.tar.gz",
174+
"https://github.com/libav/libav/archive/v9.20.tar.gz",
175+
],
176+
sha256 = "ecc2389bc857602450196c9240e1ebc59066980f5d42e977efe0f498145775d4",
177+
strip_prefix = "libav-9.20",
178+
build_file = "//third_party:libav_9_20.BUILD",
179+
)

configure.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function write_action_env_to_bazelrc() {
2121
write_to_bazelrc "build --action_env $1=\"$2\""
2222
}
2323

24-
rm .bazelrc
24+
rm -f .bazelrc
2525
if python -c "import tensorflow" &> /dev/null; then
2626
echo 'using installed tensorflow'
2727
else

tensorflow_io/video/BUILD

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
licenses(["notice"]) # Apache 2.0
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
filegroup(
6+
name = "test_data",
7+
srcs = glob(["python/kernel_tests/testdata/*"]),
8+
)
9+
10+
cc_binary(
11+
name = 'python/ops/_video_ops_ffmpeg_3.4.so',
12+
srcs = [
13+
"kernels/ffmpeg_3_4.cc",
14+
"kernels/video_reader.h",
15+
"kernels/video_dataset_ops.cc",
16+
"ops/dataset_ops.cc",
17+
],
18+
includes = ["."],
19+
linkshared = 1,
20+
deps = [
21+
"@local_config_tf//:libtensorflow_framework",
22+
"@local_config_tf//:tf_header_lib",
23+
"@ffmpeg_3_4//:ffmpeg",
24+
],
25+
copts = ["-pthread", "-std=c++11", "-D_GLIBCXX_USE_CXX11_ABI=0", "-DNDEBUG"]
26+
)
27+
28+
cc_binary(
29+
name = 'python/ops/_video_ops_ffmpeg_2.8.so',
30+
srcs = [
31+
"kernels/ffmpeg_2_8.cc",
32+
"kernels/video_reader.h",
33+
"kernels/video_dataset_ops.cc",
34+
"ops/dataset_ops.cc",
35+
],
36+
includes = ["."],
37+
linkshared = 1,
38+
deps = [
39+
"@local_config_tf//:libtensorflow_framework",
40+
"@local_config_tf//:tf_header_lib",
41+
"@ffmpeg_2_8//:ffmpeg",
42+
],
43+
copts = ["-pthread", "-std=c++11", "-D_GLIBCXX_USE_CXX11_ABI=0", "-DNDEBUG"]
44+
)
45+
46+
cc_binary(
47+
name = 'python/ops/_video_ops_libav_9.20.so',
48+
srcs = [
49+
"kernels/libav_9_20.cc",
50+
"kernels/video_reader.h",
51+
"kernels/video_dataset_ops.cc",
52+
"ops/dataset_ops.cc",
53+
],
54+
includes = ["."],
55+
linkshared = 1,
56+
deps = [
57+
"@local_config_tf//:libtensorflow_framework",
58+
"@local_config_tf//:tf_header_lib",
59+
"@libav_9_20//:libav",
60+
],
61+
copts = ["-pthread", "-std=c++11", "-D_GLIBCXX_USE_CXX11_ABI=0", "-DNDEBUG"]
62+
)
63+
64+
py_library(
65+
name = "video_ops_py",
66+
srcs = ([
67+
"python/ops/video_dataset_ops.py",
68+
]),
69+
data = [
70+
":python/ops/_video_ops_ffmpeg_3.4.so",
71+
":python/ops/_video_ops_ffmpeg_2.8.so",
72+
":python/ops/_video_ops_libav_9.20.so",
73+
],
74+
srcs_version = "PY2AND3",
75+
)
76+
77+
py_test(
78+
name = "video_py_test",
79+
srcs = [
80+
"python/kernel_tests/video_test.py"
81+
],
82+
main = "python/kernel_tests/video_test.py",
83+
data = [
84+
":test_data",
85+
],
86+
deps = [
87+
":video_ops_py",
88+
],
89+
srcs_version = "PY2AND3",
90+
)
91+
92+
py_library(
93+
name = "video_py",
94+
srcs = ([
95+
"__init__.py",
96+
"python/__init__.py",
97+
"python/ops/__init__.py",
98+
]),
99+
deps = [
100+
":video_ops_py"
101+
],
102+
srcs_version = "PY2AND3",
103+
)

tensorflow_io/video/__init__.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""Video Dataset.
16+
17+
@@VideoDataset
18+
"""
19+
20+
from __future__ import absolute_import
21+
from __future__ import division
22+
from __future__ import print_function
23+
24+
from tensorflow_io.video.python.ops.video_dataset_ops import VideoDataset
25+
26+
from tensorflow.python.util.all_util import remove_undocumented
27+
28+
_allowed_symbols = [
29+
"VideoDataset",
30+
]
31+
32+
remove_undocumented(__name__)

0 commit comments

Comments
 (0)