当前位置: 动力学知识库 > 问答 > 编程问答 >

html5 - Videojs does not play converted mp4 file

问题描述:

I am creating a platform for video files to be uploaded to. In order for them to get played through Videojs, I convert/demux mkv/flv/3gp files to mp4 files.

The issue I encounter is that if I demux such video/mkv file, I get the error message Video format or mime type not supported, even though it is a "working" mp4 file on my computer.

I think I understand that mkv files are containers, and that if demuxed it keeps the same video and audio codec and if that is not supported by Videojs/HTML5 the video cannot get played. Please, correct me if I am wrong.

Can anyone please tell me why this demux of mkv.mkv to mkv.mp4 will not play in my browser?

➜ ~ ffmpeg -i mkv.mkv -vcodec copy -acodec copy mkv.mp4

ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers

built with Apple LLVM version 8.0.0 (clang-800.0.42.1)

configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.2 --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 --disable-lzma --enable-vda

libavutil 55. 34.100 / 55. 34.100

libavcodec 57. 64.101 / 57. 64.101

libavformat 57. 56.100 / 57. 56.100

libavdevice 57. 1.100 / 57. 1.100

libavfilter 6. 65.100 / 6. 65.100

libavresample 3. 1. 0 / 3. 1. 0

libswscale 4. 2.100 / 4. 2.100

libswresample 2. 3.100 / 2. 3.100

libpostproc 54. 1.100 / 54. 1.100

Input #0, matroska,webm, from 'mkv.mkv':

Metadata:

ENCODER : Lavf53.24.2

Duration: 00:00:34.08, start: -1.400000, bitrate: 1232 kb/s

Stream #0:0: Video: mpeg4 (Simple Profile), yuv420p, 720x480 [SAR 1:1 DAR 3:2], 25 fps, 25 tbr, 1k tbn, 25 tbc (default)

Stream #0:1: Audio: aac (LC), 48000 Hz, 5.1, fltp (default)

Output #0, mp4, to 'mkv.mp4':

Metadata:

encoder : Lavf57.56.100

Stream #0:0: Video: mpeg4 (Simple Profile) ( [0][0][0] / 0x0020), yuv420p, 720x480 [SAR 1:1 DAR 3:2], q=2-31, 25 fps, 25 tbr, 16k tbn, 1k tbc (default)

Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, 5.1 (default)

Stream mapping:

Stream #0:0 -> #0:0 (copy)

Stream #0:1 -> #0:1 (copy)

Press [q] to stop, [?] for help

frame= 887 fps=0.0 q=-1.0 Lsize= 5130kB time=00:00:35.45 bitrate=1185.4kbits/s speed= 668x

video:3447kB audio:1663kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.401607%

Thanks for all the help already. I cant seem to find an answer...

网友答案:

As the comments mention you are re-muxing MPEG-4 Part 2 video, but that isn't supported by your browser. You need to re-encode to H.264:

ffmpeg -i input -c:v libx264 -c:a copy -movflags +faststart output.mp4
  • -movflags +faststart is added to reposition some data so it can begin playback without requiring the file to be completely downloaded beforehand.

  • If you device or browser does not support 5.1 channels then downmix it to stereo with -ac 2.

  • Additionally, may have to add -profile:v and -level depending if you need to support old devices.

See FFmpeg Wiki: H.264 for information on controlling quality and compatibility details.

网友答案:

You are missing the -movflags +faststart.

This parameter moves the information that the player needs to starts to play the file asap. Otherwise the file must to be completely downloaded before it starts.

The command :

ffmpeg -i mkv.mkv -vcodec copy -acodec copy -movflags +faststart mkv.mp4
分享给朋友:
您可能感兴趣的文章:
随机阅读: