Skip to content

Commit

Permalink
[fbsync] Fix test_write_video_with_audio.. again (#8558)
Browse files Browse the repository at this point in the history
Reviewed By: vmoens

Differential Revision: D60596222

fbshipit-source-id: 90d0c22e234207037443db405e0bed50aef66e96
  • Loading branch information
NicolasHug authored and facebook-github-bot committed Aug 2, 2024
1 parent 16413b1 commit 04ce704
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
7 changes: 2 additions & 5 deletions test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,14 @@ def test_write_video_with_audio(self, device, tmpdir):
f_name = os.path.join(VIDEO_DIR, "R6llTwEh07w.mp4")
video_tensor, audio_tensor, info = io.read_video(f_name, pts_unit="sec")

video_tensor = video_tensor.to(device)
audio_tensor = audio_tensor.to(device)

out_f_name = os.path.join(tmpdir, "testing.mp4")
io.video.write_video(
out_f_name,
video_tensor,
video_tensor.to(device),
round(info["video_fps"]),
video_codec="libx264rgb",
options={"crf": "0"},
audio_array=audio_tensor,
audio_array=audio_tensor.to(device),
audio_fps=info["audio_fps"],
audio_codec="aac",
)
Expand Down
2 changes: 1 addition & 1 deletion torchvision/datasets/kinetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .vision import VisionDataset


def _dl_wrap(tarpath: Union[str, Path], videopath: Union[str, Path], line: str) -> None:
def _dl_wrap(tarpath: Union[str, Path], videopath: Union[str, Path], line: str) -> None:
download_and_extract_archive(line, tarpath, videopath)


Expand Down
2 changes: 1 addition & 1 deletion torchvision/io/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def write_video(
audio_sample_fmt = container.streams.audio[0].format.name

format_dtype = np.dtype(audio_format_dtypes[audio_sample_fmt])
audio_array = torch.as_tensor(audio_array).numpy().astype(format_dtype)
audio_array = torch.as_tensor(audio_array).numpy(force=True).astype(format_dtype)

frame = av.AudioFrame.from_ndarray(audio_array, format=audio_sample_fmt, layout=audio_layout)

Expand Down

0 comments on commit 04ce704

Please sign in to comment.