Skip to content
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

Add FFmpeg support to open video files #30

Merged
merged 19 commits into from
Jan 13, 2019
Merged

Conversation

yongtang
Copy link
Member

@yongtang yongtang commented Dec 16, 2018

This fix adds a preliminary video file support (VideoDataset) by linking and using FFmpeg's libraries.

The video.VideoDataset takes input of filename list, and generates outputs of RGB24 images (uint8) in (height, width, 3).

The reason to link against FFmpeg's libraries is because FFmpeg has a LGPL 2.1+ license.

On Ubuntu 18.04, FFmpeg libraries consists of:

  • libavformat.so.57
  • libavcodec.so.57
  • libavutil.so.55
  • libswscale.so.4

Because FFmpeg only guarantee's major version conpatibility, linking to a lower version (e.g., libavformat.so.54 on Ubuntu 14.04) may not work.

To support multiple versions of Ubuntu, multiple copies of header file combined with linking to different versions of .so might be needed.

It needs to be fully tested though and only limited major version should be supported.

At the moment, only ffmpeg libraries in Ubuntu 18.04 are used.
UPDATE:
At the moment, Ubuntu 14.04, 16.04, and 18.04 are all supported. We build 3 .so files and distributed at the same time:

  • _video_ops_ffmpeg_3.4.so (Ubuntu 18.04)
  • _video_ops_ffmpeg_2.8.so (Ubuntu 16.04)
  • _video_ops_libav_9.20.so (Ubuntu 14.04)

Additional platform could be added if there is enough need from the community.

To install required libraries on Ubuntu 18.04:

apt-get -y -qq install libavformat57 libavcodec57 libavutil55 libswscale4

To build the pip package:

bazel build -s --verbose_failures build_pip_pkg

NOTE: This PR fixed #11

Signed-off-by: Yong Tang [email protected]

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@googlebot
Copy link

CLAs look good, thanks!

# License for the specific language governing permissions and limitations under
# the License.
# ==============================================================================
"""Tests for SequenceFileDataset."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this to VideoDataset instead of SequenceFileDataset? Same for other places

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @terrytangyuan, the PR has been updated.

@yongtang yongtang force-pushed the ffmpeg branch 11 times, most recently from 272d247 to abadf38 Compare December 18, 2018 14:14
@yongtang yongtang changed the title [WIP] Add FFmpeg support to open video files Add FFmpeg support to open video files Dec 18, 2018
@yongtang
Copy link
Member Author

I think this PR is almost ready. I am working on adding Ubuntu 16.04 and 14.04 support (on top of 18.04 support that is already in place). Will update the PR shortly to completion.

@yongtang yongtang force-pushed the ffmpeg branch 2 times, most recently from a6c0ae3 to a928008 Compare December 18, 2018 23:10
@yongtang
Copy link
Member Author

I think this PR is ready. We support Ubuntu 14.04, 16.04, and 18.04 at the moment, with one distributed package in pip. Tests also pass on those platforms.

@martinwicke
Copy link
Member

This is a thing of beauty. I especially appreciate the multi-version tooling.

Since these are LGPL, we have to make sure to only release dynamically linked versions. Can we make sure (with a test/scripting) that this is always going ot be the case?

@yongtang
Copy link
Member Author

@martinwicke The library only uses header files from ffmpeg to compile and build. In Bazel there is a check-license option though I don't know how reliable it is. I think some additional tooling might be possible (maybe a module in bazel) to enforce only header files are included for LGPL types of libraries .

I will take a look at the license tooling issue.

@martinwicke
Copy link
Member

I think as long as we make sure all releases are built with dynamic linking, we should be ok.

This fix adds a preliminary video file support (`VideoDataset`)
by linking and using FFmpeg's libraries.

The `video.VideoDataset` takes input of filename list, and
generates outputs of RGB24 images (`uint8`) in `(height, width, 3)`.

The reason to link against FFmpeg's libraries is because
FFmpeg has a LGPL 2.1+ license.

On Ubuntu 18.04, FFmpeg libraries consists of:
```
libavformat.so.57
libavcodec.so.57
libavutil.so.55
libswscale.so.4
```

Because FFmpeg only guarantee's major version conpatibility,
linking to a lower version (e.g., libavformat.so.54 on Ubuntu 14.04)
may not work.

To support multiple versions of Ubuntu, multiple copies of header file
combined with linking to different versions of .so might be needed.

It needs to be fully tested though and only limited major version should
be supported.

At the moment, only ffmpeg libraries in Ubuntu 18.04 are used.
To install required libraries on Ubuntu 18.04:
```
apt-get -y -qq install libavformat57 libavcodec57 libavutil55 libswscale4
```
To build the pip package:
```
bazel build -s --verbose_failures build_pip_pkg
```

Signed-off-by: Yong Tang <[email protected]>
So that build could always succeed. In runtime system .so files will be used.

Signed-off-by: Yong Tang <[email protected]>
…ave Ubuntu 18.04 support directly.

Signed-off-by: Yong Tang <[email protected]>
Encountered quite some issues with
```
Use --sandbox_debug to see verbose messages from the sandbox
/usr/bin/ld.gold: error: cannot find libavformat.so.57
/usr/bin/ld.gold: error: cannot find libavcodec.so.57
/usr/bin/ld.gold: error: cannot find libavutil.so.55
/usr/bin/ld.gold: error: cannot find libswscale.so.4
collect2: error: ld returned 1 exit status
Target //tensorflow_io/video:video_py_test failed to build
```

Believe it is related to (or similiar):
https://stackoverflow.com/questions/52386530/linker-fails-in-sandbox-when-running-through-bazel-but-works-when-sandboxed-comm?rq=1

Signed-off-by: Yong Tang <[email protected]>
(By default Travis CI uses Ruby)

Signed-off-by: Yong Tang <[email protected]>
…brary

and use `cc_import_library` rule to prevent including GPL code.

Signed-off-by: Yong Tang <[email protected]>
@yongtang
Copy link
Member Author

yongtang commented Jan 8, 2019

@terrytangyuan @martinwicke The PR has been updated.

I added a customized implementation of bazel rule def (cc_import_library) which controls the dependency so that library will only be linked to, and no source files (like GPL) are included or compiled.

It is pretty much similar to cc_import in Bazel's standard rule, except that cc_import does not support .so with soname. I created an issue in bazel repo: bazelbuild/bazel#7059

I think this FFmpeg PR is ready, please take a look and let me know if there are any issues.

Copy link
Member

@terrytangyuan terrytangyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yongtang
Copy link
Member Author

Thanks. Will merge this PR in, and have a follow up PR with an example.

@yongtang yongtang merged commit 5fac290 into tensorflow:master Jan 13, 2019
@yongtang yongtang deleted the ffmpeg branch January 13, 2019 17:49
yongtang pushed a commit that referenced this pull request Jan 27, 2022
* feat: reading from bigtable (#2)

Implements reading from bigtable in a synchronous manner.

* feat: RowRange and RowSet API.

* feat: parallel read (#4)

In this pr we make the read methods accept a row_set reading only rows specified by the user.
We also add a parallel read, that leverages the sample_row_keys method to split work among workers.

* feat: version filters (#6)

This PR adds support for Bigtable version filters.

* feat: support for other data types (#5)

* fix: linter fixes (#8)

* feat docs (#9)

* fix: building on windows (#12)

* fix: refactor bigtable package to api folder (#14)

moved bigtable to tfensorflow_io.python.api

* fix: tests hanging (#30)

changed path to bigtable emulator and cbt in tests

moved arguments' initializations to the body of the function in bigtable_ops.py

 fixed interleaveFromRange of column filters when using only one column

* fix: temporarily disable macos tests (#32)

* disable tests on macos

Co-authored-by: Kajetan Boroszko <[email protected]>
Co-authored-by: Kajetan Boroszko <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support video format for tensorflow-io
4 participants