flathub / io.otsaloma.gaupol

https://flathub.org/apps/details/io.otsaloma.gaupol
0 stars 1 forks source link

Use the FFmpeg runtime #1

Open ricvelozo opened 4 years ago

ricvelozo commented 4 years ago

This app is taking too much space. Use the FFmpeg runtime like org.blender.Blender; this will reduce the size by 80%.

otsaloma commented 4 years ago

Hi! I didn't know an ffmpeg runtime had been added. I'll give it a try. Assuming no issues, it makes all sense to switch to it.

otsaloma commented 4 years ago

I tried this. The integrated video player worked fine and using ffmpeg-full allowed dropping gst-libav making the flatpak further smaller and faster to build. However, I couldn't get subtitles to show up in mpv. The error message in mpv's console was "Can not open external file xxx.srt." I don't even know if ffmpeg-full is usable for compiling mpv. I don't really know how to debug flatpak or understand what's include and where.

In summary: Help appreciated, but this might not be doable. Also, it might be worth just waiting around for an mpv flatpak. We only need ffmpeg for mpv and if I understand the extension system correctly, we could just include that instead of compiling and bundling a separate copy of mpv.

otsaloma commented 4 years ago

If someone wants to look into it, here's the starting point in the main Gaupol repo:

https://github.com/otsaloma/gaupol/tree/master/flatpak

diff --git a/flatpak/io.otsaloma.gaupol.yml b/flatpak/io.otsaloma.gaupol.yml
index 46dab0f5..336f4e75 100644
--- a/flatpak/io.otsaloma.gaupol.yml
+++ b/flatpak/io.otsaloma.gaupol.yml
@@ -16,21 +16,20 @@ finish-args:
   - --socket=wayland
   - --socket=x11
   - --talk-name=ca.desrt.dconf
+cleanup-commands:
+  - mkdir -p /app/lib/ffmpeg
+
+add-extensions:
+
+  org.freedesktop.Platform.ffmpeg-full:
+    directory: lib/ffmpeg
+    version: "19.08"
+    add-ld-path: .
+
 modules:

   # Internal video player codecs

-  - name: gst-libav
-    buildsystem: autotools
-    config-opts:
-      # Prefer upstream configuration over what happens to be in the runtime.
-      # https://github.com/flathub/org.gnome.Totem/commit/0c8ed1e25bfad9745ff002b8b3efae3cdd3aebde
-      - --with-system-libav=no
-    sources:
-      - type: archive
-        url: https://gstreamer.freedesktop.org/src/gst-libav/gst-libav-1.16.1.tar.xz
-        sha256: e8a5748ae9a4a7be9696512182ea9ffa6efe0be9b7976916548e9d4381ca61c4
-
   - name: gst-plugins-ugly
     buildsystem: meson
     sources:
@@ -53,13 +52,6 @@ modules:

   # External video player: mpv

-  - name: ffmpeg
-    buildsystem: autotools
-    sources:
-      - type: archive
-        url: https://ffmpeg.org/releases/ffmpeg-4.1.tar.xz
-        sha256: a38ec4d026efb58506a99ad5cd23d5a9793b4bf415f2c4c2e9c1bb444acd1994
-
   - name: fribidi
     buildsystem: autotools
     sources:
ricvelozo commented 4 years ago

@otsaloma I tested it here and it worked. Is it a specific codec causing problems, maybe? My test: H.264/MKV & SRT.

ricvelozo commented 4 years ago

@otsaloma Also, consider moving the Makefile to root of project to GNOME Builder to recognize the build system (the line 10 is unnecessary for that). It will be easier for new contributors. :smiley:

otsaloma commented 4 years ago

I tried a different preview command. One that doesn't try to load subtitles from a separate file, just to see if subtitles can be loaded elsewhere.

mpv --quiet --osd-level=2 --hr-seek=yes --start=$SECONDS $VIDEOFILE

Given a Matroska file with embedded SubRip subtitles, I got more useful output. It is indeed a decoder issue, but I can't tell why it happens.

[sub/ass] Could not open libavcodec subtitle converter
[sub] Could not find subtitle decoder for format 'subrip'.

I tested it here and it worked.

Flatpaks with versioned dependencies should be reproducible, that's a relevant point there, so it sounds weird it would work for you and not me. Just to check: did you apply the above patch to the latest gaupol from the main repo? Are you sure it was built successfully and you were actually running what you built instead of some earlier installation? (To be sure you can uninstall and make sure flatpak run io.otsaloma.gaupol fails before building.)

ricvelozo commented 4 years ago

To be sure, I uninstalled the app, and removed the files produced by flatpak-builder. Tested the last commit (https://github.com/otsaloma/gaupol/commit/fccf92cca64340fcb53b8ab59d15633168bca77a) with the above patch applied.

I ran Gaupol using flatpak-builder --run build-dir flatpak/io.otsaloma.gaupol.yml gaupol, and tested a different video (DivX MPEG-4 v5/AVI) with an external subtitle file.

I have org.freedesktop.Platform.ffmpeg//1.6, org.freedesktop.Platform.ffmpeg-full//19.08 and org.freedesktop.Platform.openh264 installed in my system. Still working haha.

ricvelozo commented 4 years ago

Using Flatpak 1.4.3, Fedora 31. If you want, I can send you the zipped files (.flatpak-builder and build-dir).

ricvelozo commented 4 years ago

Strangely, even after removing the ffmpeg extension from the YAML file, I can still build mpv (without cache). The build messages list ffmpeg as present.

otsaloma commented 4 years ago

Strangely, even after removing the ffmpeg extension from the YAML file, I can still build mpv (without cache). The build messages list ffmpeg as present.

For me as well, the compilation succeeds with ffmpeg commented out, but if I then run mpv via gaupol, it doesn't work at all since the extension is not mounted.

Failed to recognize file format.

My understanding is that org.gnome.Sdk includes org.freedesktop.Sdk, which includes ffmpeg development headers which are what's needed and detected during compilation. The extension then provides just the run-time ffmpeg libraries. If ffmpeg is compiled from source while building the flatpak, it basically provides and bundles both the development and run-time dependencies.

This still doesn't explain to me why with the ffmpeg-full extension video would work, but subtitles not. I can understand if the ffmpeg runtime is somehow cut down due to patent or whatever reasons, but I'd expect that to be a problem with some osbcure video formats, not SubRip subtitles.

Erick555 commented 4 years ago

This still doesn't explain to me why with the ffmpeg-full extension video would work, but subtitles not. I can understand if the ffmpeg runtime is somehow cut down due to patent or whatever reasons, but I'd expect that to be a problem with some osbcure video formats, not SubRip subtitles.

Currently runtime ffmpeg (plus ffmpeg-full) are build in a way which needs to explicitly enable every supported ffmpeg format (video/audio/image/whatever). Considering there are many (hundreds?) possible things to enable it's very plausible that something was missed.

Reporting missed things to https://gitlab.com/freedesktop-sdk/freedesktop-sdk will help to improve things.

otsaloma commented 4 years ago

Aha, OK, this doesn't seem like a good idea anymore. I'll leave the issue reporting to others; while we could perhaps get SubRip whitelisted, we'd just soon run into something else missing. This kind of a whitelist is inherently problematic and I suspect there is some kind of a minimalist goal here as the whitelist seems confusingly small.

If you have ffmpeg normally installed, compare it's output with what you get from the org.freedesktop.Sdk Flatpak!

$ flatpak run --command=bash org.freedesktop.Sdk
$ ffmpeg -formats
[...]
File formats:
 D. = Demuxing supported
 .E = Muxing supported
 --
 D  aac             raw ADTS AAC (Advanced Audio Coding)
 DE ac3             raw AC-3
 DE ass             SSA (SubStation Alpha) subtitle
 DE flac            raw FLAC
 DE gif             CompuServe Graphics Interchange Format (GIF)
  E matroska        Matroska
 D  matroska,webm   Matroska / WebM
 D  mov,mp4,m4a,3gp,3g2,mj2 QuickTime / MOV
 DE mp3             MP3 (MPEG audio layer 3)
 D  mpegvideo       raw MPEG video
 DE ogg             Ogg
  E opus            Ogg Opus
 DE wav             WAV / WAVE (Waveform Audio)
$ ffmpeg -codecs | grep SubRip
[...]
 ..S... srt                  SubRip subtitle with embedded timing
 ..S... subrip               SubRip subtitle

Edit: I'm not actually sure if the above is ffmpeg or ffmpeg-full.

Erick555 commented 4 years ago

Above is from ffmpeg (not -full). To use ffmpeg-full you have to declare it in manifest first (also install extension). Anyway ffmpeg-full isn't ready for every app.