def __init__(self, filename, internal=False): with tf.name_scope("FFmpegIOTensor") as scope: from tensorflow_io.core.python.ops import ( # pylint: disable=import-outside-toplevel ffmpeg_ops, ) resource, columns = ffmpeg_ops.io_ffmpeg_readable_init( filename, container=scope, shared_name="{}/{}".format(filename, uuid.uuid4().hex), ) columns = [column.decode() for column in columns.numpy().tolist()] elements = [] for column in columns: shape, dtype, rate = ffmpeg_ops.io_ffmpeg_readable_spec( resource, column) shape = tf.TensorShape( [None if e < 0 else e for e in shape.numpy()]) dtype = tf.as_dtype(dtype.numpy()) spec = tf.TensorSpec(shape, dtype, column) capacity = 1 if column.startswith("v:") else 4096 function = _FFmpegIOTensorFunction( ffmpeg_ops.io_ffmpeg_readable_read, resource, column, shape, dtype, capacity=capacity, ) function = io_tensor_ops._IOTensorIterablePartitionedFunction( # pylint: disable=protected-access function, shape) if column.startswith("v:"): elements.append( FFmpegVideoIOTensor(spec, function, internal=internal)) elif column.startswith("a:"): rate = rate.numpy() elements.append( FFmpegAudioIOTensor(spec, function, rate, internal=internal)) else: elements.append( FFmpegSubtitleIOTensor(spec, function, internal=internal)) spec = tuple([e.spec for e in elements]) super().__init__(spec, columns, elements, internal=internal)
def __init__(self, filename, stream, internal=True): """FFmpegIODataset.""" with tf.name_scope("FFmpegIODataset") as scope: from tensorflow_io.core.python.ops import ffmpeg_ops # pylint: disable=import-outside-toplevel resource, _ = ffmpeg_ops.io_ffmpeg_readable_init( filename, container=scope, shared_name="%s/%s" % (filename, uuid.uuid4().hex)) shape, dtype, _ = ffmpeg_ops.io_ffmpeg_readable_spec( resource, stream) shape = tf.TensorShape( [None if e < 0 else e for e in shape.numpy()]) dtype = tf.as_dtype(dtype.numpy()) capacity = 1 if stream.startswith("v:") else 4096 super(FFmpegIODataset, self).__init__(_FFmpegIODatasetFunction( ffmpeg_ops.io_ffmpeg_readable_read, resource, stream, shape, dtype), capacity=capacity, internal=internal)