1 # Copyright 2016 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 """Tests for third_party.tensorflow.contrib.ffmpeg.decode_video_op.""" 16 17 from __future__ import absolute_import 18 from __future__ import division 19 from __future__ import print_function 20 21 import os.path 22 23 import six # pylint: disable=unused-import 24 25 from tensorflow.contrib import ffmpeg 26 from tensorflow.python.ops import image_ops 27 from tensorflow.python.platform import resource_loader 28 from tensorflow.python.platform import test 29 30 31 class DecodeVideoOpTest(test.TestCase): 32 33 def _loadFileAndTest(self, filename, width, height, frames, bmp_filename, 34 index): 35 """Loads an video file and validates the output tensor. 36 37 Args: 38 filename: The filename of the input file. 39 width: The width of the video. 40 height: The height of the video. 41 frames: The frames of the video. 42 bmp_filename: The filename for the bmp file. 43 index: Index location inside the video. 44 """ 45 with self.test_session(): 46 path = os.path.join(resource_loader.get_data_files_path(), 'testdata', 47 filename) 48 with open(path, 'rb') as f: 49 contents = f.read() 50 51 bmp_path = os.path.join(resource_loader.get_data_files_path(), 'testdata', 52 bmp_filename) 53 with open(bmp_path, 'rb') as f: 54 bmp_contents = f.read() 55 56 image_op = image_ops.decode_bmp(bmp_contents) 57 image = image_op.eval() 58 self.assertEqual(image.shape, (height, width, 3)) 59 video_op = ffmpeg.decode_video(contents) 60 video = video_op.eval() 61 self.assertEqual(video.shape, (frames, height, width, 3)) 62 self.assertAllEqual(video[index, :, :, :], image) 63 64 def testMp4(self): 65 self._loadFileAndTest('small.mp4', 560, 320, 166, 'small_100.bmp', 99) 66 67 68 if __name__ == '__main__': 69 test.main() 70