0

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月07日T15: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月07日T15: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月07日T15: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月07日T15: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月07日T15:21:10.000000Z
 handler_name : GoPro MET
 Stream #0:4(eng): Data: none (fdsc / 0x63736466), 13 kb/s (default)
 Metadata:
 creation_time : 2021年06月07日T15: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
asked Aug 12, 2022 at 7:46

1 Answer 1

3

Looks like the video is encoded in H265 which will be why it won't play in a browser, we can easily re-encode it to H264.

ffmpeg -i input.mp4 -map 0:v:0 -map 0:a:0 -c:v h264 -c:a copy -pix_fmt yuv420p output.mp4

-i input.mp4 is specifying the input file.

-map 0:v:0 is specifying to target the first input file, the video, then first video stream.

-map 0:a:0 is specifying to target the first input file, the audio, then the first audio stream.

-c:v h264 is saying to re-encode the video as H264, which is a widely supported video codec for browsers.

-c:a copy is saying to copy the audio stream without re-encoding it, as you said the audio is already working in browser and we can see it is AAC which is widely supported.

-pix_fmt yuv420p is setting the Pixel Format to yuv420p which is one of the few supported in browsers, most high-quality footage will be a less compressed format such as yuvj420p which allows for more accurate footage editing.

output.mp4 is the name and format of the output file.

This command should create usable footage in the browser but it will remove the additional GoPro Data streams, if you want you can try to retain it and see if the result will still play in a browser:

ffmpeg -i input.mp4 -map 0:v:0 -map 0:a:0 -c:v h264 -c:a copy -c:s copy -c:d copy -pix_fmt yuv420p output.mp4

-c:s copy means copy all subtitle streams. -c:d copy means copy all data streams.

You mentioned compression, you can optionally compress the video and audio by specifying bitrate and resolution manually, but it's much easier to use Constant Rate Factor which will reduce quality for file-size depending on the factors you want. CRF 22 is a good starting point, make the number smaller to increase quality and file size, make the number higher to decrease quality and file size.

ffmpeg -i input.mp4 -map 0:v:0 -map 0:a:0 -c:v h264 -c:a copy -c:s copy -c:d copy -pix_fmt yuv420p -crf 22 output.mp4

The range is 0 - 51 for h264.

answered Aug 12, 2022 at 11:58
1
  • Thanks for the detailed answer. Commented Aug 12, 2022 at 12:36

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.