Skip to content

Commit 261a5c3

Browse files
authored
Add ffmpeg support for Ubuntu 20.04 and switch to python 3.8 for tests (tensorflow#1195)
* Add ffmpeg support for Ubuntu 20.04 In the past only Ubuntu 16.04 and 18.04 are supported for ffmpeg audio/video Dataset. In this PR ffmpeg support for Ubuntu 20.04 has been added as Ubuntu 20.04 has been released this year. Also fix `Invalid return value 0 for stream protocol` issue when LIBAVFORMAT_VERSION_MAJOR > 57 Signed-off-by: Yong Tang <[email protected]> * Switch to python 3.8 for tests In the past we use python 3.6/3.7 as the default version for testing as some packages for testing are not available for 3.8 yet, even though many python systems have been upgraded to 3.8. For example, Ubuntu 20.04 and macOS's default system pythons are already 3.8. This PR switches to use python 3.8 for testings. This should also reduce GitHub Actions jobs a little bit. This PR also updates ffmpeg video samples (as there is a small different between Ubuntu 18.04 and Ubuntu 20.04 ffmpeg) Signed-off-by: Yong Tang <[email protected]> * Add python3.7 test back, based on review comment Signed-off-by: Yong Tang <[email protected]>
1 parent 32ee516 commit 261a5c3

File tree

12 files changed

+134
-22
lines changed

12 files changed

+134
-22
lines changed

.github/workflows/build.wheel.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ run_test() {
66
entry=$1
77
CPYTHON_VERSION=$($entry -c 'import sys; print(str(sys.version_info[0])+str(sys.version_info[1]))')
88
(cd wheelhouse && $entry -m pip install tensorflow_io-*-cp${CPYTHON_VERSION}-*.whl)
9-
$entry -m pip install -q pytest pytest-benchmark boto3 fastavro avro-python3 scikit-image pyarrow==0.16.0 pandas==0.24.2 google-cloud-pubsub==2.1.0 google-cloud-bigquery-storage==1.1.0 google-cloud-bigquery==2.3.1 google-cloud-storage==1.32.0
9+
$entry -m pip install -q pytest pytest-benchmark boto3 fastavro avro-python3 scikit-image pandas pyarrow==0.16.0 google-cloud-pubsub==2.1.0 google-cloud-bigquery-storage==1.1.0 google-cloud-bigquery==2.3.1 google-cloud-storage==1.32.0
1010
(cd tests && $entry -m pytest --benchmark-disable -v --import-mode=append $(find . -type f \( -iname "test_*.py" ! \( -iname "test_*_eager.py" \) \)))
1111
(cd tests && $entry -m pytest --benchmark-disable -v --import-mode=append $(find . -type f \( -iname "test_*_eager.py" ! \( -iname "test_bigquery_eager.py" \) \)))
1212
# GRPC and test_bigquery_eager tests have to be executed separately because of https://github.com/grpc/grpc/issues/20034
@@ -19,11 +19,6 @@ if [[ "$#" -gt 0 ]]; then
1919
shift
2020
fi
2121

22-
if [[ "$PYTHON_VERSION" == "python3.8" ]]; then
23-
echo "TODO: Python 3.8 test is not supported yet as dependency might not be available"
24-
exit 0
25-
fi
26-
2722
if [[ $(uname) == "Linux" ]]; then
2823
apt-get -y -qq update
2924
if [[ "${PYTHON_VERSION}" == "python3.7" ]]; then

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ jobs:
179179
runs-on: macos-latest
180180
strategy:
181181
matrix:
182-
python: ['3.6', '3.7']
182+
python: ['3.7', '3.8']
183183
steps:
184184
- uses: actions/checkout@v2
185185
- uses: docker-practice/actions-setup-docker@v1
@@ -276,10 +276,10 @@ jobs:
276276
strategy:
277277
matrix:
278278
os: [ubuntu-18.04, ubuntu-20.04]
279-
python: ['3.6', '3.7']
279+
python: ['3.7', '3.8']
280280
exclude:
281-
- os: ubuntu-20.04
282-
python: '3.6'
281+
- os: ubuntu-18.04
282+
python: '3.8'
283283
- os: ubuntu-20.04
284284
python: '3.7'
285285
steps:
@@ -375,7 +375,7 @@ jobs:
375375
runs-on: windows-latest
376376
strategy:
377377
matrix:
378-
python: ['3.6', '3.7']
378+
python: ['3.7', '3.8']
379379
steps:
380380
- uses: actions/checkout@v2
381381
- uses: actions/download-artifact@v1

.kokorun/io_cpu.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ python --version
4545
python -m pip --version
4646
docker --version
4747

48-
export PYTHON_VERSION=3.7
48+
export PYTHON_VERSION=3.8
4949

5050
export BAZEL_VERSION=$(cat .bazelversion)
5151
export BAZEL_OPTIMIZATION="--copt=-msse4.2 --copt=-mavx --compilation_mode=opt"
@@ -81,7 +81,7 @@ bash -x -e tests/test_sql/sql_test.sh sql
8181
bash -x -e tests/test_elasticsearch/elasticsearch_test.sh start
8282

8383
docker run -i --rm -v $PWD:/v -w /v --net=host \
84-
buildpack-deps:18.04 bash -x -e .github/workflows/build.wheel.sh python${PYTHON_VERSION}
84+
buildpack-deps:20.04 bash -x -e .github/workflows/build.wheel.sh python${PYTHON_VERSION}
8585

8686
## In case there are any files generated by docker with root user
8787
sudo chown -R $(id -nu):$(id -ng) .

WORKSPACE

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,17 @@ http_archive(
478478
],
479479
)
480480

481+
http_archive(
482+
name = "ffmpeg_4_2",
483+
build_file = "//third_party:ffmpeg_4_2.BUILD",
484+
sha256 = "42f3d391dbf07b65a52d3d9eed8038ecd9fae53cf4e0e44e2adb95d0cd433b53",
485+
strip_prefix = "FFmpeg-n4.2.4",
486+
urls = [
487+
"https://storage.googleapis.com/mirror.tensorflow.org/github.com/FFmpeg/FFmpeg/archive/n4.2.4.tar.gz",
488+
"https://github.com/FFmpeg/FFmpeg/archive/n4.2.4.tar.gz",
489+
],
490+
)
491+
481492
http_archive(
482493
name = "rules_python",
483494
sha256 = "c911dc70f62f507f3a361cbc21d6e0d502b91254382255309bc60b7a0f48de28",

tensorflow_io/core/BUILD

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,23 @@ cc_library(
298298
alwayslink = 1,
299299
)
300300

301+
cc_library(
302+
name = "ffmpeg_4.2_ops",
303+
srcs = [
304+
"kernels/audio_ffmpeg_kernels.cc",
305+
"kernels/ffmpeg_kernels.cc",
306+
"kernels/ffmpeg_kernels_deprecated.cc",
307+
"ops/ffmpeg_ops.cc",
308+
],
309+
copts = tf_io_copts(),
310+
linkstatic = True,
311+
deps = [
312+
"//tensorflow_io/core:dataset_ops",
313+
"@ffmpeg_4_2//:ffmpeg",
314+
],
315+
alwayslink = 1,
316+
)
317+
301318
cc_library(
302319
name = "ffmpeg_3.4_ops",
303320
srcs = [
@@ -714,6 +731,15 @@ cc_binary(
714731
],
715732
)
716733

734+
cc_binary(
735+
name = "python/ops/libtensorflow_io_ffmpeg_4.2.so",
736+
copts = tf_io_copts(),
737+
linkshared = 1,
738+
deps = [
739+
"//tensorflow_io/core:ffmpeg_4.2_ops",
740+
],
741+
)
742+
717743
cc_binary(
718744
name = "python/ops/libtensorflow_io_ffmpeg_3.4.so",
719745
copts = tf_io_copts(),

tensorflow_io/core/kernels/audio_ffmpeg_kernels.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,19 @@ class EncodeAACFunctionState {
217217
av_frame_free(&p);
218218
}
219219
}) {
220+
int channel_layout = 0;
221+
switch (channels) {
222+
case 1:
223+
channel_layout = AV_CH_LAYOUT_MONO;
224+
break;
225+
case 2:
226+
channel_layout = AV_CH_LAYOUT_STEREO;
227+
break;
228+
default:
229+
LOG(INFO) << "aac codec does not support channels = " << channels
230+
<< " yet";
231+
return;
232+
}
220233
codec_ = avcodec_find_encoder(AV_CODEC_ID_AAC);
221234
if (codec_ != nullptr) {
222235
AVCodecContext* codec_context = avcodec_alloc_context3(codec_);
@@ -232,6 +245,7 @@ class EncodeAACFunctionState {
232245
if (*p == AV_SAMPLE_FMT_FLTP) {
233246
codec_context->sample_rate = rate;
234247
codec_context->channels = channels;
248+
codec_context->channel_layout = channel_layout;
235249
codec_context->sample_fmt = AV_SAMPLE_FMT_FLTP;
236250
if (avcodec_open2(codec_context, codec_, NULL) >= 0) {
237251
LOG(INFO) << "aac codec opened successfully";

tensorflow_io/core/kernels/ffmpeg_kernels.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ class FFmpegStream {
164164
return -1;
165165
}
166166
r->offset_ += result.size();
167+
#if LIBAVFORMAT_VERSION_MAJOR > 57
168+
if (result.size() == 0) {
169+
return AVERROR_EOF;
170+
}
171+
#endif
167172
return result.size();
168173
}
169174

tensorflow_io/core/kernels/ffmpeg_kernels_deprecated.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ class FFmpegReadStream {
140140
return -1;
141141
}
142142
r->offset_ += result.size();
143+
#if LIBAVFORMAT_VERSION_MAJOR > 57
144+
if (result.size() == 0) {
145+
return AVERROR_EOF;
146+
}
147+
#endif
143148
return result.size();
144149
}
145150

tensorflow_io/core/python/ops/ffmpeg_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def _load_dependency_and_library(p):
4747

4848
_ffmpeg_ops, _decode_ops = _load_dependency_and_library(
4949
{
50+
"libtensorflow_io_ffmpeg_4.2.so": ["libavformat.so.58", "libswscale.so.5",],
5051
"libtensorflow_io_ffmpeg_3.4.so": [
51-
"libavformat.so.57",
5252
"libavformat.so.57",
5353
"libavutil.so.55",
5454
"libswscale.so.4",
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)