Beispiel #1
0
def download_source_media(girder_client: GirderClient, datasetId: str,
                          dest: Path) -> Tuple[List[str], str]:
    """Download media for dataset to dest path"""
    media = models.DatasetSourceMedia(
        **girder_client.get(f'dive_dataset/{datasetId}/media'))
    dataset = models.GirderMetadataStatic(
        **girder_client.get(f'dive_dataset/{datasetId}'))
    if dataset.type == constants.ImageSequenceType:
        for frameImage in media.imageData:
            girder_client.downloadItem(frameImage.id, str(dest))
        return [str(dest / image.filename)
                for image in media.imageData], dataset.type
    elif dataset.type == constants.VideoType and media.video is not None:
        destination_path = str(dest / media.video.filename)
        girder_client.downloadFile(media.video.id, destination_path)
        return [destination_path], dataset.type
    else:
        raise Exception(f"unexpected metadata {str(dataset.dict())}")
Beispiel #2
0
def create_movie(id):
    token = request.headers.get('girderToken', '')
    if not token or not id:
        return Response('Invalid token or parameter ID.', status=400)

    gc = GirderClient(apiUrl=girder_url)
    gc.setToken(token)
    with tempfile.TemporaryDirectory() as tmpdir:
        gc.downloadItem(id, tmpdir)
        item_name = os.listdir(tmpdir)[0]
        path_name = os.path.join(tmpdir, item_name, '*.svg')
        output_file = tempfile.NamedTemporaryFile(suffix='.mp4')
        (ffmpeg
            .input(path_name, pattern_type='glob', framerate=10)
            .output(output_file.name)
            .overwrite_output()
            .run())

        return send_file(output_file, mimetype='mp4')