@@ -205,7 +205,7 @@ def _probe_video_from_file(filename):
205
205
206
206
207
207
def _read_video_from_memory (
208
- file_buffer ,
208
+ video_data ,
209
209
seek_frame_margin = 0.25 ,
210
210
read_video_stream = 1 ,
211
211
video_width = 0 ,
@@ -225,8 +225,8 @@ def _read_video_from_memory(
225
225
226
226
Args
227
227
----------
228
- file_buffer : buffer
229
- buffer of compressed video content
228
+ video_data : data type could be 1) torch.Tensor, dtype=torch.int8 or 2) python bytes
229
+ compressed video content stored in either 1) torch.Tensor 2) python bytes
230
230
seek_frame_margin: double, optional
231
231
seeking frame in the stream is imprecise. Thus, when video_start_pts is specified,
232
232
we seek the pts earlier by seek_frame_margin seconds
@@ -273,10 +273,11 @@ def _read_video_from_memory(
273
273
_validate_pts (video_pts_range )
274
274
_validate_pts (audio_pts_range )
275
275
276
- video_tensor = torch .from_numpy (np .frombuffer (file_buffer , dtype = np .uint8 ))
276
+ if not isinstance (video_data , torch .Tensor ):
277
+ video_data = torch .from_numpy (np .frombuffer (video_data , dtype = np .uint8 ))
277
278
278
279
result = torch .ops .video_reader .read_video_from_memory (
279
- video_tensor ,
280
+ video_data ,
280
281
seek_frame_margin ,
281
282
0 , # getPtsOnly
282
283
read_video_stream ,
@@ -305,16 +306,16 @@ def _read_video_from_memory(
305
306
return vframes , aframes , info
306
307
307
308
308
- def _read_video_timestamps_from_memory (file_buffer ):
309
+ def _read_video_timestamps_from_memory (video_data ):
309
310
"""
310
311
Decode all frames in the video. Only pts (presentation timestamp) is returned.
311
312
The actual frame pixel data is not copied. Thus, read_video_timestamps(...)
312
313
is much faster than read_video(...)
313
314
"""
314
-
315
- video_tensor = torch .from_numpy (np .frombuffer (file_buffer , dtype = np .uint8 ))
315
+ if not isinstance ( video_data , torch . Tensor ):
316
+ video_data = torch .from_numpy (np .frombuffer (video_data , dtype = np .uint8 ))
316
317
result = torch .ops .video_reader .read_video_from_memory (
317
- video_tensor ,
318
+ video_data ,
318
319
0 , # seek_frame_margin
319
320
1 , # getPtsOnly
320
321
1 , # read_video_stream
@@ -342,15 +343,16 @@ def _read_video_timestamps_from_memory(file_buffer):
342
343
return vframe_pts , aframe_pts , info
343
344
344
345
345
- def _probe_video_from_memory (file_buffer ):
346
+ def _probe_video_from_memory (video_data ):
346
347
"""
347
348
Probe a video in memory.
348
349
Return:
349
350
info [dict]: contain video meta information, including video_timebase,
350
351
video_duration, video_fps, audio_timebase, audio_duration, audio_sample_rate
351
352
"""
352
- video_tensor = torch .from_numpy (np .frombuffer (file_buffer , dtype = np .uint8 ))
353
- result = torch .ops .video_reader .probe_video_from_memory (video_tensor )
353
+ if not isinstance (video_data , torch .Tensor ):
354
+ video_data = torch .from_numpy (np .frombuffer (video_data , dtype = np .uint8 ))
355
+ result = torch .ops .video_reader .probe_video_from_memory (video_data )
354
356
vtimebase , vfps , vduration , atimebase , asample_rate , aduration = result
355
357
info = _fill_info (vtimebase , vfps , vduration , atimebase , asample_rate , aduration )
356
358
return info
0 commit comments