I am trying to crossfade a silent input with a music to delay the moment when the music starts to play.
I built the command using fluent-ffmpeg so I could choose the duration of the silent input through my program. The duration of the crossfade is calculated according to the duration of the 2 inputs, and equals 0 if one of them is too short.
Below is an example of the resulting command:
ffmpeg -f lavfi -i anullsrc=r=44100 -i music.mp3 -y -filter_complex [0]atrim=duration=0.28[atrim_0];[atrim_0][1]acrossfade=d=0:c1=tri:c2=tri[final] -map [final] output.mp3
However, this command creates an empty output file when the duration of the silent input is inferior to 1 second, regardless of which music input is next. Using the same command with a trim duration > 1 second creates a valid output with the silence and the music.
I have tried to look through the FFmpeg debug report but couldn't really see what was wrong.
Below is an excerpt of the debug log report:
Input file #0 (anullsrc=r=44100):
Input stream #0:0 (audio): 14 packets read (28672 bytes); 14 frames decoded (14336 samples);
Total: 14 packets (28672 bytes) demuxed
Input file #1 (music.mp3):
Input stream #1:0 (audio): 504 packets read (210651 bytes); 504 frames decoded (578372 samples);
Total: 504 packets (210651 bytes) demuxed
Output file #0 (output.mp3):
Output stream #0:0 (audio): 0 frames encoded (0 samples); 0 packets muxed (0 bytes);
Total: 0 packets (0 bytes) muxed
Any idea what could cause this?
PS: I am using FFmpeg 4.4, and the same command with FFmpeg 4.2 lead to a segmentation fault. Don't know if this can be of any help
acrossfade can accept crossfade duration through two exclusive options: nb_samples (default: 44100) and duration (default: 0). When the latter isn't set, the former is used. So, in your command, acrossfade uses a crossfade duration of 44100 samples or 1 second. The filter needs both inputs to be at least as long as the crossfade duration.
However, in your case, it seems you just want to do two things: fade in the audio and maybe delay it. Just use afade for that.
ffmpeg -i music.mp3 -y -af afade=d=1:curve=tri,adelay=0.28s:all=1 output.mp3
This will fade-in the music over one second and delay the start by 0.28s.
Related
I'm trying to record my screen and speaker audio with ffmpeg but I'm facing various problems.
This is the command I'm using:
ffmpeg -video_size 1920x1080 -framerate 60 -f x11grab -i :0.0 -f pulse -ac 2 -i alsa_output.pci-0000_2d_00.4.analog-stereo.monitor output.mp4
but the output video is really slow and out of sync with the audio.
Moreover, I'm getting these warnings:
[x11grab # 0x563635302480] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
[aac # 0x563635319f40] Queue input is backward in time04.49 bitrate= 466.9kbits/s dup=268 drop=45 speed=1.84x
[mp4 # 0x5636353172c0] Non-monotonous DTS in output stream 0:1; previous: 217669, current: 210387; changing to 217670. This may result in incorrect timestamps in the output file.
When recording the screen with alsa source (microphone), the output video has no problems.
How can I solve?
I need to count the number of frames in a video captured by a camera on a per-second basis. I haven't found a solution using ffmpeg or ffprobe (or something else) to output the number of frames per second (maintaining a constant frame rate is not guaranteed because of the capture mechanism and needs to be verified).
So far, I've needed to run ffmpeg and ffprobe separately. First, I run ffmpeg to trim the video:
ffmpeg -ss 00:00:00 -to <desired time in seconds> -i <in_video> -c copy <out_video>
Then, I run ffprobe to count the number of frames in the snippet:
ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -print_format csv <out_video>
Is there one command to output the number of frames for each second in the video?
Run
ffmpeg -report -i <in_video> -an -vf select='if(eq(n,0),1,floor(t)-floor(prev_selected_t))' -f null -
In the generated report, search for select:1.000000
that will get you lines of the form
[Parsed_select_0 # 000001f413152540] n:270.000000 pts:138240.000000 t:9.000000 key:0 interlace_type:P pict_type:P scene:nan -> select:1.000000 select_out:0
The t is the timestamp and the n is the frame index. Check the frame index for each successive t. The difference is the frame count for that 1 second interval.
I need to convert from .mp3 to .gsm (preferably with ffmpeg).
I used it for several different formats but with this isn't as simple as it was with the others.
I don't know what parameters I'm missing.
I tried using ffmpeg with the following comand:
ffmpeg -i ".\example.mp3" ".\example.gsm"
But it shows me the following error:
Sample rate 8000Hz required for GSM, got 44100Hz Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height Conversion failed!
ffmpeg -ar 8000 -ac 1 -i ".\example.mp3" ".\example.gsm"
-ar sample rate
-ac audio channel
I'm using the following command to record a RTSP stream to a file, for a given amount of time (in this example 30 seconds):
ffmpeg -rtsp_transport tcp -i "rtsp://streamurl:554/ch0" -t 30 output.mp4
Sometimes the source stream is closed-interrupted-finished-shutdown-whateverNameYouWant before the desired timeout (in this example 30 seconds), and the ffmpeg process is finished (with no errors).
I want to know how can I programmatically check if the above ffmpeg command was finished because of the desired timeout (-t <duration> flag), or because the input stream was interrupted.
In other words, I want to know when a problem occurred with the input stream, given that ffmpeg shows no errors when the input stream is closed/interrupted.
I need to merge audio and video using ffmpeg so that, it should result in a video with the same duration as of audio.
I have tried 2 commands for that requirement in my linux terminal. Both the commands work for a few of the input videos; but for some other input_videos, they produce output same as the input video, the audio doesn't get merged.
The commands, I have tried are -
ffmpeg -i wonders.mp4 -i Carefull.mp3 -c copy testvid.mp4
and
ffmpeg -i wonders.mp4 -i Carefull.mp3 -strict -2 testvid.mp4
and
ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac -strict
experimental output.mp4
and these are my input videos -
samplevid.mp4
https://vid.me/z44E
duration - 28 seconds
size - 1.1 MB
status - working
And
wonders.mp4
https://vid.me/gyyB
duration - 97 seconds
size - 96 MB
status - not working
I have observed that the large size (more than 2MB) of the input video is probably the issue.
But, still I want the fix.