I have written a bash script to keep a ffmpeg command up and running
#!/bin/bash
while :
do
echo `ffmpeg -re -i http://domain.com/index400.m3u8 -vcodec copy -acodec copy -f mpegts udp://127.0.0.1:10000?pkt_size=1316`
done
The problem is, sometimes the input is broken, yet ffmpeg does not exit when that happens so that it is restarted by the above script. Instead what happens is the same process is kept running eventhough it is not transferring any packet to the UDP address (output). And I need to manually go into the terminal and kill it (kill -9 #processID)
I need a way to make ffmpeg kill its own process whenever the input is broken.
Appreciate your help.
Related
I have a custom sniffer, which produces output in pcapng format. I launch it like that:
<sniffer launch line> | tee out.pcapng | tshark -Tpdml -i -
expecting to have a pdml output in stdout. Generally it works, but sometimes the following happens: after the first packet was written to stdout by sniffer, tshark just reports 0 packets captured and closes. At the same time the out.pcapng appears to be valid and successfully can be opened with wireshark.
Moreover, when I try cat out.pcapng | tshark -Tpdml -i -, it would handle the input successfully in 90% of launches, but would still fail sometimes.
It seems, that changing tshark flag from -i to -r helps, but I'm not sure if it solves the problem or just make it appear less often. And anyway, I'd be pleased to know what actually happens there. Launching tsahrk with stdbuf -o 0 tshark ... doesn't help.
An example of problematic .pcapng file: https://drive.google.com/file/d/1GS41yti0zs5-ZT5bgRNYslIQW1q_fDfQ/view?usp=sharing
Version of Tshark: TShark (Wireshark) 3.2.3 (Git v3.2.3 packaged as 3.2.3-1)
I'm using localhost.run to open tunnels, so I want to launch
ssh -R 80:localhost:8080 ssh.localhost.run
The only problem is that I launch it via LSF as part of a bash script.
I get the error
Pseudo-terminal will not be allocated because stdin is not a terminal.
that I solve by using the option
-T Disable pseudo-tty allocation.
My current command is
ssh -T -R 80:localhost:8080 ssh.localhost.run
and it is the last command of my bash script.
I have also tried using -tt with the same result (https://stackoverflow.com/a/7122115/5133167)
When I launch my script from my tty, I get the expected output (a message like Connect to http://user.localhost.run or https://user.localhost.run)
When I launch it through LSF (using bsub), I don't get any output from SSH (but get the output from the other commands).
I have also tried redirecting the output of ssh to a file: it works fine when launched from the command line but not when launched from LSF.
I want to use nodemon, but still have the use of my terminal, so I ran
$ nodemon &> site.log &
But as soon as I type a single character at the prompt, nodemon stops with this message.
[1] + 45260 suspended (tty input) nodemon &> site.log
What's going on? How can I make this stop happening?
I'm running zsh on MacOS.
EDIT:
I found this answer which explains it perfectly - apparently nodemon tries to read from stdin, and unix systems will stop processes that try to read from stdin while in the background. So my question now becomes:
How do I get nodemon to stop reading from stdin? And, more generally, is there a way to get an arbitrary process to stop reading from stdin?
I figured it out. I have to redirect /dev/null to the input.
$ nodemon < /dev/null &> site.log &
When user uploads video then I make its 2 sizes. Earlier, I was doing this in two steps like following
First Size:
ffmpeg -i in.mp4 -filter:v "scale=iw*min(1170/iw\,300/ih):ih*min(1170/iw\,300/ih), pad=1170:300:(1170-iw*min(1170/iw\,300/ih))/2:(300-ih*min(1170/iw\,300/ih))/2" out.mp4
Second Size:
ffmpeg -i in.mp4 -filter:v "scale=iw*min(365/iw\,172/ih):ih*min(365/iw\,172/ih), pad=365:172:(365-iw*min(365/iw\,172/ih))/2:(172-ih*min(365/iw\,172/ih))/2" out1.mp4
But now to reduce processing time, I want to combine these 2 steps in one. I have read https://trac.ffmpeg.org/wiki/Creating%20multiple%20outputs and make following command
ffmpeg -i in.mp4 -filter:v "scale=iw*min(1170/iw\,300/ih):ih*min(1170/iw\,300/ih), pad=1170:300:(1170-iw*min(1170/iw\,300/ih))/2:(300-ih*min(1170/iw\,300/ih))/2" bigVideo.mp4 \ -filter:v "scale=iw*min(365/iw\,172/ih):ih*min(365/iw\,172/ih), pad=365:172:(365-iw*min(365/iw\,172/ih))/2:(172-ih*min(365/iw\,172/ih))/2" smallVideo.mp4
But it is giving following error
[NULL # 0xaee5440] Unable to find a suitable output format for ' -filter:v'
-filter:v: Invalid argument
so can anyone suggest me how i can solve it?
I tried to run both commands using the following script:
#!/bin/bash
for cmd in "$#"; do {
echo "Process \"$cmd\" started";
$cmd & pid=$!
PID_LIST+=" $pid";
} done
trap "kill $PID_LIST" SIGINT
echo "Parallel processes have started";
wait $PID_LIST
echo
echo "All processes have completed";
You can save it as filename.sh and make executable. after that you need to pass two of more commands as arguments, for example I ran as:
./filename.sh "ffmpeg -i input.mp4 -s 720x480 output1.mp4" "ffmpeg -i input.mp4 -s 1170x480 output2.mp4"
Your command was bit complicated for me so I try to run simple commands using parallel script.
I'm specifically looking for a solution for PuTTY but also interested for other terminal emulators, like Gnome Terminal.
My thought is it would be useful if I start a tar zxvf to be able to set a trigger on the terminal emulator, minimize it, and on next output to stdout/stderr I get a notification in the task bar that the command has finished.
This works for me:
echo -e "\a"
Then update your PuTTY session to use the Visual Bell, and set "Taskbar/caption indication on bell" to Flashing or Steady.
Then run this command after your tar completes:
tar xvzf file ; echo -e "\a"
Here is a screenshot: Save these settings as the default settings and/or the sessions' settings you have