How to play youtube song in terminal with ffplay and youtube-dl - linux

Is there any you to stream any music the terminal with youtube-dl and ffplay
I know that ffplay can play audio with shell
$ audio stram | ffplay -i -

You can try this:
youtube-dl -f bestaudio ytsearch:"SONG NAME" -o - 2>/dev/null | ffplay -nodisp -autoexit -i - &>/dev/null
Or:
youtube-dl -f bestaudio VIDEO_URL -o - 2>/dev/null | ffplay -nodisp -autoexit -i - &>/dev/null

..and if you mordernize the command a little you can play YT-videos from the terminal without ads.
youtube-dl -f mp4 YOUTUBE_VIDEO_URL -o - 2>/dev/null | ffplay -autoexit -i - &>/dev/null
Due to YouTube at the moment are throttlening youtube-dl I'm now using yt-dlp instead. Same codebase but no throttlening :)
yt-dlp -f mp4 YOUTUBE_VIDEO_URL -o - 2>/dev/null | ffplay -autoexit -i - &>/dev/null

Related

Adjusting webcam settings before shooting a photo (v4l2 and fswebcam)

I'm shooting photos with
sudo fswebcam -d /dev/video0 -r 1920x1080 --no-banner /media/networkshare/public/"Temp Photo Holder SolidScape Right"/timelapse_$DATE.jpg
on a Raspberry Pi 3 B+ running a recent version of Raspbian.
The script is controlling a Logitech c920 that has adjustable features like focus, brightness, contrast, etc.
I think the reason the 'manual' settings are not being saved is because I call the v4l2-ctl commands, add a delay, and then use fswebcam to shoot, like so:
#!/bin/bash
DATE=$(date +"%y%m%d%H%M%S")
#sudo v4l2-ctl -d /dev/video0 -c focus_auto=false
#sudo v4l2-ctl -d /dev/video0 -c focus_absolute=35
sudo v4l2-ctl -d /dev/video0 -c brightness=128
sudo v4l2-ctl -d /dev/video0 -c contrast=128
sudo v4l2-ctl -d /dev/video0 -c saturation=128
sudo v4l2-ctl -d /dev/video0 -c gain=15
sudo v4l2-ctl -d /dev/video0 -c sharpness=128
sleep 2
sudo v4l2-ctl -c exposure_auto_priority=1
#fswebcam -d /dev/video0 -r 1920x1080 --no-banner /media/networkshare/public/RasPi/"Temp Photo Holder SS"/timelapse_$DATE.jpg
sudo fswebcam -d /dev/video0 -r 1920x1080 --no-banner /media/networkshare/public/"Temp Photo Holder SolidScape Right"/timelapse_$DATE.jpg
sleep 9
sudo fswebcam -d /dev/video0 -r 1920x1080 --no-banner /media/networkshare/public/"Temp Photo Holder SolidScape Right"/timelapse_$DATE.jpg
sleep 9
How can I take a photo with manual settings appended? Maybe I need to add commands to fswebcam inline instead of calling v4l2-ctl first?
Everything is working.
No changes were needed.
I wasn't changing settings dramatically enough to notice a difference in the output.

ffmpeg and grep not working to extract mean_volume value

I have a list of mp3 files and i want to set all mean_volume to the same db value using a script, so I enter the command for detecting the value (https://trac.ffmpeg.org/wiki/AudioVolume) and I try to grep the value but it fails and instead prints all the output from the ffmpeg command. Any thoughts?
Also tried tr instead of grep. The command I used is:
ffmpeg -i sample.mp3 -filter:a volumedetect -f null /dev/null | grep 'mean_volume'
ffmpeg console output is stderr, so you need to redirect to stdout:
ffmpeg -i input.mp3 -filter:a volumedetect -f null - 2>&1 | grep mean_volume
or for Bash 4+:
ffmpeg -i input.mp3 -filter:a volumedetect -f null - |& grep mean_volume
Result:
[Parsed_volumedetect_0 # 0x564635d62800] mean_volume: -22.6 dB
If you just want the value use awk:
ffmpeg -i input.mp3 -filter:a volumedetect -f null - |& awk -F': ' '/mean_volume/ {print $2}'
Result:
-22.6 dB

First character disappears when piping script with ffmpeg to bash

I often create bash scripts with bash and pipe the results to bash... When I do this:
echo -e "ffmpeg -loglevel quiet -f lavfi -i nullsrc -t 1 -f null /dev/null\necho foo"|bash
I get
bash: line 2: cho: command not found
Where did the 'e' of 'echo' go? What does ffmpeg do there? Other commands work fine.
Note also:
echo -e "ffmpeg -loglevel quiet -f lavfi -i nullsrc -t 1 -f null /dev/null\necho foo" > /tmp/foo.sh
bash /tmp/foo.sh #works
bash < /tmp/foo.sh #doesn't
ffmpeg also reads from standard input, which it inherits from its parent process, which is the bash process reading your command line. This means ffmpeg is reading the e from echo following the new line.
One fix is to redirection standard input for ffmpeg:
echo -e "ffmpeg -loglevel quiet -f lavfi -i nullsrc -t 1 -f null /dev/null < /dev/null \necho foo"|bash
However, I can't help but point out that there isn't really any reason to run a script like this. If you want it in a separate process, start a subshell:
(
ffmpeg -loglevel quiet -f lavfi -i nullsrc -t 1 -f null /dev/null
echo foo
)

Play an MP3 file as it's being written

I'm saving an fm station to an mp3 file using rtl_fm and sox.
rtl_fm to capture the signal and sox to transcode it to mp3.
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 | sox -traw -r8k -es -b16 -c1 -V1 - -tmp3 - | sox -tmp3 - some_file.mp3
Then I'm trying to play that file in a second terminal, as the mp3 is being written using:
play -t mp3 some_file.mp3
The problem is that it only plays up until the time the mp3 had at the time the play command was invoked.
How do I get it to play the appended mp3 over time, while it's being written?
EDIT:
Running on Raspberry Pi 3 (Raspian Jessie), NooElec R820T SDR
There are a couple of things here. I don't think sox supports "tailing" a file, but I know mplayer does. However, in order to have better control over the pipeline, using gstreamer might be the way to go, as it has a parallel event stream built into its effects pipeline.
If you want to stick with sox, I would first get rid of the redundant second invocation of sox, e.g.:
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 |
sox -ts16 -r8k -c1 -V1 - some_file.mp3
And in order to play the stream while transcoding it, you could multiplex it with tee, e.g.:
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 |
tee >(sox -ts16 -r8k -c1 -V1 - some_file.mp3) |
play -ts16 -r8k -c1 -
Or if you want them to be separate processes:
# Save stream to a file
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 > some_file.s16
# Encode stream
sox -ts16 -r8k -c1 -V1 some_file.s16 some_file.mp3
# Start playing the file at 10 seconds in
tail -c+$((8000 * 10)) -f some_file.s16 |
play -ts16 -r8k -c1 -

Drawtext FPS avconv

Is it possible to write the fps with drawtext off avconv, i can't find information about it.
drawtext=fontfile=arial.ttf:text=
The full command i use without drawtext:
avconv -f rawvideo -pix_fmt gray -r 8 -s 640x480 -i - -an -t 00:00:30 -f rawvideo -r 8 -y \"/dev/xillybus_write_32\"

Resources