{
  "id": 124099,
  "title": "Reading a specific frame in a training video using OpenCv in Python",
  "url": "/competitions/deepfake-detection-challenge/discussion/124099",
  "author_name": "",
  "post_date": "2020-01-02T02:14:38.836059400Z",
  "votes": 12,
  "comment_count": 7,
  "views": 0,
  "content": "<p>@all:</p>\n\n<p>I thought this would be helpful to read a specific frame from training videos:</p>\n\n<p><a href=\"https://stackoverflow.com/questions/33650974/opencv-python-read-specific-frame-using-videocapture\">https://stackoverflow.com/questions/33650974/opencv-python-read-specific-frame-using-videocapture</a></p>\n\n<hr>\n\n<p>By JParrish88 @StackOverflow:\nIf you want an exact frame, you could just set the VideoCapture session to that frame. It's much more intuitive to automatically call on that frame. The \"correct\" solution requires you to input known data: like fps, length, and whatnot. All you need to know with the code below is the frame you want to call.</p>\n\n<p><code>\nimport numpy as np\nimport cv2\ncap = cv2.VideoCapture(video_name) #video_name is the video being called\ncap.set(1,frame_no); # Where frame_no is the frame you want\nret, frame = cap.read() # Read the frame\ncv2.imshow('window_name', frame) # show frame on window\n</code></p>",
  "messages": [
    {
      "id": "708109",
      "postDate": "01/02/2020 02:14:38",
      "content": "<p>@all:</p>\n\n<p>I thought this would be helpful to read a specific frame from training videos:</p>\n\n<p><a href=\"https://stackoverflow.com/questions/33650974/opencv-python-read-specific-frame-using-videocapture\">https://stackoverflow.com/questions/33650974/opencv-python-read-specific-frame-using-videocapture</a></p>\n\n<hr>\n\n<p>By JParrish88 @StackOverflow:\nIf you want an exact frame, you could just set the VideoCapture session to that frame. It's much more intuitive to automatically call on that frame. The \"correct\" solution requires you to input known data: like fps, length, and whatnot. All you need to know with the code below is the frame you want to call.</p>\n\n<p><code>\nimport numpy as np\nimport cv2\ncap = cv2.VideoCapture(video_name) #video_name is the video being called\ncap.set(1,frame_no); # Where frame_no is the frame you want\nret, frame = cap.read() # Read the frame\ncv2.imshow('window_name', frame) # show frame on window\n</code></p>",
      "rawMarkdown": "all:\n\nI thought this would be helpful to read a specific frame from training videos:\n\nhttps://stackoverflow.com/questions/33650974/opencv-python-read-specific-frame-using-videocapture\n\n---\nBy JParrish88 @StackOverflow:\nIf you want an exact frame, you could just set the VideoCapture session to that frame. It's much more intuitive to automatically call on that frame. The \"correct\" solution requires you to input known data: like fps, length, and whatnot. All you need to know with the code below is the frame you want to call.\n\n```\nimport numpy as np\nimport cv2\ncap = cv2.VideoCapture(video_name) #video_name is the video being called\ncap.set(1,frame_no); # Where frame_no is the frame you want\nret, frame = cap.read() # Read the frame\ncv2.imshow('window_name', frame) # show frame on window\n```",
      "votes": null
    },
    {
      "id": "708173",
      "postDate": "01/02/2020 03:32:35",
      "content": "<p>amazing work! Thanks for the excellent kernel</p>",
      "rawMarkdown": "amazing work! Thanks for the excellent kernel",
      "votes": null
    },
    {
      "id": "708224",
      "postDate": "01/02/2020 05:11:07",
      "content": "<p>Have you checked how this does in terms of speed?</p>",
      "rawMarkdown": "Have you checked how this does in terms of speed?",
      "votes": null
    },
    {
      "id": "708257",
      "postDate": "01/02/2020 05:56:14",
      "content": "<p>I haven't checked that yet! My 'only' machine is busy running some computations, maybe will test it by tomorrow!</p>",
      "rawMarkdown": "I haven't checked that yet! My 'only' machine is busy running some computations, maybe will test it by tomorrow!",
      "votes": null
    },
    {
      "id": "708327",
      "postDate": "01/02/2020 07:37:27",
      "content": "<p>Did a quick test and added a notebook: 2-ways-to-read-a-single-video-frame. <a href=\"https://www.kaggle.com/debanga/2-ways-to-read-a-single-video-frame\">https://www.kaggle.com/debanga/2-ways-to-read-a-single-video-frame</a></p>",
      "rawMarkdown": "Did a quick test and added a notebook: 2-ways-to-read-a-single-video-frame. https://www.kaggle.com/debanga/2-ways-to-read-a-single-video-frame",
      "votes": null
    },
    {
      "id": "708477",
      "postDate": "01/02/2020 10:38:31",
      "content": "<p>I did a similar test <a href=\"https://www.kaggle.com/humananalog/video-speed-test\">in this kernel</a>. If you need to extract several frames from the video, this method is significantly slower than reading the frames one-by-one. (If you just need one or two frames, this method is likely faster.)</p>",
      "rawMarkdown": "I did a similar test [in this kernel](https://www.kaggle.com/humananalog/video-speed-test). If you need to extract several frames from the video, this method is significantly slower than reading the frames one-by-one. (If you just need one or two frames, this method is likely faster.)",
      "votes": null
    },
    {
      "id": "708635",
      "postDate": "01/02/2020 13:56:04",
      "content": "<p><a href=\"/humananalog\">@humananalog</a> Thanks for pointing it out: </p>\n\n<h3>@   everyone</h3>\n\n<p>I just want to clarify here that this method is efficient for reading a 'single' frame. If you need multiple continuous frames,  this may not be the optimum way and may consider following this kernel: <a href=\"https://www.kaggle.com/humananalog/video-speed-test\">https://www.kaggle.com/humananalog/video-speed-test</a>. Please share your experience.</p>",
      "rawMarkdown": "humananalog Thanks for pointing it out: \n\n### @   everyone\nI just want to clarify here that this method is efficient for reading a 'single' frame. If you need multiple continuous frames,  this may not be the optimum way and may consider following this kernel: https://www.kaggle.com/humananalog/video-speed-test. Please share your experience.",
      "votes": null
    },
    {
      "id": "710363",
      "postDate": "01/04/2020 16:33:04",
      "content": "<p>Problem is: the read() method is leaking memory as the release() method does not work on the implementation offered by Kaggle (this is a known cv2 bug which apparently was never fixed). \nYou’ll run into RAM issues if you call read() too often...</p>",
      "rawMarkdown": "Problem is: the read() method is leaking memory as the release() method does not work on the implementation offered by Kaggle (this is a known cv2 bug which apparently was never fixed). \nYou’ll run into RAM issues if you call read() too often...",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 708173,
      "author_name": "ahmedsmara",
      "author_url": "",
      "post_date": "01/02/2020 03:32:35",
      "content": "<p>amazing work! Thanks for the excellent kernel</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 708224,
      "author_name": "ryches",
      "author_url": "",
      "post_date": "01/02/2020 05:11:07",
      "content": "<p>Have you checked how this does in terms of speed?</p>",
      "votes": null,
      "replies": [
        {
          "id": 708257,
          "author_name": "debanga",
          "author_url": "",
          "post_date": "01/02/2020 05:56:14",
          "content": "<p>I haven't checked that yet! My 'only' machine is busy running some computations, maybe will test it by tomorrow!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 708327,
          "author_name": "debanga",
          "author_url": "",
          "post_date": "01/02/2020 07:37:27",
          "content": "<p>Did a quick test and added a notebook: 2-ways-to-read-a-single-video-frame. <a href=\"https://www.kaggle.com/debanga/2-ways-to-read-a-single-video-frame\">https://www.kaggle.com/debanga/2-ways-to-read-a-single-video-frame</a></p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 708477,
      "author_name": "humananalog",
      "author_url": "",
      "post_date": "01/02/2020 10:38:31",
      "content": "<p>I did a similar test <a href=\"https://www.kaggle.com/humananalog/video-speed-test\">in this kernel</a>. If you need to extract several frames from the video, this method is significantly slower than reading the frames one-by-one. (If you just need one or two frames, this method is likely faster.)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 708635,
      "author_name": "debanga",
      "author_url": "",
      "post_date": "01/02/2020 13:56:04",
      "content": "<p><a href=\"/humananalog\">@humananalog</a> Thanks for pointing it out: </p>\n\n<h3>@   everyone</h3>\n\n<p>I just want to clarify here that this method is efficient for reading a 'single' frame. If you need multiple continuous frames,  this may not be the optimum way and may consider following this kernel: <a href=\"https://www.kaggle.com/humananalog/video-speed-test\">https://www.kaggle.com/humananalog/video-speed-test</a>. Please share your experience.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 710363,
      "author_name": "juliensa",
      "author_url": "",
      "post_date": "01/04/2020 16:33:04",
      "content": "<p>Problem is: the read() method is leaking memory as the release() method does not work on the implementation offered by Kaggle (this is a known cv2 bug which apparently was never fixed). \nYou’ll run into RAM issues if you call read() too often...</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "708109": "all:\n\nI thought this would be helpful to read a specific frame from training videos:\n\nhttps://stackoverflow.com/questions/33650974/opencv-python-read-specific-frame-using-videocapture\n\n---\nBy JParrish88 @StackOverflow:\nIf you want an exact frame, you could just set the VideoCapture session to that frame. It's much more intuitive to automatically call on that frame. The \"correct\" solution requires you to input known data: like fps, length, and whatnot. All you need to know with the code below is the frame you want to call.\n\n```\nimport numpy as np\nimport cv2\ncap = cv2.VideoCapture(video_name) #video_name is the video being called\ncap.set(1,frame_no); # Where frame_no is the frame you want\nret, frame = cap.read() # Read the frame\ncv2.imshow('window_name', frame) # show frame on window\n```",
    "708173": "amazing work! Thanks for the excellent kernel",
    "708224": "Have you checked how this does in terms of speed?",
    "708257": "I haven't checked that yet! My 'only' machine is busy running some computations, maybe will test it by tomorrow!",
    "708327": "Did a quick test and added a notebook: 2-ways-to-read-a-single-video-frame. https://www.kaggle.com/debanga/2-ways-to-read-a-single-video-frame",
    "708477": "I did a similar test [in this kernel](https://www.kaggle.com/humananalog/video-speed-test). If you need to extract several frames from the video, this method is significantly slower than reading the frames one-by-one. (If you just need one or two frames, this method is likely faster.)",
    "708635": "humananalog Thanks for pointing it out: \n\n### @   everyone\nI just want to clarify here that this method is efficient for reading a 'single' frame. If you need multiple continuous frames,  this may not be the optimum way and may consider following this kernel: https://www.kaggle.com/humananalog/video-speed-test. Please share your experience.",
    "710363": "Problem is: the read() method is leaking memory as the release() method does not work on the implementation offered by Kaggle (this is a known cv2 bug which apparently was never fixed). \nYou’ll run into RAM issues if you call read() too often..."
  },
  "source": "meta"
}