bentasker / HLS-Stream-Creator

Simple Bash Script to take a media file, segment it and create an M3U8 playlist for serving using HLS
BSD 3-Clause "New" or "Revised" License
273 stars 101 forks source link

No exit error statuses #17

Open KingMob opened 6 years ago

KingMob commented 6 years ago

I was trying to use this as part of a general video pipeline, but the script doesn't exit with error codes if there are any problems (other than the one check to verify that ffmpeg exists). This makes it hard to know if it succeeded or not.

$ HLS-Stream-Creator.sh -i non-existent-file.mp4 -s 3

ffmpeg command found.... continuing
Creating ./output
Generating HLS segments - this may take some time
ffmpeg version 3.3.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.37)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-nonfree --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
non-existent-file.mp4: No such file or directory

$ echo $?  # Show the last command's exit status
0
bentasker commented 6 years ago

Do you fancy creating a pull to drop this in? I hit up against it the other day, but haven't had time to implement myself as I had to press on with what I was using.

The main challenge, though, will probably be getting exit statuses when we fork off multiple processes to handle different bitrates, and deciding how to handle them if a single bitrate fails.

If not, then as a (horrible) workaround, you can also look at how long the script ran for - if it completes within a few seconds then it failed. Not pretty by any means...

KingMob commented 6 years ago

Man, I wish I could help, but I doubt my shell-fu is up to the task.

If you want to simplify and remove the forking, I do know ffmpeg can use multiple threads/cores, and that it can produce multiple variants with different params from a single invocation, so multiple processes are probably not necessary for maximum speed.

E.g.:

$ ffmpeg -i input \
    ... [encoding parameters 1] ... output-variant1 \
    ... [encoding parameters 2] ... output-variant2 \
    ... [encoding parameters 3] ... output-variant3
bentasker commented 6 years ago

Yeah I toyed with that a little while back, but can't remember why I went the other route (probably have a note somewhere). I've a feeling it was because I needed to do something funky with some named pipes at the same time for a muxing appliance I was building. Will have to have a dig to see if I can find the info - otherwise may well be worth doing.

In the meantime, I've added this to the wishlist in JIRA - HLS-29

KingMob commented 6 years ago

I tried at one point to build up the command-line for each variant in a loop, but I couldn't quite figure out how to properly quote things for filenames with spaces. Best of luck.