Ask Your Question

Revision history [back]

Known issue with gopro movie codec? Stops reading after 26 frames.

I have been reading in videos with VideoCapture on both Windows and Mac for several months with the same set of code. I have read a wide array of codecs without issue. I have just encountered a very odd error with the following video type

MacBook-Pro:Manakin ben$ ffmpeg -i GP020744.MP4 
ffmpeg version 3.3.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'GP020744.MP4':
  Metadata:
    major_brand     : mp41
    minor_version   : 538120216
    compatible_brands: mp41
    creation_time   : 2015-03-03T20:17:37.000000Z
    firmware        : HD4.01.02.00.00
  Duration: 00:26:30.59, start: 0.000000, bitrate: 20126 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1280x720 [SAR 1:1 DAR 16:9], 19979 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2015-03-03T20:17:37.000000Z
      handler_name    :     GoPro AVC
      encoder         : GoPro AVC encoder
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2015-03-03T20:17:37.000000Z
      handler_name    :     GoPro AAC
    Stream #0:2(eng): Data: none (tmcd / 0x64636D74) (default)
    Metadata:
      creation_time   : 2015-03-03T20:17:37.000000Z
      handler_name    :     GoPro TCD
      timecode        : 20:16:33:23
    Stream #0:3(eng): Data: none (fdsc / 0x63736466), 9 kb/s (default)
    Metadata:
      creation_time   : 2015-03-03T20:17:37.000000Z
      handler_name    :     GoPro SOS

The file can be played in VLC without issue. What's especially strange is that VideoCapture gets 26 frames before returning ret=False. Always 26 frames. I contacted the person who sent me this video to get a second video, and that one too fails after 26 frames.

The fie size is quite large (~4gb), so I won't link it here. Further deepening the mystery is that if I cut the video with ffmpeg

ffmpeg -t 20 -i GP020744.MP4 -vcodec copy -acodec copy goproexample_codec_copied.MP4

It runs without a problem! But then if you look at

MacBook-Pro:Manakin ben$ ffmpeg -i goproexample_codec_copied.MP4 
ffmpeg version 3.3.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'goproexample_codec_copied.MP4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.71.100
  Duration: 00:00:20.02, start: 0.000000, bitrate: 20114 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1280x720 [SAR 1:1 DAR 16:9], 19979 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

you can see the codec has been changed, even though -vcodec copy was invoked. This would suggest that I'm lacking some mp4 codec (i've downloaded everything I can find). But more importantly, how could opencv read the first 26 frames without the codec?

As an aside, this stack overflow question suggests this is a known issue, but that it has to do with the audio track. As evidenced by above, this is not my experience.

https://stackoverflow.com/questions/49060054/opencv-videocapture-closes-with-videos-from-gopro/49760887?noredirect=1#comment86554311_49760887

Known issue with gopro movie codec? Stops reading after 26 frames.

I have been reading in videos with VideoCapture on both Windows and Mac for several months with the same set of code. I have read a wide array of codecs without issue. I have just encountered a very odd error with the following video type

MacBook-Pro:Manakin ben$ ffmpeg -i GP020744.MP4 
ffmpeg version 3.3.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'GP020744.MP4':
  Metadata:
    major_brand     : mp41
    minor_version   : 538120216
    compatible_brands: mp41
    creation_time   : 2015-03-03T20:17:37.000000Z
    firmware        : HD4.01.02.00.00
  Duration: 00:26:30.59, start: 0.000000, bitrate: 20126 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1280x720 [SAR 1:1 DAR 16:9], 19979 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2015-03-03T20:17:37.000000Z
      handler_name    :     GoPro AVC
      encoder         : GoPro AVC encoder
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2015-03-03T20:17:37.000000Z
      handler_name    :     GoPro AAC
    Stream #0:2(eng): Data: none (tmcd / 0x64636D74) (default)
    Metadata:
      creation_time   : 2015-03-03T20:17:37.000000Z
      handler_name    :     GoPro TCD
      timecode        : 20:16:33:23
    Stream #0:3(eng): Data: none (fdsc / 0x63736466), 9 kb/s (default)
    Metadata:
      creation_time   : 2015-03-03T20:17:37.000000Z
      handler_name    :     GoPro SOS

The file can be played in VLC without issue. What's especially strange is that VideoCapture gets 26 frames before returning ret=False. Always 26 frames. I contacted the person who sent me this video to get a second video, and that one too fails after 26 frames.

The fie size is quite large (~4gb), so I won't link it here. Further deepening the mystery is that if I cut the video with ffmpeg

ffmpeg -t 20 -i GP020744.MP4 -vcodec copy -acodec copy goproexample_codec_copied.MP4

It runs without a problem! But then if you look at

MacBook-Pro:Manakin ben$ ffmpeg -i goproexample_codec_copied.MP4 
ffmpeg version 3.3.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'goproexample_codec_copied.MP4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.71.100
  Duration: 00:00:20.02, start: 0.000000, bitrate: 20114 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1280x720 [SAR 1:1 DAR 16:9], 19979 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

you can see the codec has been changed, even though -vcodec copy was invoked. This would suggest that I'm lacking some mp4 codec (i've downloaded everything I can find). But more importantly, how could opencv read the first 26 frames without the codec?

As an aside, this stack overflow question suggests this is a known issue, but that it has to do with the audio track. As evidenced by above, this is not my experience.

https://stackoverflow.com/questions/49060054/opencv-videocapture-closes-with-videos-from-gopro/49760887?noredirect=1#comment86554311_49760887

also this very old opencv question.

http://answers.opencv.org/question/4120/ffmpeg-crash-with-a-gopro-video/

Known issue with gopro movie codec? Stops reading after 26 frames.

I have been reading in videos with VideoCapture on both Windows and Mac for several months with the same set of code. I have read a wide array of codecs without issue. I have just encountered a very odd error with the following video type

MacBook-Pro:Manakin ben$ ffmpeg -i GP020744.MP4 
ffmpeg version 3.3.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'GP020744.MP4':
  Metadata:
    major_brand     : mp41
    minor_version   : 538120216
    compatible_brands: mp41
    creation_time   : 2015-03-03T20:17:37.000000Z
    firmware        : HD4.01.02.00.00
  Duration: 00:26:30.59, start: 0.000000, bitrate: 20126 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1280x720 [SAR 1:1 DAR 16:9], 19979 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2015-03-03T20:17:37.000000Z
      handler_name    :     GoPro AVC
      encoder         : GoPro AVC encoder
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2015-03-03T20:17:37.000000Z
      handler_name    :     GoPro AAC
    Stream #0:2(eng): Data: none (tmcd / 0x64636D74) (default)
    Metadata:
      creation_time   : 2015-03-03T20:17:37.000000Z
      handler_name    :     GoPro TCD
      timecode        : 20:16:33:23
    Stream #0:3(eng): Data: none (fdsc / 0x63736466), 9 kb/s (default)
    Metadata:
      creation_time   : 2015-03-03T20:17:37.000000Z
      handler_name    :     GoPro SOS

The file can be played in VLC without issue. What's especially strange is that VideoCapture gets 26 frames before returning ret=False. Always 26 frames. I contacted the person who sent me this video to get a second video, and that one too fails after 26 frames.

The fie size is quite large (~4gb), so I won't link it here. Further deepening the mystery is that if I cut the video with ffmpeg

ffmpeg -t 20 -i GP020744.MP4 -vcodec copy -acodec copy goproexample_codec_copied.MP4

It runs without a problem! But then if you look at

MacBook-Pro:Manakin ben$ ffmpeg -i goproexample_codec_copied.MP4 
ffmpeg version 3.3.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'goproexample_codec_copied.MP4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.71.100
  Duration: 00:00:20.02, start: 0.000000, bitrate: 20114 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1280x720 [SAR 1:1 DAR 16:9], 19979 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

you can see the codec has been changed, even though -vcodec copy was invoked. This would suggest that I'm lacking some mp4 codec (i've downloaded everything I can find). But more importantly, how could opencv read the first 26 frames without the codec?

As an aside, this stack overflow question suggests this is a known issue, but that it has to do with the audio track. As evidenced by above, this is not my experience.

https://stackoverflow.com/questions/49060054/opencv-videocapture-closes-with-videos-from-gopro/49760887?noredirect=1#comment86554311_49760887

also this very old opencv question.

http://answers.opencv.org/question/4120/ffmpeg-crash-with-a-gopro-video/

Edit #1

The read function is pretty boilerplate. Can be boiled down to:

self.cap=cv2.VideoCapture(self.args.video)
ret,self.image=self.read_frame()
if not ret:
  break

def read_frame(self):
  ret,self.original_image=self.cap.read()
  return((ret,self.original_image))