MCPcopy Create free account
hub / github.com/DeepLabCut/DeepLabCut / CropVideo

Function CropVideo

deeplabcut/utils/auxfun_videos.py:428–493  ·  view source on GitHub ↗

Auxiliary function to crop a video and output it to the same folder with "outsuffix" appended in its name. Width and height will control the new dimensions. Returns the full path to the downsampled video! ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4 Parameter ----

(
    vname,
    width=256,
    height=256,
    origin_x=0,
    origin_y=0,
    outsuffix="cropped",
    outpath=None,
    useGUI=False,
)

Source from the content-addressed store, hash-verified

426
427
428def CropVideo(
429 vname,
430 width=256,
431 height=256,
432 origin_x=0,
433 origin_y=0,
434 outsuffix="cropped",
435 outpath=None,
436 useGUI=False,
437):
438 """Auxiliary function to crop a video and output it to the same folder with
439 "outsuffix" appended in its name. Width and height will control the new dimensions.
440
441 Returns the full path to the downsampled video!
442
443 ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4
444
445 Parameter
446 ----------
447 vname : string
448 A string containing the full path of the video.
449
450 width: int
451 width of output video
452
453 height: int
454 height of output video.
455
456 origin_x, origin_y: int
457 x- and y- axis origin of bounding box for cropping.
458
459 outsuffix: str
460 Suffix for output videoname (see example).
461
462 outpath: str
463 Output path for saving video to (by default will be the same folder as the video)
464
465 Examples
466 ----------
467
468 Linux/MacOs
469 >>> deeplabcut.CropVideo('/data/videos/mouse1.avi')
470
471 Crops the video using default values and saves it in /data/videos as mouse1cropped.avi
472
473 Windows:
474 >>> =deeplabcut.CropVideo('C:\\yourusername\\rig-95\\Videos\\reachingvideo1.avi',
475 ... width=220,height=320,outsuffix='cropped')
476
477 Crops the video to a width of 220 and height of 320 starting at the origin (top left)
478 and saves it in C:\\yourusername\\rig-95\\Videos as reachingvideo1cropped.avi
479 """
480 writer = VideoWriter(vname)
481
482 if useGUI:
483 print("Please, select your coordinates (draw from top left to bottom right ...)")
484 coords = draw_bbox(vname)
485

Callers

nothing calls this directly

Calls 4

cropMethod · 0.95
VideoWriterClass · 0.85
draw_bboxFunction · 0.85
set_bboxMethod · 0.80

Tested by

no test coverage detected