owickstrom / komposition

The video editor built for screencasters
https://owickstrom.github.io/komposition/
Mozilla Public License 2.0
429 stars 21 forks source link

Unable to preview video #48

Closed danbroooks closed 6 years ago

danbroooks commented 6 years ago

When I attempt to preview a video, the preview window will open, however the video will not play. In the terminal i get the following output:

ffmpeg -v quiet -stats -nostdin -i /tmp/project.komposition-e7528f83531c4127/HKT-Video.flv -filter_complex scale=width=640:height=360:force_original_aspect_ratio=disable -f mp4 -framerate 25 -vcodec h264 /tmp/project.komposition-e7528f83531c4127/proxies/HKT-Video.proxy.mp4
Extracting frame at 00:00:0.0 from /tmp/project.komposition-e7528f83531c4127/proxies/HKT-Video.proxy.mp4.
ffmpeg -nostdin -ss 0.0 -i /tmp/project.komposition-e7528f83531c4127/proxies/HKT-Video.proxy.mp4 -vf scale=1920:1080 -t 1 -vframes 1 /tmp/project.komposition-e7528f83531c4127/1988438641208273781.png
ffmpeg -v quiet -stats -nostdin -i /tmp/project.komposition-e7528f83531c4127/HKT-Video.flv -f lavfi -i aevalsrc=0:duration=238.733 -filter_complex [0:v:0]trim=start=0.0:duration=238.733,scale=width=960:height=540:force_original_aspect_ratio=disable,setpts=PTS-STARTPTS[v0];[1:a:0]asetpts=PTS-STARTPTS[a1];[v0]concat=n=1:v=1:a=0,setpts=PTS-STARTPTS[video];[a1]concat=n=1:v=0:a=1,asetpts=PTS-STARTPTS[audio] -map [video] -map [audio] -f matroska -framerate 25 -vcodec h264 -acodec aac -listen 1 http://localhost:12345
Could not establish connection to server. (5): Could not establish connection to server.
Internal data stream error. (1): Internal data stream error.
Stream doesn't contain enough data. (4): Stream doesn't contain enough data.

When I close the window, and attempt to preview again, komposition crashes and I get the following output:

ffmpeg -v quiet -stats -nostdin -i /tmp/project.komposition-e7528f83531c4127/HKT-Video.flv -f lavfi -i aevalsrc=0:duration=238.733 -filter_complex [0:v:0]trim=start=0.0:duration=238.733,scale=width=960:height=540:force_original_aspect_ratio=disable,setpts=PTS-STARTPTS[v0];[1:a:0]asetpts=PTS-STARTPTS[a1];[v0]concat=n=1:v=1:a=0,setpts=PTS-STARTPTS[video];[a1]concat=n=1:v=0:a=1,asetpts=PTS-STARTPTS[audio] -map [video] -map [audio] -f matroska -framerate 25 -vcodec h264 -acodec aac -listen 1 http://localhost:12345

ERROR: Caught a segmentation fault while loading plugin file:
/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstlibav.so

Please either:
- remove it and restart.
- run with --gst-disable-segtrap --gst-disable-registry-fork and debug.

When running the outputted command directly in the terminal, and without -v quiet I get this:

λ ffmpeg -stats -nostdin -i /tmp/project.komposition-e7528f83531c4127/HKT-Video.flv -f lavfi -i aevalsrc=0:duration=238.733 -filter_complex [0:v:0]trim=start=0.0:duration=238.733,scale=width=960:height=540:force_original_aspect_ratio=disable,setpts=PTS-STARTPTS[v0];[1:a:0]asetpts=PTS-STARTPTS[a1];[v0]concat=n=1:v=1:a=0,setpts=PTS-STARTPTS[video];[a1]concat=n=1:v=0:a=1,asetpts=PTS-STARTPTS[audio] -map [video] -map [audio] -f matroska -framerate 25 -vcodec h264 -acodec aac -listen 1 http://localhost:12345
ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, flv, from '/tmp/project.komposition-e7528f83531c4127/HKT-Video.flv':
  Metadata:
    encoder         : Lavf56.40.101
  Duration: 00:03:58.73, start: 0.067000, bitrate: 227 kb/s
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080, 2500 kb/s, 30.30 fps, 30 tbr, 1k tbn, 60 tbc
    Stream #0:1: Audio: aac (LC), 44100 Hz, stereo, fltp, 128 kb/s
Input #1, lavfi, from 'aevalsrc=0:duration=238.733':
  Duration: N/A, start: 0.000000, bitrate: 2822 kb/s
    Stream #1:0: Audio: pcm_f64le, 44100 Hz, mono, dbl, 2822 kb/s
Filter setpts has an unconnected output
zsh: command not found: [1:a:0]asetpts=PTS-STARTPTS[a1]
zsh: command not found: [v0]concat=n=1:v=1:a=0,setpts=PTS-STARTPTS[video]
zsh: command not found: [a1]concat=n=1:v=0:a=1,asetpts=PTS-STARTPTS[audio]

I think the issue may lie in the fact that there are ;'s in the options passed to filter_complex... zsh is then treating the options following the first block as an entirely new command. So if I wrap this portion in "'s, the command is successful:

λ ffmpeg -stats -nostdin -i /tmp/project.komposition-e7528f83531c4127/HKT-Video.flv -f lavfi -i aevalsrc=0:duration=238.733 -filter_complex "[0:v:0]trim=start=0.0:duration=238.733,scale=width=960:height=540:force_original_aspect_ratio=disable,setpts=PTS-STARTPTS[v0];[1:a:0]asetpts=PTS-STARTPTS[a1];[v0]concat=n=1:v=1:a=0,setpts=PTS-STARTPTS[video];[a1]concat=n=1:v=0:a=1,asetpts=PTS-STARTPTS[audio]" -map [video] -map [audio] -f matroska -framerate 25 -vcodec h264 -acodec aac -listen 1 http://localhost:12345
ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, flv, from '/tmp/project.komposition-e7528f83531c4127/HKT-Video.flv':
  Metadata:
    encoder         : Lavf56.40.101
  Duration: 00:03:58.73, start: 0.067000, bitrate: 227 kb/s
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080, 2500 kb/s, 30.30 fps, 30 tbr, 1k tbn, 60 tbc
    Stream #0:1: Audio: aac (LC), 44100 Hz, stereo, fltp, 128 kb/s
Input #1, lavfi, from 'aevalsrc=0:duration=238.733':
  Duration: N/A, start: 0.000000, bitrate: 2822 kb/s
    Stream #1:0: Audio: pcm_f64le, 44100 Hz, mono, dbl, 2822 kb/s

and I am able to open http://localhost:12345/ with VLC and said video plays successfully.

I attempted to tweak the printFilterGraph function in src/Komposition/FFmpeg/Command.hs like so:

printFilterGraph :: FilterGraph -> Text
printFilterGraph (FilterGraph chains) = "\"" <> printFilterComplex <> "\"" 
  where
    printFilterComplex =
      Text.intercalate ";" (NonEmpty.toList (map printFilterChain chains))

    printFilterChain (FilterChain calls) =
      Text.intercalate "," (NonEmpty.toList (map printRoutedFilter calls))

    printRoutedFilter RoutedFilter {..} =
      foldMap (encloseInBrackets . printStreamSelector) filterInputs
        <> printFilter routedFilter
        <> foldMap (encloseInBrackets . printStreamSelector) filterOutputs

Only now this breaks the command that imports the video via the Import Assets menu option. I'm not sure why this is broken now, testing the ffmpeg output for the import directly in the terminal converts the video just fine. So I am unsure about how to proceed at this point.

owickstrom commented 6 years ago

Regarding printing the command, when the arguments are passed to the process library, they are quoted correctly by it. Thus, we can't add quotes to the arguments in the printer, but we need to do it at the very end where printing the command with putStrLn and unwords:

  -- in Komposition.FFmpeg.Process
  ...
  liftIO (putStrLn (Prelude.unwords ("ffmpeg" : allArgs)))
  ...

There each arg in the allArgs need to be wrapped in quotes.

danbroooks commented 6 years ago

Hi @owickstrom, apologies for the delayed response, I've been meaning to test this out for a bit but only just found the time!

Unfortunately I am still having this issue, I am able to import the video and append it to the timeline, but once I hit play a black box appears and I get the seg fault issue as described above.

You say in #52 that it is not the ideal solution, so you may want to undo those changes if you believed it would fix this issue (and it doesn't relate to a fix for anything else). It's quite possible that it is something on my machine not running right, or some incompatibility thing with ffmpeg... I'm not too sure. I'm running on Ubuntu 18.04 if that helps anything.

owickstrom commented 6 years ago

@danbroooks OK, I see. The segfault issue is related to the Gstreamer plugins version bundled with Ubuntu 18.04, I'm afraid. I haven't found any workaround to this issue (I'm using Nix as on Ubuntu so not getting the issue that way). I guess you could try installing Gstreamer and its plugins from source. Other than that, I'm not really sure how to fix it. :disappointed: