Skip to content

Commit cb544c2

Browse files
committed
Merge branch 'main' of github.com:pytorch/torchcodec into file_like_tutorial
2 parents 91128ac + e70a98b commit cb544c2

File tree

2 files changed

+51
-16
lines changed

2 files changed

+51
-16
lines changed

packaging/post_build_script.sh

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,14 @@ assert_not_in_wheel $wheel_path "^doc"
3737
assert_not_in_wheel $wheel_path "^benchmarks"
3838
assert_not_in_wheel $wheel_path "^packaging"
3939

40-
if [[ "$unamestr" == 'Linux' ]]; then
41-
# TODO: Put this back with higher upper bound of version symbol.
42-
# # See invoked python script below for details about this check.
43-
# extracted_wheel_dir=$(mktemp -d)
44-
# unzip -q $wheel_path -d $extracted_wheel_dir
45-
# symbols_matches=$(find $extracted_wheel_dir | grep ".so$" | xargs objdump --syms | grep GLIBCXX_3.4.)
46-
# python packaging/check_glibcxx.py "$symbols_matches"
47-
48-
echo "ls dist"
49-
ls dist
50-
51-
old="linux_x86_64"
52-
new="manylinux_2_17_x86_64.manylinux2014_x86_64"
53-
echo "Replacing ${old} with ${new} in wheel name"
54-
mv dist/*${old}*.whl $(echo dist/*${old}*.whl | sed "s/${old}/${new}/")
55-
fi
40+
# TODO: Put this back with higher upper bound of version symbol.
41+
#if [[ "$unamestr" == 'Linux' ]]; then
42+
# # See invoked python script below for details about this check.
43+
# extracted_wheel_dir=$(mktemp -d)
44+
# unzip -q $wheel_path -d $extracted_wheel_dir
45+
# symbols_matches=$(find $extracted_wheel_dir | grep ".so$" | xargs objdump --syms | grep GLIBCXX_3.4.)
46+
# python packaging/check_glibcxx.py "$symbols_matches"
47+
#fi
5648

5749
echo "ls dist"
5850
ls dist

test/test_ops.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,49 @@ def seek(self, offset: int, whence: int) -> bytes:
10701070
"approximate",
10711071
)
10721072

1073+
@pytest.mark.parametrize("how_much_to_read", ("half", "minus_10"))
1074+
def test_file_like_read_less_than_requested(self, how_much_to_read):
1075+
# Check that reading fewer bytes than requested still works. FFmpeg will
1076+
# figure out how to get the necessary bytes.
1077+
class FileLike:
1078+
def __init__(self, file):
1079+
self._file = file
1080+
1081+
def read(self, size: int) -> bytes:
1082+
if how_much_to_read == "half":
1083+
size = size // 2
1084+
elif how_much_to_read == "minus_10":
1085+
size = size - 10
1086+
else:
1087+
raise ValueError("Check parametrization of this test!")
1088+
1089+
return self._file.read(size)
1090+
1091+
def seek(self, offset: int, whence: int) -> bytes:
1092+
return self._file.seek(offset, whence)
1093+
1094+
decoder_file_like = create_from_file_like(
1095+
FileLike(open(NASA_VIDEO.path, mode="rb", buffering=0))
1096+
)
1097+
add_video_stream(decoder_file_like)
1098+
1099+
decoder_reference = create_from_file(str(NASA_VIDEO.path))
1100+
add_video_stream(decoder_reference)
1101+
1102+
torch.manual_seed(0)
1103+
indices = torch.randint(
1104+
0, len(NASA_VIDEO.frames[NASA_VIDEO.default_stream_index]), size=(50,)
1105+
).tolist()
1106+
1107+
frames_file_like, *_ = get_frames_at_indices(
1108+
decoder_file_like, frame_indices=indices
1109+
)
1110+
frames_references, *_ = get_frames_at_indices(
1111+
decoder_reference, frame_indices=indices
1112+
)
1113+
1114+
torch.testing.assert_close(frames_file_like, frames_references)
1115+
10731116

10741117
class TestAudioEncoderOps:
10751118

0 commit comments

Comments
 (0)