Search code examples
javajavafxmedia-playercodec

JavaFX media player does not play video


Using OpenJFX 11 I am using a mediaplayer to play some clips on a Linux system. Some of them display, others don't. As far as I can tell the only difference in the encoding is, that the not playing video contains an audio track. This is the output of mediainfo for the video that plays:

General
Complete name                            : OpenPatricianData/src/main/resources/video/event/BlackDeath.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 26.0 MiB
Duration                                 : 30s 0ms
Overall bit rate                         : 7 265 Kbps
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00
Writing application                      : Lavf54.63.104

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 30s 0ms
Bit rate                                 : 7 264 Kbps
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 24.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.146
Stream size                              : 26.0 MiB (100%)
Writing library                          : x264 core 142 r2389 956c8d8
Encoding settings                        : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=12 / lookahead_threads=2 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=24 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

And this the info for the one that is not working:

General
Complete name                            : OpenPatricianData/src/main/resources/video/event/fire.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 30.4 MiB
Duration                                 : 19s 368ms
Overall bit rate                         : 13.2 Mbps
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00
Writing application                      : Lavf54.63.104

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L5
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 19s 334ms
Bit rate                                 : 12.9 Mbps
Nominal bit rate                         : 40.0 Mbps
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 24.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.260
Stream size                              : 29.8 MiB (98%)
Writing library                          : x264 core 142 r2389 956c8d8
Encoding settings                        : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=0 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=12 / lookahead_threads=2 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=24 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=abr / mbtree=1 / bitrate=40000 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

Audio
ID                                       : 2
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 3
Mode                                     : Joint stereo
Codec ID                                 : 6B
Duration                                 : 19s 368ms
Bit rate mode                            : Constant
Bit rate                                 : 256 Kbps
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 KHz
Compression mode                         : Lossy
Stream size                              : 605 KiB (2%)
Default                                  : Yes
Alternate group                          : 1
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

There is no error message logged or displayed.

If I remember correctly this has worked before, when using JavaFX in version 8. Since then I also upgraded the OS, so it could be some missing codecs as well.

  1. How would I have to encode a video with sound, so that it is played using JavaFX MediaPlayer?
  2. If on certain OS it is required to supply additional codecs, as hinted by this old article, how to do that with a Maven project? I do not want the user to require to install additional libraries by hand, so that my application works.

[EDIT:] On the chance that it has anything to do with libavcodec here is the list returned by sudo find / -name 'libavcodec*':

/var/lib/dpkg/info/libavcodec-dev:amd64.list
/var/lib/dpkg/info/libavcodec-ffmpeg56:amd64.list
/var/lib/dpkg/info/libavcodec-ffmpeg56:amd64.shlibs
/var/lib/dpkg/info/libavcodec-ffmpeg56:amd64.symbols
/var/lib/dpkg/info/libavcodec-dev:amd64.md5sums
/var/lib/dpkg/info/libavcodec-ffmpeg56:amd64.triggers
/var/lib/dpkg/info/libavcodec-ffmpeg56:amd64.md5sums
/var/cache/apt/archives/libavcodec-ffmpeg56_7%3a2.8.14-0ubuntu0.16.04.1_amd64.deb
/var/cache/apt/archives/libavcodec-dev_7%3a2.8.15-0ubuntu0.16.04.1_amd64.deb
/var/cache/apt/archives/libavcodec-ffmpeg56_7%3a2.8.15-0ubuntu0.16.04.1_amd64.deb
/var/cache/apt/archives/libavcodec-dev_7%3a2.8.14-0ubuntu0.16.04.1_amd64.deb
/usr/lib/vlc/plugins/codec/libavcodec_plugin.so
/usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56
/usr/lib/x86_64-linux-gnu/libavcodec.so
/usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56.60.100
/usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.a
/usr/lib/x86_64-linux-gnu/libavcodec.a
/usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so
/usr/lib/x86_64-linux-gnu/pkgconfig/libavcodec-ffmpeg.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/libavcodec.pc
/usr/share/doc/libavcodec-ffmpeg56
/usr/share/doc/libavcodec-dev
/usr/share/lintian/overrides/libavcodec-ffmpeg56
/usr/include/x86_64-linux-gnu/libavcodec

Solution

  • Turns out that while MP3 is supported as audio, it is not supported for video, at least not out of the box for Linux.

    What works through is MP4 together with AAC for the audio track. At least this is true for Java 11, OpenJFX 11 on Linux Mint 18.3.