Kagami / ffmpeg.js

Port of FFmpeg with Emscripten
Other
3.28k stars 332 forks source link

Black video in QuickTime #41

Open fredrikj opened 7 years ago

fredrikj commented 7 years ago

It seems like a new build of ffmpeg-worker-mp4.js is needed. When using current build, I get an mp4 file that plays fine in VLC, but plays with a black video in Quicktime. Doing a conversion of the same webm file in my own installation of ffmpeg plays good in Quicktime. Running ffprobe on both outputs, I mainly get a difference in encoder versions:

encoder : Lavf57.41.100 vs encoder : Lavf57.56.101

(apart from some minor differences in the video or audio streams, which would make sense since the encoders are different)

Hence - may I suggest that new builds are published?

Kagami commented 7 years ago

That's weird. Could you upload video which gives black output in QT?

fredrikj commented 7 years ago

Here are two very short files, created from the same webm source. I created native.mp4 with my own installation of ffmpeg and js.mp4 with this build. js.mp4 shows black video in qt.

quicktime.black.zip

joerick commented 5 years ago

Did you ever fix this @fredrikj ? I'm trying to debug the same problem. At the moment it looks like ffmpeg.js doesn't understand the h264 data inside the stream. It's writing a single NAL in the mp4 file instead of ~100, and not including SPS and PPS data in the avcC box.

Then I spotted this error:

ffmpeg: [NULL @ 0x83ddf0] Opening 'input.webm' for reading
transcoder.js?7f08:61 ffmpeg: [file @ 0x83e4e0] Setting default whitelist 'file,crypto'
transcoder.js?7f08:61 ffmpeg: [matroska,webm @ 0x83ddf0] Format matroska,webm probed with size=2048 and score=100
transcoder.js?7f08:61 ffmpeg: st:0 removing common factor 1000000 from timebase
transcoder.js?7f08:61 ffmpeg: [matroska,webm @ 0x83ddf0] Before avformat_find_stream_info() pos: 136 bytes read:32768 seeks:0 nb_streams:1
transcoder.js?7f08:61 ffmpeg: [matroska,webm @ 0x83ddf0] parser not found for codec h264, packets or times may be invalid.

parser not found for codec h264, packets or times may be invalid... That error doesn't appear on my local machine's ffmpeg. Could be related to how the library is built?

fredrikj commented 5 years ago

No, didn't fix this. In the end, I didn't need ffmpeg.js so I haven't bothered about it (not that I would have the skills to fix it myself anyway :) ).

joerick commented 5 years ago

Thanks for getting back. I'm pretty stumped so might leave this for now. I'll also note that I've tried a webm fork that has Lavf58.20.100 and saw the same problem.

This is the version I tried:

ffmpeg version n4.1-13-gb420f23 Copyright (c) 2000-2018 the FFmpeg developers
built with emcc (Emscripten gcc/clang-like replacement) 1.38.21 (commit df648b43825d3ab1179886d3c78020ed890333d3)
configuration: --cc=emcc --enable-cross-compile --target-os=none --arch=x86 --disable-runtime-cpudetect --disable-asm --disable-fast-unaligned --disable-pthreads --disable-w32threads --disable-os2threads --disable-debug --disable-stripping --disable-all --enable-ffmpeg --enable-avcodec --enable-avformat --enable-avutil --enable-swresample --enable-swscale --enable-avfilter --disable-network --disable-d3d11va --disable-dxva2 --disable-vaapi --disable-vdpau --enable-decoder=vp8 --enable-decoder=vp9 --enable-decoder=theora --enable-decoder=mpeg2video --enable-decoder=mpeg4 --enable-decoder=h264 --enable-decoder=hevc --enable-decoder=png --enable-decoder=mjpeg --enable-decoder=vorbis --enable-decoder=opus --enable-decoder=mp3 --enable-decoder=ac3 --enable-decoder=aac --enable-decoder=ass --enable-decoder=ssa --enable-decoder=srt --enable-decoder=webvtt --enable-demuxer=matroska --enable-demuxer=ogg --enable-demuxer=avi --enable-demuxer=mov --enable-demuxer=flv --enable-demuxer=mpegps --enable-demuxer=image2 --enable-demuxer=mp3 --enable-demuxer=concat --enable-protocol=file --enable-filter=aresample --enable-filter=scale --enable-filter=crop --enable-filter=overlay --disable-bzlib --disable-iconv --disable-libxcb --disable-lzma --disable-securetransport --disable-xlib --disable-zlib --enable-encoder=libx264 --enable-encoder=libmp3lame --enable-encoder=aac --enable-muxer=mp4 --enable-muxer=mp3 --enable-muxer=null --enable-gpl --enable-libmp3lame --enable-libx264 --extra-cflags=-I../lame/dist/include --extra-ldflags=-L../lame/dist/lib
libavutil      56. 22.100 / 56. 22.100
libavcodec     58. 35.100 / 58. 35.100
libavformat    58. 20.100 / 58. 20.100
libavfilter     7. 40.101 /  7. 40.101
libswscale      5.  3.100 /  5.  3.100
libswresample   3.  3.100 /  3.  3.100

from https://github.com/uetchy/ffmpeg.js

Kagami commented 4 years ago

Hi @fredrikj @joerick A long time has passed, could you try to reproduce with the latest build? If yes, could you provide input, output and full command?

I don't have macOS unfortunately, but maybe I will be able to analyze the resulting files.

sergeykurson commented 4 years ago

@Kagami seems like I'm experiencing the same problem and https://github.com/Kagami/ffmpeg.js/issues/109 related (or even duplicate) as well. I'll provide original webm, web transcoded mp4 and desktop transcoded mp4. Desktop one plays well in QuickTime. Arguments are -i video.webm -c:v copy video.mp4 files.zip

amrithyerramilli commented 3 years ago

Hi - I took am facing this same error as well.

I am capturing a HTML canvas using MediaRecorder on Chrome, using video/webm\;codecs=h264. I am then using ffmpeg-mp4.js to change the container to mp4 (from webm).

Here are the files for you reference: videos.zip

In the logs from ffmpeg.js, I can see [matroska,webm @ 0x72be20] parser not found for codec h264, packets or times may be invalid.

It looks like the video is fine - but the Windows 10 player doesn't recognize it and complains of corrupt file. The video plays fine on Chrome.

The ffmpeg invocation code looks like this:

    let stdout = "";
    let stderr = "";

    let webmBlobArrayBuffer = await webmBlob.arrayBuffer();
    console.log(webmBlobArrayBuffer);
    console.log(webmBlobArrayBuffer.byteLength);
    let webmBlobUint8Array = new Uint8Array(webmBlobArrayBuffer);

    //"-movflags", "faststart",
    let mp4 = ffmpeg({
      MEMFS: [{name: "in.webm", data: webmBlobUint8Array }],
      arguments: ["-loglevel", "debug", "-i", "in.webm", "-codec", "copy", "out.mp4"],
      print: function(data) { stdout += data + "\n"; },
      printErr: function(data) { stderr += data + "\n"; },
      onExit: function(code) {
        console.log("Process exited with code " + code);
        console.log(stdout);
        console.log(stderr);
      },
    });

Here is the full log for reference:

ffmpeg version n4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with emcc (Emscripten gcc/clang-like replacement) 1.39.11
  configuration: --cc=emcc --ranlib=emranlib --enable-cross-compile --target-os=none --arch=x86 --disable-runtime-cpudetect --disable-asm --disable-fast-unaligned --disable-pthreads --disable-w32threads --disable-os2threads --disable-debug --disable-stripping --disable-safe-bitstream-reader --disable-all --enable-ffmpeg --enable-avcodec --enable-avformat --enable-avfilter --enable-swresample --enable-swscale --disable-network --disable-d3d11va --disable-dxva2 --disable-vaapi --disable-vdpau --enable-decoder=vp8 --enable-decoder=h264 --enable-decoder=vorbis --enable-decoder=opus --enable-decoder=mp3 --enable-decoder=aac --enable-decoder=pcm_s16le --enable-decoder=mjpeg --enable-decoder=png --enable-demuxer=matroska --enable-demuxer=ogg --enable-demuxer=mov --enable-demuxer=mp3 --enable-demuxer=wav --enable-demuxer=image2 --enable-demuxer=concat --enable-protocol=file --enable-filter=aresample --enable-filter=scale --enable-filter=crop --enable-filter=overlay --enable-filter=hstack --enable-filter=vstack --disable-bzlib --disable-iconv --disable-libxcb --disable-lzma --disable-sdl2 --disable-securetransport --disable-xlib --enable-zlib --enable-encoder=libx264 --enable-encoder=libmp3lame --enable-encoder=aac --enable-muxer=mp4 --enable-muxer=mp3 --enable-muxer=null --enable-gpl --enable-libmp3lame --enable-libx264 --extra-cflags='-s USE_ZLIB=1 -I../lame/dist/include' --extra-ldflags=-L../lame/dist/lib
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
Splitting the commandline.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Reading option '-i' ... matched as input url with argument 'in.webm'.
Reading option '-codec' ... matched as option 'codec' (codec name) with argument 'copy'.
Reading option 'out.mp4' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input url in.webm.
Successfully parsed a group of options.
Opening an input file: in.webm.
[NULL @ 0x72be20] Opening 'in.webm' for reading
[file @ 0x72c510] Setting default whitelist 'file,crypto'
[matroska,webm @ 0x72be20] Format matroska,webm probed with size=2048 and score=100
st:0 removing common factor 1000000 from timebase
[matroska,webm @ 0x72be20] Before avformat_find_stream_info() pos: 136 bytes read:32768 seeks:0 nb_streams:1
[matroska,webm @ 0x72be20] parser not found for codec h264, packets or times may be invalid.
[h264 @ 0x72d330] Warning: not compiled with thread support, using thread emulation
[matroska,webm @ 0x72be20] parser not found for codec h264, packets or times may be invalid.
[h264 @ 0x72d330] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x72d330] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x72d330] nal_unit_type: 5(IDR), nal_ref_idc: 3
    Last message repeated 15 times
[h264 @ 0x72d330] Format yuv420p chosen by get_format().
[h264 @ 0x72d330] Reinit context to 1088x1088, pix_fmt: yuv420p
[h264 @ 0x72d330] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 3
    Last message repeated 95 times
[matroska,webm @ 0x72be20] All info found
[matroska,webm @ 0x72be20] rfps: 29.333333 0.016818
[matroska,webm @ 0x72be20] rfps: 29.416667 0.007986
    Last message repeated 1 times
[matroska,webm @ 0x72be20] rfps: 29.500000 0.002526
    Last message repeated 1 times
[matroska,webm @ 0x72be20] rfps: 29.583333 0.000437
[matroska,webm @ 0x72be20] rfps: 29.666667 0.001720
[matroska,webm @ 0x72be20] rfps: 29.750000 0.006376
    Last message repeated 1 times
[matroska,webm @ 0x72be20] rfps: 29.833333 0.014403
    Last message repeated 1 times
[matroska,webm @ 0x72be20] rfps: 59.000000 0.010102
    Last message repeated 1 times
[matroska,webm @ 0x72be20] After avformat_find_stream_info() pos: 793088 bytes read:807845 seeks:0 frames:48
Input #0, matroska,webm, from 'in.webm':
  Metadata:
    encoder         : Chrome
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0(eng), 48, 1/1000: Video: h264 (Constrained Baseline), 1 reference frame, yuv420p(left), 1080x1080 (1088x1088), 0/1, SAR 1:1 DAR 1:1, 29.58 tbr, 1k tbn, 2k tbc (default)
Successfully opened the file.
Parsing a group of options: output url out.mp4.
Applying option codec (codec name) with argument copy.
Successfully parsed a group of options.
Opening an output file: out.mp4.
[file @ 0xd337b0] Setting default whitelist 'file,crypto'
Successfully opened the file.
Output #0, mp4, to 'out.mp4':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0(eng), 0, 1/16000: Video: h264 (Constrained Baseline), 1 reference frame (avc1 / 0x31637661), yuv420p(left), 1080x1080 (0x0) [SAR 1:1 DAR 1:1], 0/1, q=2-31, 29.58 tbr, 16k tbn, 1k tbc (default)
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
No more output streams to write to, finishing.
frame=  107 fps=0.0 q=-1.0 Lsize=    1571kB time=00:00:04.94 bitrate=2602.4kbits/s speed=92.9x    
video:1569kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.112062%
Input file #0 (in.webm):
  Input stream #0:0 (video): 107 packets read (1607151 bytes); 
  Total: 107 packets (1607151 bytes) demuxed
Output file #0 (out.mp4):
  Output stream #0:0 (video): 107 packets muxed (1607151 bytes); 
  Total: 107 packets (1607151 bytes) muxed
0 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0xd33850] Statistics: 2 seeks, 10 writeouts
[AVIOContext @ 0x7345d0] Statistics: 1608106 bytes read, 0 seeks
Blankgiraffe commented 3 years ago

Use this flag for Apple software (Quicktime, Quick Look, etc..) to properly playback.

-pix_fmt yuv420p

Original answer: https://apple.stackexchange.com/a/166554