ekisu / mpv-webm

Simple WebM maker for mpv, with no external dependencies.
MIT License
571 stars 33 forks source link

Encode fails when launching mpv through Finder #2

Closed nickbudi closed 6 years ago

nickbudi commented 6 years ago

I'm getting the first pass failed error when trying this script for the first time.

Checking logs didn't reveal anything useful but when running the encoding command from the terminal I got

[encode-lavc] neither audio nor video codec was found
[encode-lavc] vo-lavc: encoded 0 bytes
[encode-lavc] ao-lavc: encoded 0 bytes
Encoding initialization failed.

Any ideas? I'm on macOS High Sierra and it looks like the script tries to use libvpx and libvorbis codecs.

ekisu commented 6 years ago

Which build are you using? Please post the output from mpv --ovc=help and mpv --oac=help.

nickbudi commented 6 years ago

here's the mpv output

ekisu commented 6 years ago

Apparently your libavcodec was compiled without libvpx/libvorbis encoding support. I don't know if macOS mpv builds are statically or dynamically linked, but there's not much that can be done aside from enabling the right flags on the build.

Edit: just for the record, can your mpv play webm files?

nickbudi commented 6 years ago

Yeah my mpv build is able to play webm files.

Looks like --enable-libvorbis --enable-libvpx are the required build flags

ekisu commented 6 years ago

Can you (re)install ffmpeg enabling libvpx and libvorbis, and report if it works?

Maybe this helps.

nickbudi commented 6 years ago

Thanks, reinstalling ffmpeg with those flags works.

But I think the webm output file is corrupt: original webm output

Same output for other video formats. I also noticed encoding will fail if I open the video through finder instead of the command line.

nickbudi commented 6 years ago

Setting the script to use to libvpx-v9 instead of libvpx fixed everything.

ekisu commented 6 years ago

Could you try encoding it with ffmpeg, as described here? Using VP8 alone shouldn't be the reason why it's producing such broken files.

nickbudi commented 6 years ago

using -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis is working, but VP8 from the script is still broken

ekisu commented 6 years ago

I'm running out of ideas here, sadly I don't have a Mac to try this myself. Does modifying the 1/2-pass setting change anything? Maybe VP8 can't, for some reason, use/write the first pass log file. Also, if you execute the mpv encoding command on the terminal again, does anything change (for both 1 and 2 pass variations)?

Please post logs if you find them necessary/somewhat useful.

nickbudi commented 6 years ago

As far as my issues go single or two pass doesn't matter. I figured out the VP8 corruption is caused by libvpx_threads being set to anything other than 1 (default 4), so I can get a proper webm files with VP8, but only if I open the video through a terminal.

When I open a video through finder instead of the terminal encoding fails. The mpv command being run for both terminal and finder processes are the same though, and running the mpv command separately works so I'm stumped there. And switching to VP9 and encoding through finder works, including libvpx_threads=4.

Don't think this is helpful but here's the relevant part of the log from encoding through finder with twopass=false:

[   4.632][i][webm] Encoding to ~/small-[00_01.066-00_02.866]-audio.webm
[   4.632][v][webm] Command line: mpv ~/small.mp4 --start=0:00:01.066 --end=0:00:02.866 --ovc=libvpx --oac=libvorbis --vid=1 --aid=1 --sid=no --vf lavfi=[colormatrix=bt709:bt601] --ovcopts-add=threads=1 --ovcopts-add=b=11111k --ovcopts-add=crf=10 -o=~/small-[00_01.066-00_02.866]-audio.webm
[   4.632][v][cplayer] Run command: show-text, flags=0, args=[�Started encode..., 5000, 0]
[   4.643][v][osd/libass] Shaper: FriBidi 0.19.7 (SIMPLE) HarfBuzz-ng 1.5.1 (COMPLEX)
[   4.643][v][osd/libass] Setting up fonts...
[   4.644][v][osd/libass] Using font provider coretext
[   4.644][v][osd/libass] Done.
[   4.647][v][osd/libass] fontselect: (sans-serif, 400, 0) -> /System/Library/Fonts/Helvetica.ttc, -1, Helvetica
[   4.649][v][vo/opengl] Reallocating OSD texture to 512x128.
[   4.724][v][cplayer] Run command: script-binding, flags=9, args=[webm/e]
[   4.739][v][cplayer] Run command: show-text, flags=0, args=[�Encode failed! Check the logs for details., 5000, 0]
[   4.744][v][vo/opengl] Reallocating OSD texture to 1024x128.
[   4.826][v][lavf] EOF reached.
[   5.508][v][cplayer] Run command: quit, flags=9, args=[0]
[   5.508][v][cplayer] EOF code: 6
ekisu commented 6 years ago

I've updated the script to produce better logging. Please try it out and post logs.

Edit: if the libvpx_threads issue occurs even when using ffmpeg directly, you might consider opening a bug on their tracker.

nickbudi commented 6 years ago

Ah you're right the threads issue lies with ffmpeg. I'll open a bug report with them.

I noticed with your last update encoding failure prints success and vice versa. Here's the updated log when encoding through finder

[  17.771][i][webm] Encoding to ~/small-[00_01.900-00_03.733]-audio.webm
[  17.771][v][webm] Command line: mpv ~/small.mp4 --start=0:00:01.900 --end=0:00:03.733 --ovc=libvpx --oac=libvorbis --vid=1 --aid=1 --sid=no --vf lavfi=[colormatrix=bt709:bt601] --ovcopts-add=threads=1 --ovcopts-add=b=10909k --ovcopts-add=crf=10 -o=~/small-[00_01.900-00_03.733]-audio.webm
[  17.771][v][cplayer] Run command: show-text, flags=0, args=[�Started encode..., 5000, 0]
[  17.870][v][webm] Command failed! Reason:  nil  Killed by us?  no
[  17.870][v][webm] Command stdout:
[  17.870][v][webm]
[  17.870][v][cplayer] Run command: show-text, flags=0, args=[�Encoded successfully! Saved to\N{\b1}~/small-[00_01.900-00_03.733]-audio.webm{\b0}, 5000, 0]
ekisu commented 6 years ago

I noticed with your last update encoding failure prints success and vice versa.

Fixed that.

Anyway, I think this might be, somehow, related to mpv not allowing multiple instances under macOS (mpv-player/mpv#1377) when using the app bundle (the Terminal allows you to run as many instances as you like). But, because it works when libvpx-vp9 is used, I'm not entirely sure why that would matter. I'll try wrapping it on a bash instance or something.

Edit: try this and this, you should find 2 files named "encode-log.log" on your home dir, please upload them.

ekisu commented 6 years ago

Closed, seems to be working as of now (see #13).