Search code examples
rffmpeg

Extract frames from a video (errors from using grabVideoStills and ffmpeg)


I'm attempting to extract frame-by-frame images from a set of videos. I've tried to do this using grabVideoStills and ffmpeg but I can't get either to work.

Here is my grabVideoStills command:

  grabVideoStills(
    01_H35_combined_small.mp4,
  imageDir = "C:/Users/pb/OneDrive/PD/MAG/split_stimuli",
  overWriteDir = FALSE,
  sampleWindow = 1
)

And I get the following error:

    imageDir = "C:/Users/pb/OneDrive/PD/MAG/split_stimuli",
Error: unexpected ',' in "imageDir = "C:/Users/pb/OneDrive/PD/MAG/split_stimuli","
>   overWriteDir = FALSE,
Error: unexpected ',' in "  overWriteDir = FALSE,"
>   sampleWindow = 1
> )
Error: unexpected ')' in ")"

Here is my ffmpeg command:

ffmpeg - i 01_H35_combined_small.mp4 %04d.png

And I get the following error message:

Error: unexpected numeric constant in "ffmpeg - i 01"

One thought I had about this error is that it doesn't like the number at the start of the filename, I've tried using quotation marks but it yields a similar error:

Error: unexpected string constant in "ffmpeg - i "01_H35_combined_small.mp4"" 

Any help would be greatly appreciated!


Solution

  • With the av package you can do:

    library(av)
    av_video_images("yourFile.mp4", destdir = "destinationFolder", format = "png")