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

asked 2018-04-13 12:51:49 -0600

benweinstein gravatar image

updated 2018-04-13 14:01:45 -0600

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 ...
(more)
edit retag flag offensive close merge delete

Comments

please show your opencv code.

berak gravatar imageberak ( 2018-04-13 13:42:13 -0600 )edit

added code sample.

benweinstein gravatar imagebenweinstein ( 2018-04-13 14:02:15 -0600 )edit

Hi! I am pretty sure I know the solution to your problem since I had exactly the same problem (maybe even also 26 frames)... OpenCV cannot deal with the sound track of the GoPro videos. I solved it by stripping the sound off my videos with ffmpeg before giving them to the OpenCV code. The sound can not only be muted, the whole track has to be removed. I am currently again facing problems with OpenCV and GoPro and was reading more about the problem. Maybe setting the right codec for the capture with capture.set(CV_CAP_PROP_FOURCC, ... )) may also help?

Alexand gravatar imageAlexand ( 2018-05-19 21:35:54 -0600 )edit