How to automatically add date to output file generated in ffmpeg? - ffmpeg

I am using Terminal to run ffmpeg commands (Mac OS) in order to record radio shows streamed online. The stream is in m3u8 I want to output it in mp3. So far so good, I am able to achieve that. However, I'd like the output file to read YYYYMMDD-fm93-segal.mp3 where YYYYMMMDD are the date the recording was made.
I am not able to achieve this using -strftime 1 for some reason. When using my code, the output file reads %Y%m&d-fm93-segal.mp3 instead of replacing the strings by the real date.
Here is the line I'm using:
ffmpeg -i "https://cogecomedia.leanstream.co/cogecomedia/CJMFFM.stream/playlist.m3u8" -acodec mp3 -strftime 1 "%Y%m%d-fm93-segal.mp3"
Anyone knows why and could help me with that?

-strftime is not a generic option, but is only supported by some muxers: hls, image, segment.
One method is to use the segment muxer and give it a big -segment_time value if desired:
ffmpeg -i "https://cogecomedia.leanstream.co/cogecomedia/CJMFFM.stream/playlist.m3u8" -f segment -segment_time 24:00:00 -acodec mp3 -strftime 1 "%Y%m%d-fm93-segal.mp3"

Related

Option to generate a .m4s file every second

I am trying to stream my live recording from a camera (web cam/ IP cam) to my web application. The streaming technique I use is MPEG-DASH, which has manifest in MPD format. To generate an MPD format from the web-cam, I use FFmpeg tool in shell command line:
ffmpeg -re -y -f dshow -i video="Logitech HD Webcam C525" -c:v libx264 -c:a libfdk_aac -f dash "manifest.mpd"
This code will generate a video chunk in .m4s format every 5-8 seconds.
Question is, what FFmpeg option can I use to generate a .m4s file every second instead of every 5-8 seconds? I suppose it has something to do with segment?
-seg_duration 1 -ldash 1 -streaming 1 would help you.

How to use ffmpeg to split an audio file into HLS-compatible chunks? (mp3 format)

I've been looking all over the web & StackOverflow, and can't get this to work. I have an audio file that I'd like to split into mp3 files and generate a corresponding m3u8 file.
I've tried this, which was the closest:
ffmpeg -i sometrack.wav -c:a libmp3lame -b:a 256k -map 0:0 -f segment -segment_time 10 -segment_list outputlist.m3u8 -segment_format mpegts 'output%03d.mp3'
But all the mp3 files are garbled when I play them.
There are two issues here. FFmpeg normally looks at the extension of the output files to determine output container. However, when the output format is forced -segment_format for segment muxer or just -f format for most others, ffmpeg will pay heed to that and no longer look at the extension. In this case, segment_format is set to mpegts so that's what the output files will be. To ensure valid mp3 files, set segment_format to mp3.
The second issue is that since the extension is mp3, my guess is that hls.js is not able to correctly determine the format of the segments, or it assumes a wrong format and tries to parse them that way. Either way, there should be some messages in the browser console to that effect. See https://github.com/video-dev/hls.js/pull/1190 for issues that hls.js has had with format probing.

How to capture multiple screenshot from online video stream using ffmpeg with specific seek time

I'm using ffmpeg to take screenshot from online video stream. I want to seek multiple timeline. I've used the following command to capture 1 screenshot by seek command:
ffmpeg -ss 00:02:10 -i "stream-url" -frames:v 1 out1.jpg
How I can take multiple screenshot via multiple seek time. I've searched for the solution but no success.
I've used the following command to take multiple screenshot as follows:
ffmpeg -noaccurate_seek -ss 00:01:10 -i "stream-url" -map 0:v:0 -vframes 1 -f mpeg "thumb/output_01.jpg" -ss 00:02:10 -i "stream-url" -map 1:v:0 -vframes 1 -f mpeg "thumb/output_02.jpg"
Is there any way to generate screenshots from same input via seek command? How to make it more faster? How to skip multiple input(-i param)? I've also tried with other commands but those are more slower. Can anyone help me?
There's no easy way I know to specify a number of arbitrary seek points from which to extract frames (similar question here).
However, seeking is very fast with the way you specified. Instead of constructing a complex command, you could just download the YouTube video using youtube-dl (if you haven't done that already) and generate the commands like this:
ffmpeg -ss 00:01:10 -i input -frames:v 1 out1.jpg
ffmpeg -ss 00:02:05 -i input -frames:v 1 out2.jpg
ffmpeg -ss 00:03:20 -i input -frames:v 1 out3.jpg
Note that exporting JPG might lead to low quality. Using PNG is preferred; you will get lossless frames that you can handle with another program later (e.g. to resize or compress).
If you want to get frames from regular intervals, use the fps filter to drop the framerate:
ffmpeg -i input -filter:v fps=1/60 out%02d.jpg
This will output a frame every minute (1/60 frames per second = 1 frame per minute), with two zero-padded digits as output numbers. You could additionally offset the start by providing a -ss option before the input file.

Add multiple audio files to video at specific points using FFMPEG

I am trying to create a video out of a sequence of images and various audio files using FFmpeg. While it is no problem to create a video containing the sequence of images with the following command:
ffmpeg -f image2 -i image%d.jpg video.mpg
I haven't found a way yet to add audio files at specific points to the generated video.
Is it possible to do something like:
ffmpeg -f image2 -i image%d.jpg -i audio1.mp3 AT 10s -i audio2.mp3 AT 15s video.mpg
Any help is much appreciated!
EDIT:
The solution in my case was to use sox as suggested by blahdiblah in the answer below. You first have to create an empty audio file as a starting point like that:
sox -n -r 44100 -c 2 silence.wav trim 0.0 20.0
This generates a 20 sec empty WAV file. After that you can mix the empty file with other audio files.
sox -m silence.wav "|sox sound1.mp3 -p pad 0" "|sox sound2.mp3 -p pad 2" out.wav
The final audio file has a duration of 20 seconds and plays sound1.mp3 right at the beginning and sound2.mp3 after 2 seconds.
To combine the sequence of images with the audio file we can use FFmpeg.
ffmpeg -i video_%05d.png -i out.wav -r 25 out.mp4
See this question on adding a single audio input with some offset. The -itsoffset bug mentioned there is still open, but see users' comments for some cases in which it does work.
If it works in your case, that would be ideal:
ffmpeg -i in%d.jpg -itsoffset 10 -i audio1.mp3 -itsoffset 15 -i audio2.mp3 out.mpg
If not, you should be able to combine all the audio files with sox, overlaying or inserting silence to produce the correct offsets and then use that as input to FFmpeg. Not as convenient, but guaranteed to work.
One approach I can think of is to create your audio file for the whole duration of the video first and then mux the audio with the video file

Generate a movie with ffmpeg from a changing still image url?

I need to create a movie/stream with ffmpeg from a HTTP url that points to an image. This image gets updated 1 time per second.
I already know how to convert from MPEG-4 to flv for example using the ffmpeg command line, but now I need to start from this still image that gets updated. I would like ffmpeg to 'GET' the url 1 time per second for example.
regards,
Wim
The command line option needed is -loop_input. I am currenly using this command line to do it:
ffmpeg -loop_input -analyzeduration 0 -r 3 -i http://ipaddress/current.jpg -an -re -copyts -f flv output.flv
The -loop_input instructs ffmpeg to read the jpg on the given URL at the input frame rate (3 fps in this example). The -analyzeduration 0 will give a quicker startup and show the first frame of your movie faster. The output can be anything, in the example here, it is a flash movie, but it can be anything ffmpeg supports.

Resources