0

Im using ffmpeg to record online stream. I want to record in small pieces with killing ffmpeg process and starting again. Trying to do it with command watch -n 40 "pkill ffmpeg; ffmpeg -i http://SiteName.com/playlist.m3u8 radioSTREAM.$(date +%d-%m-%g-%Hh%Mm%Ss).mp3" but it stucking. How to make it work ?

Additional question is how to put all this construction in at command?

  • Consider stream copying the audio with -c:a copy instead of re-encoding it. – llogan Jun 2 '16 at 7:14
  • Still not working – user547325 Jun 2 '16 at 19:18
  • It wasn't a solution to whatever issue you're experience, but an unrelated suggestion. – llogan Jun 2 '16 at 19:34
  • Oh thank you. For video+audio stream it -c:v copy -c:a copy or i can do -c:v:a copy? – user547325 Jun 3 '16 at 13:30
  • You can use -c copy if you want to stream copy both. – llogan Jun 3 '16 at 16:34
1

A more elegant solution is to use the segment muxer:

ffmpeg -i input -c copy -f segment -segment_time 40 output_%03d.mp3

Results in approximately 40 second segments:

$ ls -m1
output_000.mp3
output_001.mp3
...
output_010.mp3

The example avoids re-encoding by using stream copy mode, and assumes the input and output formats are the same (MP3 in this example).

  • This is it. Watch usage even not needed here. Though naming here not working that good. Ffmpeg segements thing refusing to work if not put somewhere in filename the %03d and $(date +%d-%m-%g-%Hh%Mm%Ss) wiriting in name of segment same as in the first segment. But this not that important. Thanks for the solution. Still curious how to make through the watch – user547325 Jun 6 '16 at 13:05
0

Put it in a shell script so that you have less tricky escaping, you can the also run that shell script from the at command

If you run the shell script as follows

bash -x ./script.sh 

You will see what values the variables have at each point in the script.

  • With script working but not perfect. Now command is watch -n 60 bash -x ./rstream.sh The time interval in watch -n 60 not always giving me 60 second length files, it can also be 40 or 50 seconds length. And its not works when I put in at. And if there is way to run this without script ? – user547325 Jun 2 '16 at 19:18
  • Ffmpeg will take a few seconds to start so I guess you might have to make the segments overlap to ensure you don't loose data. – Amias Jun 3 '16 at 6:44
  • It is not ffmpeg. I use ffmpeg in at and recording starts in the required time. I think it is pkill ffmpeg, in script its demanding sudo pass, messing couple of seconds or more and starts anyway. Changing to sudo pkill ffmpeg didnt helped with delay too. – user547325 Jun 6 '16 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.