fstark / macflim

MacFlim flim player source code and utilities
MIT License
90 stars 4 forks source link

Cannot make the encoder #40

Closed nsputnik closed 1 year ago

nsputnik commented 1 year ago

I am on Apple Silicon Ventura 13. I installed ffmpeg(4), (nulinked first, that did not work until I installed the default ffmpeg) , and ImageMagic. I am not too savvy with command line but make is not working, even with the special instructions you have for it.

What directory should I be set to when I do git clone https://github.com/fstark/macflim.git?

When I do CFLAGS=-I/opt/homebrew/include/ LDLIBS=-L/opt/homebrew/lib/ make the response is make: *** No targets specified and no makefile found. Stop. I don't see a make file at the macflim root, but I did find one in src. So I cd to src, ran the code above there were 16 warnings about warning sprintf.

warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.

I am not finding and instructions on how to install sprintf(3).

fstark commented 1 year ago

Thx for trying macflim

What directory should I be set to when I do git clone https://github.com/fstark/macflim.git?

This will extract macflim in a directory called macflim in the directory you are in. Use your favorite development directory.

You then cd macflim

You need to go into src to build the encoder. Need to update the readme.

You can ignore the warning about sprintf, I may replace them with snprintf, which is slightly less portable.

Did you got a binary after make? If not, post the whole compilation log.

nsputnik commented 1 year ago

@fstark Here is the error I get on Apple Silicon 13.2, Xcode 14.3.

$ CFLAGS=-I/opt/homebrew/include/ LDLIBS=-L/opt/homebrew/lib/ make
c++  -std=c++2a -c -O3 reader.cpp -o reader.o
In file included from reader.cpp:1:
./reader.hpp:102:9: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
        sprintf( buffer, file_pattern_.c_str(), current_image_index_ );
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here
__deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg'
        #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                      ^
reader.cpp:4:10: fatal error: 'libavformat/avformat.h' file not found
#include <libavformat/avformat.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.
make: *** [reader.o] Error 1

For each macOS (and I have tried this one 10.13.6 10.15.7, 13.2) what version of Xcode and Command Line Tools should I run?

On 10.13.6 I can't get ImageMagick installed because brew says it is too old. Do you know how I can find an install a version that works?

nsputnik commented 1 year ago

Here is the error I get in 10.14.6 with xCode 11.3.1, Intel i7.

$ sudo make
Password:
c++  -std=c++2a -c -O3 -I liblzg/src/include flimmaker.cpp -o flimmaker.o
flimmaker.cpp:253:35: warning: 'tmpnam' is deprecated: This function is provided for
      compatibility reasons only. Due to security concerns inherent in the design of tmpnam(3),
      it is highly recommended that you use mkstemp(3) instead. [-Wdeprecated-declarations]
    std::string cache_file = std::tmpnam( nullptr );
                                  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:186:1: note: 'tmpnam'
      has been explicitly marked deprecated here
__deprecated_msg("This function is provided for compatibility reasons only.  Due to sec...
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:180:48: note: 
      expanded from macro '__deprecated_msg'
        #define __deprecated_msg(_msg) __attribute__((deprecated(_msg)))
                                                      ^
flimmaker.cpp:626:30: error: 'exists' is unavailable: introduced in macOS 10.15
        if (std::filesystem::exists(cache_file))
                             ^
/Applications/Xcode 11.13.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/filesystem:1617:39: note: 
      'exists' has been explicitly marked unavailable here
inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p) {
                                      ^
flimmaker.cpp:626:37: error: 'path' is unavailable: introduced in macOS 10.15
        if (std::filesystem::exists(cache_file))
                                    ^
/Applications/Xcode 11.13.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/filesystem:773:3: note: 
      'path' has been explicitly marked unavailable here
  path(const _Source& __src, format = format::auto_format) {
  ^
flimmaker.cpp:626:37: error: '~path' is unavailable: introduced in macOS 10.15
        if (std::filesystem::exists(cache_file))
                                    ^
/Applications/Xcode 11.13.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/filesystem:791:3: note: 
      '~path' has been explicitly marked unavailable here
  ~path() = default;
  ^
1 warning and 3 errors generated.
make: *** [flimmaker.o] Error 1
nsputnik commented 1 year ago

The issue could be with ffmpeg@4, before I even get to trying to install macflim. Here is the very end of a log for an install attempt of ffmpeg@4 on OS X 10.15.7 with Xcode 12.4. I think I got this error on some other OSed I have tried.

Error: ffmpeg@4: Failed to download resource "libvorbis"
Download failed: Homebrew-installed `curl` is not installed for: https://downloads.xiph.org/releases/vorbis/libvorbis-1.3.7.tar.xz
nsputnik@Nicks-Mac-mini src % ffmpeg@4
zsh: command not found: ffmpeg@4

libvorbis not installed? Ok.

$   brew reinstall libvorbis
Warning: libvorbis 1.3.7 is already installed and up-to-date.
To reinstall 1.3.7, run:
  brew reinstall libvorbis

?

fstark commented 1 year ago

Skimming through your logs, I see two issues:

a) one related to ffmpeg:

reader.cpp:4:10: fatal error: 'libavformat/avformat.h' file not found

include <libavformat/avformat.h>

this means that the dev headers for ffmpeg (which are used by macflim) are nowhere to be found.

b) one related to your C++ environment:

/Applications/Xcode 11.13.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/filesystem:791:3: note: '~path' has been explicitly marked unavailable here

this means that your compiler is not C++20 compliant.

Let me do a clean compile with Ventura 13.2.1 (22D68) and post the result here.

(Looking at your compile for Ventura, it looks like ffmpeg@4 is not installed)

fstark commented 1 year ago

So, on 13.2.1:

fred@fredosx ~ % brew install ffmpeg@4
Running `brew update --auto-update`...
==> Downloading https://ghcr.io/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:61029cec31c68a1fae1fa90fa876adf43d0becff777da793f9b5c5577f00567a
########################################################################################################################################################################################## 100.0%
==> Pouring portable-ruby-2.6.10_1.el_capitan.bottle.tar.gz
==> Downloading https://formulae.brew.sh/api/formula.jws.json
########################################################################################################################################################################################## 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
########################################################################################################################################################################################## 100.0%
==> Auto-updated Homebrew!
Updated 1 tap (yt-dlp/taps).

You have 92 outdated formulae and 1 outdated cask installed.

ffmpeg@4  is already installed but outdated (so it will be upgraded).
==> Fetching dependencies for ffmpeg@4: highway, imath, jpeg-turbo, libpng, xz, zstd, libtiff, little-cms2, openexr, webp, jpeg-xl, aom, dav1d, freetype, fontconfig, ca-certificates, libunistring, gettext, libidn2, libtasn1, nettle, p11-kit, openssl@1.1, libnghttp2, unbound, gnutls, fribidi, pcre2, glib, libxau, libxdmcp, libxcb, libx11, libxext, libxrender, pixman, icu4c, harfbuzz, libunibreak, libass, libbluray, mbedtls, librist, libvidstab, libvpx, openjpeg, rav1e, libsamplerate, flac, mpg123, libsndfile, rubberband, sdl2, snappy, srt, leptonica, libarchive, pango and tesseract
...

Followed by 30 minutes of stuff and hundred of lines of log (how can brew be so freaking slow???), until:

==> ffmpeg@4
ffmpeg@4 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have ffmpeg@4 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/ffmpeg@4/bin:$PATH"' >> ~/.zshrc

For compilers to find ffmpeg@4 you may need to set:
  export LDFLAGS="-L/usr/local/opt/ffmpeg@4/lib"
  export CPPFLAGS="-I/usr/local/opt/ffmpeg@4/include"
==> gawk
GNU "awk" has been installed as "gawk".
If you need to use it as "awk", you can add a "gnubin" directory
to your PATH from your ~/.bashrc and/or ~/.zshrc like:

    PATH="/usr/local/opt/gawk/libexec/gnubin:$PATH"
fred@fredosx ~ % 

Then:

fred@fredosx ~ % brew unlink ffmpeg
Unlinking /usr/local/Cellar/ffmpeg/6.0... 110 symlinks removed.
fred@fredosx ~ % brew link ffmpeg@4
Linking /usr/local/Cellar/ffmpeg@4/4.4.4... 116 symlinks created.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/ffmpeg@4/bin:$PATH"' >> ~/.zshrc
fred@fredosx ~ % 

So now ffmpeg should be OK.

Now, getting the source:

fred@fredosx ~ % git clone  https://github.com/fstark/macflim.git
Cloning into 'macflim'...
remote: Enumerating objects: 1071, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 1071 (delta 4), reused 8 (delta 3), pack-reused 1055
Receiving objects: 100% (1071/1071), 67.20 MiB | 16.61 MiB/s, done.
Resolving deltas: 100% (743/743), done.
fred@fredosx ~ % 

The compiling:

fred@fredosx ~ % cd macflim/src
fred@fredosx src % make
c++  -std=c++2a -c -O3 -I liblzg/src/include flimmaker.cpp -o flimmaker.o
In file included from flimmaker.cpp:37:
In file included from ./flimencoder.hpp:6:
In file included from ./flimcompressor.hpp:7:
./compressor.hpp:154:59: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
    virtual std::string name() const { char buffer[1024]; sprintf( buffer, "z%lu", sizeof(T)*8 ); return buffer; }
                                                          ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here
__deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
^
[REMOVED A LOT OF CRAP]
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here
__deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg'
        #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                      ^
6 warnings generated.
c++  -std=c++2a flimmaker.o imgcompress.o image.o watermark.o ruler.o reader.o writer.o -lavformat -lavcodec -lavutil -o ../flimmaker
cc -O3 -Wno-unused-result  flimutil.c -o ../flimutil
fred@fredosx src %

There are warnings due to the new clang being an ass on sprintf and tmpnam. Also warnings from ffmpeg4 as they deprecated a function but seem completely unabkle to give clear instruction on what to use instead. Having spent many dozen of hours to get this running, I am not too enthousastic at going throught the frustration again soon.

Then make sure you have yt-dlp up to date:

fred@fredosx src % brew upgrade yt-dlp
==> Downloading https://formulae.brew.sh/api/formula.jws.json
################################################################################################################################ 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
################################################################################################################################ 100.0%
==> Upgrading 1 outdated package:
yt-dlp/taps/yt-dlp 2021.11.10.1 -> 2023.3.4
==> Fetching yt-dlp/taps/yt-dlp
==> Downloading https://files.pythonhosted.org/packages/2a/18/70c32fe9357f3eea18598b23aa9ed29b1711c3001835f7cf99a9818985d0/Brotli-1.0.9
################################################################################################################################ 100.0%
==> Downloading https://files.pythonhosted.org/packages/cc/85/319a8a684e8ac6d87a1193090e06b6bbb302717496380e225ee10487c888/certifi-2022
################################################################################################################################ 100.0%
==> Downloading https://files.pythonhosted.org/packages/f3/d9/2232a4cb9a98e2d2501f7e58d193bc49c956ef23756d7423ba1bd87e386d/mutagen-1.45
################################################################################################################################ 100.0%
==> Downloading https://files.pythonhosted.org/packages/52/0d/6cc95a83f6961a1ca041798d222240890af79b381e97eda3b9b538dba16f/pycryptodome
################################################################################################################################ 100.0%
==> Downloading https://files.pythonhosted.org/packages/f8/a3/622d9acbfb9a71144b5d7609906bc648c62e3ca5fdbb1c8cca222949d82c/websockets-1
################################################################################################################################ 100.0%
==> Downloading https://files.pythonhosted.org/packages/e8/4a/1e01f24fcb49191626e2b17d00e13a093315d03a9da09fccb1c75913e420/yt-dlp-2023.
################################################################################################################################ 100.0%
==> Upgrading yt-dlp/taps/yt-dlp
  2021.11.10.1 -> 2023.3.4 

==> python3.11 -m venv --system-site-packages /usr/local/Cellar/yt-dlp/2023.3.4/libexec
==> /usr/local/Cellar/yt-dlp/2023.3.4/libexec/bin/pip install -v --no-deps --no-binary :all: --use-feature=no-binary-enable-wheel-cache
==> /usr/local/Cellar/yt-dlp/2023.3.4/libexec/bin/pip install -v --no-deps --no-binary :all: --use-feature=no-binary-enable-wheel-cache
==> /usr/local/Cellar/yt-dlp/2023.3.4/libexec/bin/pip install -v --no-deps --no-binary :all: --use-feature=no-binary-enable-wheel-cache
==> /usr/local/Cellar/yt-dlp/2023.3.4/libexec/bin/pip install -v --no-deps --no-binary :all: --use-feature=no-binary-enable-wheel-cache
==> /usr/local/Cellar/yt-dlp/2023.3.4/libexec/bin/pip install -v --no-deps --no-binary :all: --use-feature=no-binary-enable-wheel-cache
==> /usr/local/Cellar/yt-dlp/2023.3.4/libexec/bin/pip install -v --no-deps --no-binary :all: --use-feature=no-binary-enable-wheel-cache
==> Caveats
zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
🍺  /usr/local/Cellar/yt-dlp/2023.3.4: 4,134 files, 46.8MB, built in 1 minute 13 seconds
==> Running `brew cleanup yt-dlp`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Removing: /usr/local/Cellar/yt-dlp/2021.11.10.1... (2,986 files, 26.0MB)
fred@fredosx src % 

Here we are:

fred@fredosx src % cd ..
fred@fredosx macflim % ./flimmaker 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' --mp4 test.mp4
[youtube] Extracting URL: https://www.youtube.com/watch?v=dQw4w9WgXcQ
[youtube] dQw4w9WgXcQ: Downloading webpage
[youtube] dQw4w9WgXcQ: Downloading android player API JSON
[info] dQw4w9WgXcQ: Downloading 1 format(s): 22
[download] Destination: /var/tmp/tmp.0.XhyOwj
[download] 100% of   19.09MiB in 00:00:00 at 53.99MiB/s
Encoding arguments :
--byterate 6000 --fps-ratio 1 --group true --bars false --dither error --error-stability 0.3 --error-algorithm floyd --error-bidi 1 --error-bleed 0.99 --filters g1.6sc --codec null --codec z32 --codec lines --codec invert --silent false
Read 5301 frames
POSTER INDEX: 2500
**** fps               : 25/1=25
**** # of input images : 5301
**** # of movie ticks  : 12722
Encoded 5301 output frames
95.6% of frames are within 1% of the target pixels
96.4% of frames are within 2% of the target pixels
97.3% of frames are within 5% of the target pixels
PROFILE BYTERATE 6000
[libx264 @ 0x7f8e4444aa00] non-strictly-monotonic PTS
[mp4 @ 0x7f8e46b90000] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 1500 >= 1500
Wrote 12722 frames
Removing '/var/tmp/tmp.0.XhyOwj'
[aac @ 0x7f8e45c83e00] 2 frames left in the queue on closing
fred@fredosx macflim % ls -l test.mp4 
-rw-r--r--  1 fred  staff  713045823 Jun  1 18:59 test.mp4
fred@fredosx macflim % ls -l out.flim 
-rw-r--r--  1 fred  staff  79087382 Jun  1 18:59 out.flim
fred@fredosx macflim % 

Success!

fstark commented 1 year ago

(btw, sent you a DM on discord a couple of days ago so we can debug that)

fstark commented 1 year ago

This is fixed. The issue was:

a) a linux binary was weirdly in the macflim directory of OSX (no idea how you managed to get this) b) the Makefile had to be changed to add the new path for homebrew libraries in OSX.

I'll change the Makefile so it works by default on M1 macs.