videoffmpeggopro

How to extract video+audio streams from MP4 file via ffmpeg?


I have a bunch of MP4 files from a GoPro, which include streams of metadata like GPS information. Now unfortunately when I try to open these MP4 files in any browser (tried both Firefox and Chrome on Windows and Linux), then only the audio is being played, but no video. I can, however, open the MP4 files in VLC player and that can play both video and audio without problem - so the files seem correct, just the browser cannot play them correctly.

Since I need to play the MP4 files in a browser, I need to extract both the video and the audio streams from the original files and create new MP4 files out of them, in a format so that the browser can play them. I also don't want to loose any frames during conversion - it would be OK to compress the video stream a bit, so that the resulting MP4 files would be a bit smaller than the originals, but the number of frames and the FPS value and these settings must be exactly as in the original file.

What would be the proper ffmpeg command to achieve this?
For your reference, this is the information from ffprobe on one of the videos:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55ce62e37a00] Using non-standard frame rate 59/1
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/winclients/ASFINAG/Abnahme/GX010005.MP4':
  Metadata:
    major_brand     : mp41
    minor_version   : 538120216
    compatible_brands: mp41
    creation_time   : 2021-06-07T15:21:10.000000Z
    location        : +48.3743+016.2383/
    location-eng    : +48.3743+016.2383/
    firmware        : HD9.01.01.00.00
  Duration: 00:08:51.54, start: 0.000000, bitrate: 60205 kb/s
    Stream #0:0(eng): Video: hevc (Main) (hvc1 / 0x31637668), yuvj420p(pc, bt709), 3840x2160 [SAR 1:1 DAR 16:9], 59941 kb/s, 59.94 fps, 59.94 tbr, 60k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2021-06-07T15:21:10.000000Z
      handler_name    : GoPro H.265
      encoder         : GoPro H.265 encoder
      timecode        : 15:35:51:04
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s (default)
    Metadata:
      creation_time   : 2021-06-07T15:21:10.000000Z
      handler_name    : GoPro AAC
      timecode        : 15:35:51:04
    Stream #0:2(eng): Data: none (tmcd / 0x64636D74) (default)
    Metadata:
      creation_time   : 2021-06-07T15:21:10.000000Z
      handler_name    : GoPro TCD
      timecode        : 15:35:51:04
    Stream #0:3(eng): Data: bin_data (gpmd / 0x646D7067), 47 kb/s (default)
    Metadata:
      creation_time   : 2021-06-07T15:21:10.000000Z
      handler_name    : GoPro MET
    Stream #0:4(eng): Data: none (fdsc / 0x63736466), 13 kb/s (default)
    Metadata:
      creation_time   : 2021-06-07T15:21:10.000000Z
      handler_name    : GoPro SOS
Unsupported codec with id 0 for input stream 2
Unsupported codec with id 100359 for input stream 3
Unsupported codec with id 0 for input stream 4

Solution

  • The issue I think you are seeing is that the videos are using H.265 codec and this is not well supported across browsers - current snapshot at time of writing: https://caniuse.com/hevc

    You should not need to extract the tracks to transcode, however - ffmpeg will allow you specify the full input mp4 file and provide a new mp4 output file.

    There is an ffmpeg wiki guide that goes into much more detail here: https://trac.ffmpeg.org/wiki/Encode/H.264

    At a high level you command will look something like:

    ffmpeg -i yourInputFile.mp4 -c:v libx264 -crf 23 -preset ultrafast -c:a aac yourOutput.mp4

    Look in particular the note on the CRF value in the guide linked to as this will affect the size and quality.