I'm using ffmpeg for transcoding my videos on my servers.
Some times ffmpeg carshes in transode during, and that process stalled on task manager and it used ram,but not consumed cpu(it seems ffmpeg crashed).
1- Is there any solution for knowing that how can I manage this process on my servers?
2- Must be handle that from web server side or can I manage it from ffmpeg side?
I mean, ffmpeg has there any property for when transcoding take a long time,that stops.
Or Can I handle this from server side(iis recycling stops the process in run time transcoding, i don't want to use that, maybe I'm wrong, just help me).
What is the best solution ?
I used this code for example:
ffmpeg -i kata.mp4 -filter_complex
[0:v]drawtext=fontfile=OpenSansRegular.ttf:text=localhost/Parsa:fontcolor
=white:r=25:box=1:boxcolor=black#0.3:boxborderw=3:fontsize=15:x=15:y=(h-text_h-
15)[v];[v]split=4[s0][s1][s2][s3];[s0]scale=hd720[v0];[s1]scale=hd480[v1];
[s2]scale=nhd[v2];[s3]scale=cga[v3] -map [v0] -map [v1] -map [v2] -map [v3] -map
a? -c:v libx264 -c:a aac -f tee -g 48 -threads 0 "
[select='v\:0,a':f=hls:hls_list_size=0]../video/720p/out.m3u8|
[select='v\:1,a':f=hls:hls_list_size=0]../video/480p/out.m3u8|
[select='v\:2,a':f=hls:hls_list_size=0]../video/360p/out.m3u8|
[select='v\:3,a':f=hls:hls_list_size=0]../video/200p/out.m3u8"
Related
Can I overlay/downmix two audio mp3 files into one mp3 output file using ffmpeg?
stereo + stereo → stereo
Normal downmix
Use the amix filter:
ffmpeg -i input0.mp3 -i input1.mp3 -filter_complex amix=inputs=2:duration=longest output.mp3
Or the amerge filter:
ffmpeg -i input0.mp3 -i input1.mp3 -filter_complex amerge=inputs=2 -ac 2 output.mp3
Downmix each input into specific output channel
Use the amerge and pan filters:
ffmpeg -i input0.mp3 -i input1.mp3 -filter_complex "amerge=inputs=2,pan=stereo|c0<c0+c1|c1<c2+c3" output.mp3
mono + mono → stereo
Use the join filter:
ffmpeg -i input0.mp3 -i input1.mp3 -filter_complex join=inputs=2:channel_layout=stereo output.mp3
Or amerge:
ffmpeg -i input0.mp3 -i input1.mp3 -filter_complex amerge=inputs=2 output.mp3
mono + mono → mono
Use the amix filter:
ffmpeg -i input0.mp3 -i input1.mp3 -filter_complex amix=inputs=2:duration=longest output.mp3
More info and examples
See FFmpeg Wiki: Audio Channels
Check this out:
ffmpeg -y -i ad_sound/whistle.mp3 -i ad_sound/4s.wav -filter_complex "[0:0][1:0] amix=inputs=2:duration=longest" -c:a libmp3lame ad_sound/outputnow.mp3
I think it will help.
The amix filter helps to mix multiple audio inputs into a single output.
If you run the following command:
ffmpeg -i INPUT1 -i INPUT2 -i INPUT3 -filter_complex amix=inputs=3:duration=first:dropout_transition=3 OUTPUT
This command will mix 3 input audio streams (I used two mp3 files, in the example below) into a single output with the same duration as the first input and a dropout transition time of 3 seconds.
The amix filter accepts the following parameters:
inputs:
The number of inputs. If unspecified, it defaults to 2.
duration:
How to determine the end-of-stream.
longest:
The duration of the longest input. (default)
shortest:
The duration of the shortest input.
first:
The duration of the first input.
dropout_transition:
The transition time, in seconds, for volume renormalization when an input stream ends. The default value is 2 seconds.
For example, I ran the following command in Ubuntu:
FFMPEG version: 3.2.1-1
UBUNTU 16.04.1
ffmpeg -i background.mp3 -i bSound.mp3 -filter_complex amix=inputs=2:duration=first:dropout_transition=0 -codec:a libmp3lame -q:a 0 OUTPUT.mp3
-codec:a libmp3lame -q:a 0 was used to set a variable bit rate. Remember that, you need to install the libmp3lame library, if is necessary. But, it will work even without the -codec:a libmp3lame -q:a 0 part.
Reference: https://ffmpeg.org/ffmpeg-filters.html#amix
For merging two audio files with different volumes and different duration following command will work:
ffmpeg -y -i audio1.mp3 -i audio2.mp3 -filter_complex "[0:0]volume=0.09[a];[1:0]volume=1.8[b];[a][b]amix=inputs=2:duration=longest" -c:a libmp3lame output.mp3
Here duration can be change to longest or to shortest, you can also change the volume levels according to your need.
If you're looking to add background music to some voice use the following command as in the gaps the music will become loud automatically:
ffmpeg -i bgmusic.mp3 -i audio.mp3 -filter_complex "[1:a]asplit=2[sc][mix];[0:a][sc]sidechaincompress=threshold=0.003:ratio=20[bg]; [bg][mix]amerge[final]" -map [final] final.mp3
In this threshold is something whose value will decide how much loud the audio should be, the less the threshold more the audio will be. Ratio gives how much the other audio should be compressed, the more the ratio the more the compression is.
If they are different length, you can use apad to add a silent sound to the shortest one
With Bash
set 'amovie=a.mp3 [gg]; amovie=b.mp3 [hh]; [gg][hh] amerge'
ffmpeg -f lavfi -i "$1" -q 0 c.mp3
Example
You can use the following command arguments:
// Command is here
let commandValue = "-y -i \(recordedAudioPath) -i \(backgroundAudio) -filter_complex [\(0):a][\(1):a]amerge=inputs=\(2)[a] -map [a] -ac \(2) -shortest -preset ultrafast \(outputPath)"
MobileFFmpeg.execute(commandValue)
I've been trying to make a mosaic of two rtmp streams and resend it to Twitch, i´m using a nginx with a rtmp module and ffmpeg. I've come out with this but doesnt work:
exec /usr/bin/ffmpeg - report -i rtmp://localhost/app/input -i rtmp://localhost/app/input -filter_complex "[0:v]scale=480:-1,setsar=1[l];[1:v]scale=480:-1,setsar=1[r];[l][r]hstack;[0:a][1:a]amerge=inputs=2[a]" -map v -map "[a]" -c:v libx264 -preset veryfast -ar 44100 -f flv rtmp://live-mia.twitch.tv/app/xxxxxxxxxx
The report shows an endless loop
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
how do I get this stream working?
At last, this the code I' been able to make work
exec /usr/bin/ffmpeg - report -i rtmp://localhost/app/input -i rtmp://localhost/app/input2 -filter_complex "[0:v]scale=480:-1,setsar=1[l];[1:v]scale=480:-1,setsar=1[r];[l][r]hstack[v];[0:a][1:a]amerge=inputs=2[a]" -map "[v]" -map "[a]" -c:v libx264 -preset veryfast -ac 2 -f flv rtmp://live-mia.twitch.tv/app/xxxxxxxxxx
It must be re-encoded the stream in order to Twitch been able to shown it. Also , as im runing ffmpeg in a nginx, the nginx's user must have root permissions.
I am working on an adaptive HLS solution using Nginx RTMP module as a streaming server and VideoJs as a client. I have completed the setup i.e. NGINX configurations and client sample in VideoJs.
NGINX Configurations:
nginx.txt
I am using this Ffmpeg command to generate stream:
ffmpeg -re -i /home/user/Downloads/test.mp4 -vcodec libx264 -vprofile baseline -g 30 -acodec aac -strict -2 -f flv rtmp://192.168.1.68/live
My problem is that sometimes the Nginx does not generate .ts and .m3u8 files in /tmp/hls directory when I issue the above ffmpeg command. I have also enabled the nginx-rtmp module logs but they are only giving me access information and I am not getting any logs in error logs.
Do let me know if more information is required. Any help will be appreciated.
Thanks,
I've been attempting to transcode a stream produced by obs studio to my nginx server and send it off to youtube. Now I've made it work with twitch and I know these settings are actually transcoding it mostly correctly and is viewable. The problem being that youtube live picks it up as Bad video settings and tells me to change the current video container format. The other side effect that is probly unrelated is the stream looks really poorly on youtube. Looks like it was streamed at a poor bitrate and stuff but the real problem is the bad video settings error.
The ffmpeg command being used is as follows
ffmpeg -i rtmp://localhost/Private/Private1 -vb 6000k -minrate 6000k -maxrate 6000k -bufsize 6000k -s 1280x720 -c:v libx264 -preset faster -r 50 -g 100 -keyint_min 50 -x264opts nal-hrd=cbr:force-cfr=1 -sws_flags lanczos -tune film -pix_fmt yuv420p -c:a copy -f flv -threads 6 -strict normal rtmp://a.rtmp.youtube.com/live2/{key}
I've tried with different framerates and been googling for awhile and found nothing or interpreted everything wrongly. Either way I would be very happy for some help here.
System info.
OS: Ubuntu Server 16.04 LTS
Ram: 10gb
Processor: AMD Phenom(tm) II X6 1090T
GPU: Geforce GT 520
Internet.
Upload 15mbit
Download 150mbit
If you need any more info I will gladly send it. Thanks for reading.
Edit 1
After some googling about what I'm doing wrong I decided to try and change stuff slightly and came up with this command
ffmpeg -re -i rtmp://localhost/(app)/(key) -c:v libx264 -r 50 -g 100 -keyint_min 100 -x264opts "keyint=100:min-keyint=100:no-scenecut" -sws_flags lanczos -profile:v baseline -preset veryfast -vb 6000K -minrate 6000k -maxrate 6000k -bufsize 6000k -s 1280x720 -tune film,zerolatency -pix_fmt yuv420p -f flv -c:a copy -ac 1 -strict normal rtmp://(output site)/(output app)/(output key)
which as of my current testing seems to at least have a healthy stream for longer than 2 minutes if i only output to youtube live directly. Ive found output to my nginx server then youtube live breaks things.
my nginx rtmp settings are on this link https://pastebin.com/siE99Tv8
Edit 2
If I push the stream to a site like restream to stream it to youtube then it seems to be working. tested for 25 minutes with no change of them saying bad video container or anything. So I'm going to say nginx is partly to blame in how its distributing the files? Unsure what I'm doing wrong. I am pretty sure ffmpeg isn't to blame here at least
Seems YouTube does not like nginx. I found two solutions for this.
Solution 1
Add "meta copy;" to you nginx config as follow:
rtmp {
server {
listen 1935;
application youtube{
live on;
meta copy;
push rtmp://a.rtmp.youtube.com/live2/(key);
}
}
}
Solution 2
Modify nginx-rtmp-module/ngx_rtmp_codec_module.c and replace the line:
ngx_string("Server"),
with
ngx_string("xtradata"),
then recompile nginx.
I'm trying to use Nginx to do live stream to combine two stream into one, so I need to spawn FFMpeg, like so
ffmpeg -i "rtmp://in/1" -i "rtmp://in/2" -filter_complex "overlay=70:50" -vcodec libx264 -preset ultrafast -f flv rtmp://out
However, is there a way to detect if one of the incoming stream drops, and I can continue the stream? From what I'm reading, it is not possible, and ffmpeg task will be killed.