Apple HLS with ffmpeg and mediastreamsegmenter and vlc - audio

I'm trying to stream using a ffmpeg stream from a windows box. Here is the command I'm running on the windows box
ffmpeg -f dshow -i audio=”Wave In 2 32130101 (Orban Optim” -acodec libmp3lame -ab 64k -f mpegts udp://172.30.16.181:2222?pkt_size=188?buffer_size=128000
This part works and I'm able to listen to it on my mac via VLC and I'm streaming it out from VLC to port 20103
but when I use mediasegmenter
mediastreamsegmenter -s 3 -f /Users/vickkrish/ 127.0.0.1:2222
This is what happens
Mar 6 2014 04:11:02.926: audio pid set at 44
Mar 6 2014 04:11:03.165: audio pid change to 44
Mar 6 2014 04:11:03.328: audio pid change to 44
Mar 6 2014 04:11:03.583: audio pid change to 44
Mar 6 2014 04:11:03.745: audio pid change to 44
Mar 6 2014 04:11:03.989: audio pid change to 44
Mar 6 2014 04:11:04.151: audio pid change to 44
Mar 6 2014 04:11:04.316: audio pid change to 44
Mar 6 2014 04:11:04.492: audio pid change to 44
Mar 6 2014 04:11:04.740: audio pid change to 44
Mar 6 2014 04:11:04.887: audio pid change to 44
Mar 6 2014 04:11:05.175: audio pid change to 44
Mar 6 2014 04:11:05.338: audio pid change to 44
Mar 6 2014 04:11:05.582: audio pid change to 44
and no .ts files are created.

Try to pipe FFmpeg's output to mediastreamsegmenter instead of making mediastreamsegmenter listen to a UDP port.
Something along the lines of
ffmpeg -i {video} -b:a {audio_bitrate} -b:v {video_bitrate} -vcodec libx264 -acodec aac -strict -2 - | mediastreamsegmenter -b {url_for_manifest} -f {directory_to_dump_ts} -D

Wouldn't it be easier to use VLC for transcoding AND segmenting? Something along lines of
ip=$1
port=$2
name=$3
host=$4
mkdir -p /wwwroot/$name
rm /wwwroot/$name/$name*.*
voptions="threads=4,width=720,height=576,fps=25,vcodec=h264,vb=2048,venc=x264{aud,profile=baseline,level=30,keyint=25,bframes=0,ref=1,nocabac},acodec=mp4a,ab=192,channels=2" # 2 mpbs Full D1
index="/wwwroot/$name/$name.m3u8"
idxurl="http://$host/$name/$name-########.ts"
dst="/wwwroot/$name/$name-########.ts"
vlc-wrapper -I dummy udp://#$ip:$port vlc://quit --sout="#transcode{$voptions}:duplicate{dst=std{access=livehttp{seglen=60,numsegs=60,index=$index,index-url=$idxurl},mux=ts{use-key-frames},dst=$dst}}" -vvv

Related

How to use wget with multithread and wildcards?

I want to use wget to download multiple files at once in a script using wildcards, like this:
wget -r -nd --no-parent --no-remove-listing $ftpUrl -l1 -A file1*.txt &
wget -r -nd --no-parent --no-remove-listing $ftpUrl -l1 -A file2*.txt &
wget -r -nd --no-parent --no-remove-listing $ftpUrl -l1 -A file3*.txt &
The problem is that wget downloads .listing file everytime and because there are multiple instances running, sometimes the file is being downloaded when another instance is reading it.
Is there a way to lock .listing file or ask wget to not download it (I can do it manually as the first command)? I don't understand how it reads this .listing file since it's not a plain list of the URLs, but rather something like this:
drwxr-xr-x 3 4015 4015 16384 Dec 14 21:23 .
drwxr-xr-x 4 4015 4015 4096 Dec 14 21:23 ..
-rw-r--r-- 1 4015 4015 327 Feb 15 2022 file1-bla.txt
-rw-r--r-- 1 4015 4015 10716 Feb 15 2022 file2-bla.txt
-rw-r--r-- 1 4015 4015 163 Feb 15 2022 file2-bla.txt
If I try to use -i .listing (or even if I rename .listing to list.txt and use -i list.txt) I get an error saying that the URLs are not valid or something.
RFC 959 stipulates that
LIST (LIST) This command causes a list to be sent from the server to the passive DTP. If the pathname specifies a directory or other
group of files, the server should transfer a list of files in the
specified directory. If the pathname specifies a file then the server
should send current information on the file. A null argument implies
the user's current working or default directory. The data transfer is
over the data connection in type ASCII or type EBCDIC. (The user must
ensure that the TYPE is appropriately ASCII or EBCDIC). Since the
information on a file may vary widely from system to system, this
information may be hard to use automatically in a program, but may be
quite useful to a human user.
Observe that it does not impose formal requirement what exactly will be returned.
drwxr-xr-x 3 4015 4015 16384 Dec 14 21:23 .
drwxr-xr-x 4 4015 4015 4096 Dec 14 21:23 ..
-rw-r--r-- 1 4015 4015 327 Feb 15 2022 file1-bla.txt
-rw-r--r-- 1 4015 4015 10716 Feb 15 2022 file2-bla.txt
-rw-r--r-- 1 4015 4015 163 Feb 15 2022 file2-bla.txt
This looks akin to output of ls -lah command, if you are interested in using that to form URL list acceptable by wget then you should take last column (excluding . and ..) and prefix them with URL of FTP server, if that URL is ftp://ftp.example.com and you got list as above then your list of URLs should look as follows
ftp://ftp.example.com/file1-bla.txt
ftp://ftp.example.com/file2-bla.txt
ftp://ftp.example.com/file3-bla.txt

PulseAudio cannot see working USB sound card

I have a Raspberry Pi, running Raspbian, with a cheap SoundBlaster USB card plugged into it. The card is visible to ALSA:
# aplay -l | grep card
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 IEC958/HDMI [bcm2835 IEC958/HDMI]
card 0: ALSA [bcm2835 ALSA], device 2: bcm2835 IEC958/HDMI1 [bcm2835 IEC958/HDMI1]
card 1: S3 [Sound Blaster Play! 3], device 0: USB Audio [USB Audio]
And I can play sound through this card:
$ speaker-test -Dhw:1,0 -c2 -twav
does output "front left" and "front right" in a woman's voice through the connected speakers.
However, PulseAudio does not recognize the card:
$ pacmd list-sinks|egrep -i 'index:|name:'
* index: 0
name: <auto_null>
I'm not even sure how to select this card in alsamixer; hitting "F2" and looking at /proc/asound/cards does show this, but then "F6" only shows the default card and trying to enter another value, like "S3" (the name of the card) or "1" or "hw1" or "hw:1,0" just returns "Cannot open mixer device [whatever]. No such file or directory."
I've tried a variety of solutions I've found; none of them work. For example, adding load-module module-alsa-sink device=hw:1,0 to /etc/pulse/default.pa does not trigger an error, but it also does not change the output of pacmd list-sinks, and does not give me any sound.
Adding an ALSA configuration file consisting of:
pcm.!default {
type hw
card 1
}
ctl.!default {
type hw
card 1
}
does make the USB card available to alsamixer, and I can then play things directly through ALSA, e.g. $ aplay test.wav, but it's still invisible to Pulse via list-sinks, and if I try to play anything through Pulse, I get errors or no sound, e.g. with mocp sample.mp3 there's no sound.
I can't imagine this should be so hard, so I assume I'm missing something obvious. Could someone tell me what it is?
[EDIT:]
The output of ls -l /dev/snd is:
$ ls -l /dev/snd
total 0
drwxr-xr-x 2 root root 60 Jan 12 17:01 by-id
drwxr-xr-x 2 root root 80 Jan 12 17:01 by-path
crw-rw---- 1 root audio 116, 0 Jan 12 17:01 controlC0
crw-rw---- 1 root audio 116, 32 Jan 12 17:01 controlC1
crw-rw---- 1 root audio 116, 16 Jan 12 17:01 pcmC0D0p
crw-rw---- 1 root audio 116, 17 Jan 12 17:01 pcmC0D1p
crw-rw---- 1 root audio 116, 18 Jan 12 17:01 pcmC0D2p
crw-rw---- 1 root audio 116, 56 Jan 12 17:01 pcmC1D0c
crw-rw---- 1 root audio 116, 48 Jan 12 17:01 pcmC1D0p
crw-rw---- 1 root audio 116, 1 Jan 12 17:01 seq
crw-rw---- 1 root audio 116, 33 Jan 12 17:01 timer

cron job fails regularly every hour

I read plenty of Q&A about cron but I was not able to understand an anomaly which I am facing.
I have a Raspberry Pi running 3 cronjobs:
* * * * * /home/pi/heartbeatgenerator.sh 2>&1
*/5 * * * * /home/pi/extase2influx/extase2influx.sh 2>&1
*/5 * * * * /home/pi/ows2influx/ows2influx.sh 2>&1
The first one is a simple script which write every minute 0 or 1 alternatively to a database (InfluxDB) via a curl call. The idea is to check if the RPi has a regular connection to the DB and function properly.
It looks like this:
value=$(($( date +"%M")%2))
curl -i -XPOST "https://[REDACTED].influxcloud.net:8086/write?db=[REDACTED]&u=[REDACTED]&p=[REDACTED]&precision=s" \
--data "heartbeat $HOSTNAME=$value"
The second script is query some sensors and posting the values to the same DB.
The third script is bascially the same of the second one, but the first line has a 'sleep 10s' command (to avoid a spike in CPU/network usage).
Now, everything is working nicely EXCEPT that the first script (the heartbeat) fails regularly every hour at minute 08 and 09. It fails meaning no data are posted into the DB. This is a piece of the DB dump:
1/7/2019 1:05:06.000000000 PM,1
1/7/2019 1:06:01.000000000 PM,0
1/7/2019 1:07:01.000000000 PM,1
1/7/2019 1:10:01.000000000 PM,0
1/7/2019 1:11:01.000000000 PM,1
1/7/2019 1:12:02.000000000 PM,0
This is how looks like visually
Here is a piece of the logfile:
Jan 7 13:05:01 RPi CRON[6346]: (pi) CMD (/home/pi/ows2influx/ows2influx.sh 2>&1)
Jan 7 13:05:01 RPi CRON[6347]: (pi) CMD (/home/pi/extase2influx/extase2influx.sh 2>&1)
Jan 7 13:05:01 RPi CRON[6348]: (pi) CMD (/home/pi/heartbeatgenerator.sh 2>&1)
Jan 7 13:05:01 RPi CRON[6334]: (CRON) info (No MTA installed, discarding output)
Jan 7 13:05:11 RPi pi: /home/pi/extase2influx/extase2influx.sh INFO: Database entry successfull. Written 1520 bytes
Jan 7 13:05:11 RPi CRON[6333]: (CRON) info (No MTA installed, discarding output)
Jan 7 13:05:12 RPi pi: /home/pi/ows2influx/ows2influx.sh INFO-OWS: Database entry successfull. Written 1456 bytes
Jan 7 13:05:12 RPi CRON[6332]: (CRON) info (No MTA installed, discarding output)
Jan 7 13:05:16 RPi dhcpcd[520]: wlan0: Router Advertisement from fe80::21d:aaff:feb0:8f20
Jan 7 13:05:20 RPi dhcpcd[520]: wlan0: Router Advertisement from fe80::21d:aaff:feb0:8f20
Jan 7 13:05:24 RPi dhcpcd[520]: wlan0: Router Advertisement from fe80::21d:aaff:feb0:8f20
Jan 7 13:06:01 RPi CRON[6566]: (pi) CMD (/home/pi/heartbeatgenerator.sh 2>&1)
Jan 7 13:06:01 RPi CRON[6562]: (CRON) info (No MTA installed, discarding output)
Jan 7 13:07:01 RPi CRON[6579]: (pi) CMD (/home/pi/heartbeatgenerator.sh 2>&1)
Jan 7 13:07:07 RPi CRON[6575]: (CRON) info (No MTA installed, discarding output)
Jan 7 13:07:54 RPi dhcpcd[520]: wlan0: Router Advertisement from fe80::21d:aaff:feb0:8f20
Jan 7 13:07:58 RPi dhcpcd[520]: wlan0: Router Advertisement from fe80::21d:aaff:feb0:8f20
Jan 7 13:08:01 RPi CRON[6608]: (pi) CMD (/home/pi/heartbeatgenerator.sh 2>&1)
Jan 7 13:08:02 RPi CRON[6604]: (CRON) info (No MTA installed, discarding output)
Jan 7 13:08:02 RPi dhcpcd[520]: wlan0: Router Advertisement from fe80::21d:aaff:feb0:8f20
Jan 7 13:09:00 RPi dhcpcd[520]: wlan0: Router Advertisement from fe80::21d:aaff:feb0:8f20
Jan 7 13:09:01 RPi CRON[6636]: (pi) CMD (/home/pi/heartbeatgenerator.sh 2>&1)
Jan 7 13:09:01 RPi CRON[6632]: (CRON) info (No MTA installed, discarding output)
Jan 7 13:09:04 RPi dhcpcd[520]: wlan0: Router Advertisement from fe80::21d:aaff:feb0:8f20
Jan 7 13:09:08 RPi dhcpcd[520]: wlan0: Router Advertisement from fe80::21d:aaff:feb0:8f20
Jan 7 13:10:01 RPi CRON[6672]: (pi) CMD (/home/pi/extase2influx/extase2influx.sh 2>&1)
Jan 7 13:10:01 RPi CRON[6673]: (pi) CMD (/home/pi/heartbeatgenerator.sh 2>&1)
Jan 7 13:10:01 RPi CRON[6674]: (pi) CMD (/home/pi/ows2influx/ows2influx.sh 2>&1)
Jan 7 13:10:06 RPi pi: /home/pi/extase2influx/extase2influx.sh INFO: Database entry successfull. Written 1490 bytes
Jan 7 13:10:06 RPi CRON[6661]: (CRON) info (No MTA installed, discarding output)
Jan 7 13:10:07 RPi CRON[6662]: (CRON) info (No MTA installed, discarding output)
Jan 7 13:10:12 RPi pi: /home/pi/ows2influx/ows2influx.sh INFO-OWS: Database entry successfull. Written 1376 bytes
Jan 7 13:10:12 RPi CRON[6660]: (CRON) info (No MTA installed, discarding output)
Jan 7 13:11:01 RPi CRON[6868]: (pi) CMD (/home/pi/heartbeatgenerator.sh 2>&1)
Jan 7 13:11:07 RPi CRON[6864]: (CRON) info (No MTA installed, discarding output)
I don't see anything strange and I don't see any reason why the cronjob heartbeat.sh fails at minute 08 and 09 of every hour.
Has some of you any clue?

BeagleBone Black UART1 enabled, but does not send or receive data

I have (finally) managed to get UART1 going on my BBB using the instructions here:
http://tenderlovemaking.com/2014/01/19/enabling-ttyo1-on-beaglebone.html
Doing ls -la /dev/ttyO* gives
crw--w---- 1 root tty 248, 0 Sep 22 14:50 /dev/ttyO0
crw-rw---- 1 root dialout 248, 1 Sep 22 14:50 /dev/ttyO1
but I cannot seem to write or read anything.
echo "wibble" > /dev/ttyO1
does nothing (I ran screen /dev/ttyO1 115200 in another terminal window). Is there a further step to actually get data flowing through the serial port?
Note: Beaglebone revision is B6.

How to get the start time of a long-running Linux process?

Is it possible to get the start time of an old running process? It seems that ps will report the date (not the time) if it wasn't started today, and only the year if it wasn't started this year. Is the precision lost forever for old processes?
You can specify a formatter and use lstart, like this command:
ps -eo pid,lstart,cmd
The above command will output all processes, with formatters to get PID, command run, and date+time started.
Example (from Debian/Jessie command line)
$ ps -eo pid,lstart,cmd
PID CMD STARTED
1 Tue Jun 7 01:29:38 2016 /sbin/init
2 Tue Jun 7 01:29:38 2016 [kthreadd]
3 Tue Jun 7 01:29:38 2016 [ksoftirqd/0]
5 Tue Jun 7 01:29:38 2016 [kworker/0:0H]
7 Tue Jun 7 01:29:38 2016 [rcu_sched]
8 Tue Jun 7 01:29:38 2016 [rcu_bh]
9 Tue Jun 7 01:29:38 2016 [migration/0]
10 Tue Jun 7 01:29:38 2016 [kdevtmpfs]
11 Tue Jun 7 01:29:38 2016 [netns]
277 Tue Jun 7 01:29:38 2016 [writeback]
279 Tue Jun 7 01:29:38 2016 [crypto]
...
You can read ps's manpage or check Opengroup's page for the other formatters.
The ps command (at least the procps version used by many Linux distributions) has a number of format fields that relate to the process start time, including lstart which always gives the full date and time the process started:
# ps -p 1 -wo pid,lstart,cmd
PID STARTED CMD
1 Mon Dec 23 00:31:43 2013 /sbin/init
# ps -p 1 -p $$ -wo user,pid,%cpu,%mem,vsz,rss,tty,stat,lstart,cmd
USER PID %CPU %MEM VSZ RSS TT STAT STARTED CMD
root 1 0.0 0.1 2800 1152 ? Ss Mon Dec 23 00:31:44 2013 /sbin/init
root 5151 0.3 0.1 4732 1980 pts/2 S Sat Mar 8 16:50:47 2014 bash
For a discussion of how the information is published in the /proc filesystem, see
https://unix.stackexchange.com/questions/7870/how-to-check-how-long-a-process-has-been-running
(In my experience under Linux, the time stamp on the /proc/ directories seem to be related to a moment when the virtual directory was recently accessed rather than the start time of the processes:
# date; ls -ld /proc/1 /proc/$$
Sat Mar 8 17:14:21 EST 2014
dr-xr-xr-x 7 root root 0 2014-03-08 16:50 /proc/1
dr-xr-xr-x 7 root root 0 2014-03-08 16:51 /proc/5151
Note that in this case I ran a "ps -p 1" command at about 16:50, then spawned a new bash shell, then ran the "ps -p 1 -p $$" command within that shell shortly afterward....)
As a follow-up to Adam Matan's answer, the /proc/<pid> directory's time stamp as such is not necessarily directly useful, but you can use
awk -v RS=')' 'END{print $20}' /proc/12345/stat
to get the start time in clock ticks since system boot.1
This is a slightly tricky unit to use; see also convert jiffies to seconds for details.
awk -v ticks="$(getconf CLK_TCK)" 'NR==1 { now=$1; next }
END { printf "%9.0f\n", now - ($20/ticks) }' /proc/uptime RS=')' /proc/12345/stat
This should give you seconds, which you can pass to strftime() to get a (human-readable, or otherwise) timestamp.
awk -v ticks="$(getconf CLK_TCK)" 'NR==1 { now=$1; next }
END { print strftime("%c", systime() - (now-($20/ticks))) }' /proc/uptime RS=')' /proc/12345/stat
Updated with some fixes from Stephane Chazelas in the comments; thanks as always!
If you only have Mawk, maybe try
awk -v ticks="$(getconf CLK_TCK)" -v epoch="$(date +%s)" '
NR==1 { now=$1; next }
END { printf "%9.0f\n", epoch - (now-($20/ticks)) }' /proc/uptime RS=')' /proc/12345/stat |
xargs -i date -d #{}
1 man proc; search for starttime.
ls -ltrh /proc | grep YOUR-PID-HERE
For example, my Google Chrome's PID is 11583:
ls -l /proc | grep 11583
dr-xr-xr-x 7 adam adam 0 2011-04-20 16:34 11583
$ ps -p 182454 -o lstart=
Mon Oct 18 17:26:44 2021
But can I get the answer in epoch seconds?
ps -eo pid,cmd,lstart | grep YOUR-PID-HERE
ps -eo pid,etime,cmd|sort -n -k2
use the command ls -ld /proc/process_id where process_id can be find using top command

Resources