Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input from STDIN and spooling through audio/video. #109

Open
Demonstrandum opened this issue Oct 15, 2017 · 10 comments
Open

Input from STDIN and spooling through audio/video. #109

Demonstrandum opened this issue Oct 15, 2017 · 10 comments

Comments

@Demonstrandum
Copy link

Take input from STDIN from a pipe

I was wondering if piping the video data directly to mkchromecast through stdin would be possible.
e.g. data from the webcam:

ffmpeg -loglevel panic -f video4linux2 -i /dev/video0 -f ogg - | mkchromecast --video -
# The dash at the end in the ffmpeg command means it outputs to 
# STDOUT instead of to a file,
# and the dash in the mkchromecast command would mean it read
# the data from STDIN.

I couldn't find an way of doing this, so instead I recorded it to a separate file with

ffmpeg -f video4linux2 -i /dev/video0 -f ogg me.ogg

then in a separate shell session I streamed it:

mkchromecast --video me.ogg

which of course results in a huge delay as it reads form the beginning of the file, and the beginning was mkchromecast connecting.

This brings me on to my next question:

Spooling

Is there any way to spool backwards and forwards from whatever file it's reading, perhaps a way to go back to the beginning of the file or go to the very end (useful for streaming continuously growing file like from a webcam).

I don't know if any of this seems reasonable.

@muammar
Copy link
Owner

muammar commented Oct 16, 2017

I will try to put something together, but I am more than happy to receive a PR if you want to.

@muammar
Copy link
Owner

muammar commented Dec 22, 2017

@Demonstrandum I have pushed fbae38e, can you check the devel branch and let me know if it works? The example you showed here should work in the following way:

python3 mkchromecast.py --video --command 'ffmpeg -f video4linux2 -i /dev/video0 -f ogg pipe:1'

@Demonstrandum
Copy link
Author

Hi, it might just be me but it doesn't seem to completely work. It even goes so far as to say it's streaming and I see a loading animation on the TV however it stops and then goes back to the default casting logo home screen.

I know streaming with seekable formats like mp3 is difficult and I was using ogg, so I set it to ogg for audio coding with the command:

python mkchromecast.py -c ogg --video --command 'ffmpeg -f video4linux2 -i /dev/video0 -f ogg pipe:1'

But yet it did not work.

One thing I saw when trying was the line:

The media type string used is: video/mp4

The video format should be ogg, how can I change this?

@muammar
Copy link
Owner

muammar commented Dec 22, 2017

Chromecast does not support ogg for video. Check this: https://developers.google.com/cast/docs/media. Could you try mp4 and let me know if it works? if it does, then I can update the documentation. Thanks.

@Demonstrandum
Copy link
Author

Trying with mp4 for the -f flag doesn't seem to work either. Does this work for you?

@muammar
Copy link
Owner

muammar commented Dec 22, 2017

Trying with mp4 for the -f flag doesn't seem to work either. Does this work for you?

I will try this again, you are right that it is not working. I will get back to you. Thanks for being so responsive.

@muammar
Copy link
Owner

muammar commented Dec 22, 2017

@Demonstrandum I have made a test. This is working for me:

python3 mkchromecast.py --video --command 'ffmpeg -re -i /path/to/myvideo.mp4 -map_chapters -1 -vcodec libx264 -preset ultrafast -tune zerolatency -maxrate 10000k -bufsize 20000k -pix_fmt yuv420p -g 60 -f mp4 -max_muxing_queue_size 9999 -movflags frag_keyframe+empty_moov pipe:1' 

The small flag that I implemented is working when I use the command above. This means that one has to find the right " ffmpeg command" that can be used to pipe correctly. I will let you know if I find how (you do the same if you can please). Then we can proceed to modify the documentation accordingly.

muammar added a commit that referenced this issue Dec 25, 2017
* devel: (98 commits)
  - Cleaning some of the modules. - I moved checkmktmp() and writePidFile() functions from __init__.py to utils.py.
  New `--loop` flag added to repeat videos when using ffmpeg or avconv. Related to #113.
  Updated version.py.
  Updated changelog.
  Fixed NameError found by Peter Meiser when no devices are found.
  start_tray functions were fixed for macOS bundle.
  Preparing release 0.3.8.
  Changed help about --command flag.
  - Node updated to 9.3.0 for macOS. - systray.py now imports sys.
  Now all code is PEP8 and Pyflakes clean.
  Removed app.py for this release.
  I added the --video flag to the --command example.
  New flag `command` for setting a custom ffmpeg command. Closes issue #109.
  audio.py is not PEP8 and pyflakes clean.
  This commit the `segment_time` flag has been fixed. Closes issue #71.
  Changelog updated.
  Minimal changes.
  mkchromecast.py is now PEP8 clean.
  Fixing TypeError in cast.py.
  Allow custom server port with ffmpeg or avconv. Related to #122.
  ...
@muammar
Copy link
Owner

muammar commented Mar 10, 2018

@Demonstrandum did it work for you?

@jlherren
Copy link

Any comment on the second part of the question about being able to seek within the video? I understand that jumping around in the video stream is non-trivial if the video is being transcoded/encoded on the fly. But given a H.264/AAC file which the chromecast can play natively it probably shouldn't be too hard. (Seeking would usually happen from the Google Home app.)

@Demonstrandum
Copy link
Author

@muammar Sorry for the slightly late response, but, no I can't seem to get it to work.
I see a little loading animation on the TV and nothing happens. I also tried the webcam stream through ffmpeg with the --command as well, but the webcam light only flashes on for a brief moment(?), turns off and nothing happens.

😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants