adding repeated background audio with ffmpeg [closed] - audio

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
With ffmpeg, I see how to add music file as background for a video, but the problem is how to make the audio loop/repeat. Is there a way out?

ffmpeg has the promising -loop_input flag, but it doesn't support audio inputs yet.
I'd recommend sox and the -shortest option for ffmpeg as a solution.
sox short_audio.mp3 looped_audio.mp3 repeat 1000 # adjust count as necessary
ffmpeg -i input_video.mp4 -i looped_audio.mp3 -shortest output_video.mp4
The sox command will loop the input, and the ffmpeg command will use it for the audio, but stop when it runs out of video to process.

I ran into the same problem and managed to do it by using ffmpeg and concat[enate] filter. Here is an example of how to loop it three times:
ffmpeg -i audio.wav -filter_complex "[0:a]afifo[a0];[0:a]afifo[a1];[0:a]afifo[a2];[a0][a1][a2]concat=n=3:v=0:a=1[a]" -map "[a]" out.wav
Edited (23/12/2020)
In addition to the above, another super easy 2 methods :
1st method : with audio output SIZE defined.
meaning : it will repeat / concatenate "MyAudio.mp3" till it reaches size of 10M and stop ( you will need to calculate end size yourself )
ffmpeg -stream_loop -1 -i "MyAudio.mp3" -fs 10M -c copy "MyRepeatingAudio.mp4"
2nd method : with NO output SIZE defined ( you will need to stop process, CTRL+C once it reaches required size
ffmpeg -stream_loop -1 -i "MyAudio.mp3" -c copy "MyRepeatingAudio.mp4"
Please note that above methods are also for REPEATING VIDEOS
3rd-party edit (15/09/2021)
This command adds repeating audio to a video in a single step:
ffmpeg -i input.mp4 -stream_loop -1 -i audio.mp4 -shortest \
-map 0:v:0 -map 1:a:0 -c:v copy output.mp4

Related

Corrupted output when resizing with scale_npp filter ffmpeg

I'm trying to transcode a single video file into multiple variants with different
resolutions/bitrates using GPU acceleration - in one command.
The encoding/decoding part is working great and produces results as expected.
Main issue
However when I try to resize using the scale_npp filter things start to turn green.
The resulting output from ffmpeg is just a green image
Similar to Issue1,
Issue2 Already asked in ffmpeg forum but there is no answer for this issue
Command i am using for conversion
ffmpeg -y -vsync 0 -hwaccel cuvid -c:v h264_cuvid -i input.mp4 -vf scale_npp=1280:720 -c:a copy -c:v h264_nvenc -b:v 360k -hls_time 10 -hls_segment_filename output/ts_%03d.ts output/m3.m3u8
My output video showing like
https://i.stack.imgur.com/EbVfV.jpg
I appreciate your help.
Thanks

FFmpeg stream dynamic png

I would like to know if its possible to stream a png or any kind of image using ffmpeg. I would like to generate the image contiously using nodejs that updates every 10 seconds. I would like to display game stats with this in a corner and mix it with some background music or pre recorded commentary on it. Additionaly i would like to mix a video and the image should act like an overlay.
I am also not sure if using a transparent png image its possible to do
I couldn't get my head around doing the mixing with ffmpeg and its looks very complicated so i would like to get some help on it.
I have video files stored in a folder that i would like to continously stream and mix different music and an image on it. I would like to have it all continously working without stopping the stream.
Is it possible with ffmpeg cli on linux or i cant avoid using a desktop windows pc for such thing?
Well after digging through the documentation and asking for help on irc i came up with the following command:
First i store the list of tracks in a txt file such as:
playlist.txt
file 'song1.mp3'
file 'song2.mp3'
file 'song3.mp3'
Then i want to concat the tracks so i use -concat and specify the input as a txt file.
The second thing is using a static image as an input that i can manually update.
ffmpeg -re -y -f concat -safe 0 -i playlist.txt -framerate 1 -loop 1 -f image2 \
-vcodec libx264 -pix_fmt yuv420p -preset ultrafast -r 12 -g 24 -b:v 4500k \
-acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b:a 128k -bufsize 512k \
-f flv "rtmp://"
The rest is specificing the output format and other settings for streaming.
Thats what i came up with so far, not sure if theres any better way of doing this but right now it is sufficient enough for my needs.

FFMPEG encode audio and forced subtitles at same time?

I'm using latest static build of ffmpeg windows.
My input file (.mkv) is:
[video] - 1080, V_MPEG4/ISO/AVC, 14.6 Mbps, ID#0
[audio] - DTS 5.1, 1510 Kbps, ID#1
[subtitles] - S_TEXT/ASS Lossless English, ID#14
My problem is this: I convert the audio, so that my target player, a XB1 console (media support faq), is able to play audio/video. However sometimes its rather difficult to hear or parts may be in foreign language, so I want to force the english subtitles into the mix at the same time I convert the audio.
Currently for the audio, I use the following command
ffmpeg -i input.mkv -codec copy -acodec ac3 output.mkv
Can I somehow tie in the forced subtitles (onto the video) in order to save an extra process of taking the output.mkv and trying to force subtitles on?
Edit: I've tried using the following command to extract subtitles to be able to edit them
ffmpeg -i Movie.mkv -map 0:s:14 subs.srt
However i get the error: Stream map '0:s:14' matches no streams
Edit2: attempted to extract subtitles and succeeded with
ffmpeg -i input.mkv -map 0:14 -c copy subtitles.ass
but still looking to force the subtitles, nonetheless!
Also - a little bonus to this question - can I somehow extract the .ass file and edit it to only produce subtitles for foreign parts - so english audio doesn't have subtitles during the movie but foreign audio does have subtitles?
Cheers
Edit3:
When I try to use both of the commands at once (my earlier mentioned audio converter & one from the ffmpeg wiki)
ffmpeg -i input.mkv -codec copy -acodec ac3 -vf "ass=subs.ass" output.mkv
I get the following error from ffmpeg,
Filtergraph 'ass=subs.ass' was defined for video output stream 0:0 but codec copy was selected.
Filtering and streamcopy cannot be used together.
Since your media player does not support subtitles, the text has to be burnt onto the video image. For that, use
ffmpeg -i input.mkv -vf "ass=subs.ass" -c:v libx264 -crf 20 -c:a ac3 output.mkv
This will re-encode the video, since text is being added. The CRF value controls the video quality. Lower values produce better quality but larger files. 18 to 28 is a decent range to try.

ffmpeg live transcoding faster alternative? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
Is there any opensource alternative to ffmpeg and VLC to live video transcoding from HTTP streaming to RTMP or other?
ffmpeg caused my CPU (AMD 4.0GHZ 8Core) is loaded 100% with only 8 SD streams.
Thanks for help.
PS.
I think I don't need to transcode my video, I can also stream with something like http video proxy. Source is in HTTP streaming format, also I am under Linux.
Your question should be: "Is there any opensource alternative faster than ffmpeg".
And the answer is No.
If you dont need to transcode, add -acodec copy -vcodec copy to your command line
ffmpeg is flexible encoder you can tweak it much you like , it's up to encoding algorithm and Size VS Quality battle , I think now days X264 are more efficacy than it was before , the important tweaks with ffmpeg to speedup encoding is -preset the default is medium you can use fast or faster and watch the quality of your output video . I have live steaming video and I use this command
ffmpeg -loglevel 0 -thread_queue_size 32768 -re -i "http://sorce" -vcodec libx264 -preset fast -break_non_keyframes 1 -profile:v high444 -x264-params "nal-hrd=cbr" -b:v 260k -acodec aac -b:a 32k -map_metadata -1 -s 480x360 -f flv rtmp://localhost/hls/live
That for very low quality video ,
ffmpeg -loglevel 0 -thread_queue_size 32768 -re -i "http://source" -vcodec libx264 -preset fast -break_non_keyframes 1 -b:v 665k -profile:v high444 -x264-params "nal-hrd=cbr" -acodec aac -b:a 32k -map_metadata -1 -s 854x480 -f flv rtmp://localhost/hls/live
you will get better quality and viewable picture when increase -b:v value .
so it's up to you preferred network you can get much higher video quality with less CPU usage.

Add audio (with an offset) to video with FFMPEG

I have a 10 minute video and a 50 minute audio mp3.
The video starts at 500 seconds into the audio.
Using FFMPEG, how can I add the the audio to the video but specify a 500 seconds audio offset (So that they sync up)?
EDIT:
Down the bottom of this page it suggests how to specify an offset.
$ ffmpeg -i video_source -itsoffet delay -i audio_source -map 0:x -map 1:y .......
However, when I apply this, it still starts the audio from the start.
We are 8 years later, and the -itsoffset does work.
Exactly as in your linked page:
ffmpeg -i input_1 -itsoffset 00:00:03 -i input_2
Note that you place the -itsoffset switch before the input you want to delay, in this case input_2 will be delayed.
So in your case that the video starts later, you would add -itsoffset 00:08:20 before the video input.
I couldn't get audio to offset properly either, and some searching suggests that -itsoffset is currently broken.
You could try and get/compile an old version of ffmpeg before it broke (which doesn't sound like much fun).
Alternately, you could pad your audio with the necessary silence using something like sox and then combine:
sox -null silence.mp3 trim 0 500 # use -r to adjust sample-rate if necessary
sox silence.mp3 input.mp3 padded_input.mp3
ffmpeg -i in.avi -i padded_input.mp3 out.avi

Resources