shaka-project / shaka-streamer

A simple config-file based approach to preparing streaming media, based on FFmpeg and Shaka Packager.
https://shaka-project.github.io/shaka-streamer/
Apache License 2.0
200 stars 64 forks source link

Help debugging python transcoding / streaming server #100

Closed inglesuniversal closed 3 years ago

inglesuniversal commented 3 years ago

After installing the scripts and libraries on my MacBook Air ... I was able to upload the transcoded MOV file into one of my AWS buckets.... I left ALL the settings in the pipeline_vod_file.yaml UNTOUCHED.

The video plays beautifully on your Player or pasting the URL on my desktop copy of VLC

BUT...

NO audio comes out in the output files once stored on my bucket, during playback the speaker icon remains disabled all the way through.

Any IDEAS on how to enable the audio / codec properly?

Regards

Hugo Barbosa

PS: Amazing Project!!!

joeyparrish commented 3 years ago

Hi Hugo,

Can you please share your input and pipeline config files, as well as the output of ffprobe -i /path/to/yourfile.mov?

It could be something missing in your input or pipeline config, or it could be an issue detecting the audio stream in your original MOV file.

Thanks!

inglesuniversal commented 3 years ago

Thanks for the prompt reply...

$    ffprobe -i SAMPLE_FILE.mov 
ffprobe version 4.4 Copyright (c) 2007-2021 the FFmpeg developers
built with Apple clang version 12.0.5 (clang-1205.0.22.9)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.4_2 --enable-shared --enable-pthreads --enable-version3 --cc=clang -- 
host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable- 
libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable- 
libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp -- 
enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable- 
libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable- 
libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack -- 
enable-avresample --enable-videotoolbox
libavutil      56. 70.100 / 56. 70.100
libavcodec     58.134.100 / 58.134.100
libavformat    58. 76.100 / 58. 76.100
libavdevice    58. 13.100 / 58. 13.100
libavfilter     7.110.100 /  7.110.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  9.100 /  5.  9.100
libswresample   3.  9.100 /  3.  9.100
libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'SAMPLE_FILE.mov':
Metadata:
major_brand     : qt  
minor_version   : 0
compatible_brands: qt  
creation_time   : 2021-04-16T18:09:14.000000Z
com.apple.quicktime.make: Apple
com.apple.quicktime.model: iPhone 11
com.apple.quicktime.software: 14.4.2
com.apple.quicktime.creationdate: 2021-04-16T13:09:14-0500
Duration: 00:00:16.37, start: 0.000000, bitrate: 8035 kb/s
Stream #0:0(und): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709), 1920x1080, 7739 kb/s, 30 fps, 30 tbr, 600 
tbn, 600 tbc (default)
Metadata:
  rotate          : 180
  creation_time   : 2021-04-16T18:09:14.000000Z
  handler_name    : Core Media Video
  vendor_id       : [0][0][0][0]
  encoder         : HEVC
Side data:
  displaymatrix: rotation of -180.00 degrees
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 188 kb/s (default)
  Metadata:
  creation_time   : 2021-04-16T18:09:14.000000Z
  handler_name    : Core Media Audio
  vendor_id       : [0][0][0][0]
Stream #0:2(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
Metadata:
  creation_time   : 2021-04-16T18:09:14.000000Z
  handler_name    : Core Media Metadata
Stream #0:3(und): Data: none (mebx / 0x7862656D), 39 kb/s (default)
Metadata:
  creation_time   : 2021-04-16T18:09:14.000000Z
  handler_name    : Core Media Metadata
Stream #0:4(und): Data: none (mebx / 0x7862656D), 47 kb/s (default)
Metadata:
  creation_time   : 2021-04-16T18:09:14.000000Z
  handler_name    : Core Media Metadata
  Unsupported codec with id 0 for input stream 2
  Unsupported codec with id 0 for input stream 3
  Unsupported codec with id 0 for input stream 4
inglesuniversal commented 3 years ago

YAML FILES follow... Archive.zip .

joeyparrish commented 3 years ago

Your input file only specifies the video stream. Where you have this:

  - name: Papa_y_Sunny_Teleferico.mov
    media_type: video

You need this:

  # We want the video from this,
  - name: Papa_y_Sunny_Teleferico.mov
    media_type: video
  # as well as audio from the same.
  - name: Papa_y_Sunny_Teleferico.mov
    media_type: audio

It is structured this way because you can add audio and video from different sources, and/or add multiple audio tracks (different languages, for example).

Does this help?

inglesuniversal commented 3 years ago

IT WORKED!!!

I'm speechless!!! Way to go!!!

Now... what would be the steps to mount this on a python3 web server having curl / php / node.js in order to call this function once the files (MOV) are uploaded.

Can this script work with remote URLs or the files have to be in the same folder (downloaded first)?

I have access to EC2 and Bitnami Servers at AWS

NOTE: How can I extract the 1st frame as an image (.jpg or preferably .webp) ?

Best regards

joeyparrish commented 3 years ago

Now... what would be the steps to mount this on a python3 web server having curl / php / node.js in order to call this function once the files (MOV) are uploaded.

You can use the Python module API instead of the command-line in your Python-based web server, and there's a great example of this in our test runner. Check out run_end_to_end_tests.py, which uses Flask to run a web server and trigger Streamer encodes based on web requests. Our tests (written in JavaScript, running in a browser) will send a request to the local test server to start an encoder, then start streaming the content from the local server to test that it is playable (using Shaka Player in the browser).

Can this script work with remote URLs or the files have to be in the same folder (downloaded first)?

With a new release of shaka-streamer-binaries including the fix for https://github.com/joeyparrish/static-ffmpeg-binaries/issues/2, we will be able to do that. The n4.4-1 release of static-ffmpeg-binaries and the corresponding 0.5.0 release of shaka-streamer-binaries are missing TLS support in FFmpeg.

I'll try to get that out soon.

NOTE: How can I extract the 1st frame as an image (.jpg or preferably .webp) ?

I suggest you use FFmpeg directly for this: https://stackoverflow.com/a/27573049

joeyparrish commented 3 years ago

With a new release of shaka-streamer-binaries including the fix for joeyparrish/static-ffmpeg-binaries#2, we will be able to do that. The n4.4-1 release of static-ffmpeg-binaries and the corresponding 0.5.0 release of shaka-streamer-binaries are missing TLS support in FFmpeg.

The n4.4-2 release is out, as well as the corresponding 0.5.1 release of shaka-streamer-binaries. You should be able to update now with:

pip install --upgrade shaka-streamer-binaries

Then https resource URLs will work as expected.

inglesuniversal commented 3 years ago

Wow... Can't stop praising your work and your generous help to get me started.

Tried the update locally on my MacBook Air and then on one of my AWS-VM's and in both scenarios ... It worked like a charm!

It nicely fetched a remote URL without even having to encode its very long path .... Simply amazing!

So, where do I go from here?

Out of Django and Flask which one is the fastest way to accomplish adding a web interface to this beauty?

Best regards!

Hugo Barbosa

inglesuniversal commented 3 years ago

SIDENOTE:

While I was writing this answer .... this tiny error came up on my remote server ... which I fixed with the following commands:

sudo apt-get install gcc python-dev python-setuptools
sudo easy_install -U pip
sudo pip uninstall crcmod
sudo pip3 install -U crcmod
inglesuniversal commented 3 years ago

Oops ... Something make the process come to a full stop on my remote server .... Can you please take a look at the end of the log?

    sys.exit(gslib.__main__.main())
File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/__main__.py", line 444, in main
    user_project=user_project)
File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/__main__.py", line 782, in _RunNamedComm
andAndHandleExceptions
    _HandleUnknownFailure(e)
File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/__main__.py", line 639, in _RunNamedComm
andAndHandleExceptions
    user_project=user_project)
File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/command_runner.py", line 412, in RunName
dCommand
    return_code = command_inst.RunCommand()
File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/commands/rsync.py", line 1672, in RunCom
mand
    diff_iterator = _DiffIterator(self, src_url, dst_url)
File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/commands/rsync.py", line 1003, in __init
__
    fail_on_error=True)
File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/command.py", line 1524, in Apply
    parallel_operations_override=parallel_operations_override)
File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/command.py", line 1721, in _ParallelAppl
y
    user_project=self.user_project)
File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/command.py", line 2222, in __init__
    worker_thread.start()
File "/usr/lib/python3.7/threading.py", line 847, in start
    _start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
File "/usr/lib/python3.7/multiprocessing/managers.py", line 183, in accepter
    t.start()
File "/usr/lib/python3.7/threading.py", line 847, in start
    _start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread

Best regards

inglesuniversal commented 3 years ago

Ran it again with a brand new bucket at AWS ... and got this error too...

    frame=   40 fps=1.7 q=0.0 q=0.0 q=0.0 q=0.0 q=0.0 q=0.0 q=0.0 q=0.0 size=       0kB time=00:00:00.50 bitrate=   0.6kbits/s speed=
    Traceback (most recent call last):
    File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gsutil", line 21, in <module>
    gsutil.RunMain()
    File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gsutil.py", line 122, in RunMain
    sys.exit(gslib.__main__.main())
    File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/__main__.py", line 444, in main
    user_project=user_project)
    File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/__main__.py", line 782, in _RunNamedComm
    andAndHandleExceptions
    frame=   41 fps=1.6 q=0.0 q=0.0 q=0.0 q=0.0 q=0.0 q=0.0 q=0.0 q=0.0 size=       0kB time=00:00:00.53 bitrate=   0.5kbits/s speed=
    _HandleUnknownFailure(e)
    frame=   41 fps=1.6 q=0.0 q=0.0 q=0.0 q=0.0 q=0.0 q=0.0 q=0.0 q=0.0 size=       0kB time=00:00:00.53 bitrate=   0.5kbits/s speed=
    _HandleUnknownFailure(e)
    File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/__main__.py", line 639, in _RunNamedComm
    andAndHandleExceptions
    user_project=user_project)
    File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/command_runner.py", line 412, in RunName
    dCommand
    return_code = command_inst.RunCommand()
    File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/commands/rsync.py", line 1672, in RunCom
    mand
    diff_iterator = _DiffIterator(self, src_url, dst_url)
    File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/commands/rsync.py", line 1003, in __init
    __
    fail_on_error=True)
    File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/command.py", line 1524, in Apply
    parallel_operations_override=parallel_operations_override)
    File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/command.py", line 1721, in _ParallelAppl
    y
    user_project=self.user_project)
    File "/opt/bitnami/apache/htdocs/shaka-streamer/google-cloud-sdk/platform/gsutil/gslib/command.py", line 2222, in __init__
    worker_thread.start()
    File "/usr/lib/python3.7/threading.py", line 847, in start
    _start_new_thread(self._bootstrap, ())
    RuntimeError: can't start new thread
    Exception in cloud - (<class 'subprocess.CalledProcessError'>, CalledProcessError(1, ['gsutil', '-q', '-h', 'Cache-Control: no-st
    ore, no-transform', '-m', 'rsync', '-C', '-r', '-d', '-x', '.*m3u8', '-x', '.*mpd', 'output_files', 's3://mycloudvip-shaka-stream
    er/demo/']), <traceback object at 0x7f3454b2a0c8>)
    CloudNode: 'Continuing.'
mariocynicys commented 3 years ago

Hello @inglesuniversal , Based on this and this SoF threads, I think it is the system on the remote server blocking the creation of new threads due to a user limit.

mariocynicys commented 3 years ago

This issue might help.

inglesuniversal commented 3 years ago

Before I investigate any further. Are there any minimum requirements for this script to run? My Mac has 8gb or RAM while the remote VM has only 2 GB. Can codelab machines be used for this type of process?

mariocynicys commented 3 years ago

The script it self is light weight, but the ffmpeg and packager processes managed by the script may vary in resource usage based on the inputs and the pipeline used, there is no specific minimum requirement as per my knowledge, it is mostly based on how big your encoding pipeline is. Don't know about codelab :(, a google search surprisingly didn't help.

joeyparrish commented 3 years ago

My best advice for a template on how to run Shaka Streamer in a web server is our Flask-based test runner: https://github.com/google/shaka-streamer/blob/master/run_end_to_end_tests.py

As @meryacine mentioned, you may need more RAM depending on your pipeline settings. Assuming you don't want to spend more money on an instance with more RAM, I suggest you try reducing the max resolution or number of resolutions you're encoding in parallel.

inglesuniversal commented 3 years ago

Sure... I'll look into all the suggestions and ideas you and your TEAM are kindly proving me!

shaka-bot commented 3 years ago

Closing due to inactivity. If this is still an issue for you or if you have further questions, you can ask us to reopen or have the bot reopen it by including @shaka-bot reopen in a comment.