I need to insert a short beep into another audio file (similar to a censorship bleep) using linux and/or php.
I'm thinking there should be some way to do it with ffmpeg (with some combination of -t, concat, map, async, adelay, itsoffset?) or avconv or mkvmerge - but haven't found anyone doing this. Maybe I need to do it in 2 stages somehow?
For example if I have a 60 second mp3 and want to beep out 2 seconds at 2 places the desired result would be:
0:00-0:15 from original
0:15-0:17 beep (overwrites the 2 secs of original)
0:17-0:40 from original
0:40-0:42 beep
0:42-0:60 from original
I have a 2 second beep.mp3, but can use something else instead like -i "sine=frequency=1000:duration=2"
You can use the concat demuxer.
Create a text file, e.g.
file main.wav
inpoint 0
outpoint 15
file beep.wav
file main.wav
inpoint 17
outpoint 40
file beep.wav
file main.wav
inpoint 40
outpoint 42
and then
ffmpeg -f concat -i list.txt out.mp3
Convert the beep file to have the same sampling rate and channel count as the main audio.
First, you need to have beep.mp3 time equal to 60 seconds or little bit less than your mp3 file time.
Then, you can use ffmpeg code -ss <start_time> -t <duration> -i <your_file>.mp3
ffmpeg -ss 00:00:00 -t 15 -i ./original.mp3 -ss 00:15:00 -t 2 -i ./beep.mp3 -ss 00:17:00 -t 23 -i ./original.mp3 -ss 00:40:00 -t 2 -i ./beep.mp3 -ss 00:42:00 -i ./original.mp3 -filter_complex '[0:0][1:0] concat=n=2:v=0:a=1[out]' -map '[out]' ./output.mp3
at the end you will get output.mp3 file as you needed.
Related
I would like to cut a video at the beginning at any particular timestamp, and it need to be precise, so the nearest key frame is not good enough.
Also, these videos are rather long - an hour or longer - so I would like to avoid re-encoding this altogether if possible, or otherwise only re-encode a minimal fraction of the total duration. Thus, would like to maximise the use of -vcodec copy.
How can I accomplish this using ffmpeg?
NOTE: See scenario, and my own rough idea for a possible solution below.
Scenario:
Original video
Length of 1:00:00
Has a key frame every 10s
Desired cut:
From 0:01:35 through till the end
Attempt #1:
Using -ss 0:01:35 -i blah.mp4 -vcodec copy, what results is a file where:
audio starts at 0:01:30
video also starts at 0:01:30
this starts both the audio and the video too early
using -i blah.mp4 -ss 0:01:35 -vcodec copy, what results is a file where:
audio starts at 0:01:35,
but the video is blank/ black for the first 5 seconds,
until 0:01:40, when the video starts
this starts the audio on time,
but the video starts too late
Rough idea
(1) cut 0:01:30 to 0:01:40
re-encode this to have new key frames,
including one at the target time of 0:01:35
then cut this to get the 5 seconds from 0:01:35 through 0:01:40
(2) cut 0:01:40 through till the end
without re-encoding, using -vcodec copy
(3) ffmpeg concat the first short clip (the 5 second one)
with the second long clip
I know/ can work out the commands for (2) and (3), but am unsure about what commands are needed for (1).
List timestamps of key frames:
ffprobe -v error -select_streams v:0 -skip_frame nokey -show_entries frame=pkt_pts_time -of csv=p=0 input.mp4
It will output something like:
0.000000
2.502000
3.795000
6.131000
10.344000
12.554000
16.266000
...
Let's say you want to delete timestamps 0 to 5, and then stream copy the remainder. The closest following key frame is 6.131.
Re-encode 5 to 6.131. Ensure the input and output match attributes and formats. For MP4 default settings should do most of the work, assuming H.264/AAC, but you may have to manually match the profile.
ffmpeg -i input.mp4 -ss 5 -to 6.131 trimmed.mp4
Make input.txt for the concat demuxer:
file 'trimmed.mp4'
file 'input.mp4'
inpoint 6.131
Concatenate:
ffmpeg -f concat -i input.mp4 -c copy output.mp4
try
ffmpeg -i src.mp4 -vcodec copy -reset_timestamps 1 -map 0 out.mp4
or
ffmpeg -i src.mp4 -vcodec copy -reset_timestamps 1 -map 0 src_.m3u8
which generates hls playlists
How to use the command line tool ffmpeg on Windows to split a sound file to multiple sound files without changing the sound properties same everything each one is fixed 30 seconds length. I got this manual example from here:
ffmpeg -i long.mp3 -acodec copy -ss 00:00:00 -t 00:00:30 half1.mp3
ffmpeg -i long.mp3 -acodec copy -ss 00:00:30 -t 00:00:30 half2.mp3
But is there a way to tell it to split the input file to equally sound files each one is 30 seconds and the last one is the remaining what ever length.
You can use the segment muxer.
ffmpeg -i long.mp3 -acodec copy -vn -f segment -segment_time 30 half%d.mp3
Add -segment_start_number 1 to start segment numbering from 1.
I have an mp4 file and I want to take two sequential sections of the video out and render them as individual files, later recombining them back into the original video. For instance, with my video video.mp4, I can run
ffmpeg -i video.mp4 -ss 56 -t 4 out1.mp4
ffmpeg -i video.mp4 -ss 60 -t 4 out2.mp4
creating out1.mp4 which contains 00:00:56 to 00:01:00 of video.mp4, and out2.mp4 which contains 00:01:00 to 00:01:04. However, later I want to be able to recombine them again quickly (i.e., without reencoding), so I use the concat demuxer,
ffmpeg -f concat -safe 0 -i files.txt -c copy concat.mp4
where files.txt contains
file out1.mp4
file out2.mp4
which theoretically should give me back 00:00:56 to 00:01:04 of video.mp4, however there are always dropped audio frames where the concatenation occurs, creating a very unpleasant sound artifact, an audio blip, if you will.
I have tried using async and -af apad on initially creating the two sections of the video but I am still faced with the same problem, and have not found the solution elsewhere. I have experienced this issue in multiple different use cases, so hopefully this simple example will shed some light on the real problem.
I suggest you export segments to MOV with PCM audio, then concat those but with re-encoding audio.
ffmpeg -i video.mp4 -c:a pcm_s16le -ss 56 -t 4 out1.mov
...
and then
ffmpeg -f concat -safe 0 -i files.txt -c:v copy concat.mp4
lets say I have a video file (video.mp4) and 2 audio files (audio1.mp3 and audio2.mp3.) The video has a length of 60 seconds, every audio file has a length of 30 seconds.
What I am trying to achive is:
the first 20 seconds of the video is with original audio stream, followed by 20 seconds of the first audio file (offset of 5 seconds with a length of 20s) and the same with the second audio file.
ffmpeg -i video.mp4 -ss 5 -t 20 -i audio1.mp3 -ss 5 -t 20 -i audio2.mp3 -vcodec copy -acodec copy -copyinkf -map 0:v:0 -map 1:a:0 -map 2:a:0 -shortest final.mp4
The command above takes the video stream of the first input and the audio stream of the third input. The audio stream of the second input seems to be overwritten. How can I put all audio streams together and how can I define the offset when the audio streams should begin?
I assume that you want the combined audio programme in one stream. Even if you applied timestamp offsets to the other audios, most players won't switch audio streams mid-playback.
So,
ffmpeg -i video.mp4 -ss 5 -t 20 -i audio1.mp3 -ss 5 -t 20 -i audio2.mp3
-filter_complex
"[0]atrim=0:20[a];[1]adelay=20000|20000[b];[2]adelay=40000|40000[c];[a][b][c]amix=3"
-vcodec copy -copyinkf -shortest final.mp4
I am trying to clip an MP3 between two starting points, like starting at 10 seconds and ending at 16 seconds (time interval of 6 seconds).
I am using this command:
ffmpeg -ss 10 -i input.mp3 -t 6 output.mp3
The resulting output.mp3 contains the 6 seconds that I specified followed by 8 or 9 seconds of empty audio. Is there something wrong with my command?
Edit:
ffmpeg -ss 10 -t 6 -i input.mp3 output.mp3 says -t is not an input option, keeping it for the next output; consider fixing your command line. and gives me a file that's got 8 seconds of audio starting from 10s and then some 9 or 10 seconds of silence.
ffmpeg -ss 10 -to 16 -i input.mp3 output.mp3 produces a file that is twice the length of the original - basically the same audio file repeated again.\
Testing the output:
I used Quicktime and it has silent audio at the end. The description of the output file in finder says like 14 seconds. When I use VLC, it plays for the correct 6 seconds and stops, even though its duration in the file browser in VLC says 14. My MPlayer doesn't work properly. I also did the preview audio in Finder, and it plays the 6 seconds properly and then stops. But the round seeker bar of the MP3 didn't reach the end. And it also says 14 seconds instead of 6.
My goal is to stream this 6 second file through a REST API to the front end. I want the user to be able to download this file properly. Ideally it won't have inconsistent metadata (14 seconds instead of 6).
For me both
ffmpeg -ss 10 -t 6 -i input.mp3 output.mp3
or
ffmpeg -ss 10 -i input.mp3 -t 6 output.mp3
work OK, just 6 seconds of audio. Here's the mplayer output (last line):
A: 5.8 (05.7) of 6.0 (06.0) 0.5%
Also
ffmpeg -ss 10 -to 16 -i input.mp3 output.mp3
work the same way. I use ffmpeg version 1.2.4. I guess your ffmpeg is somehow "broken" or the input file is somehow (report a bug in either case).
You may try the other answer with mp3cut from portforwardpodcast or
sox input.mp3 output.mp3 trim 10 6
ffmpeg - Trim audio file without re-encoding
Use ffmpeg to trim an audio file without re-encoding it.
Trim starting from 10 seconds and end at 16 seconds (total time 6 seconds)
ffmpeg -i input.mp3 -ss 10 -t 6 -acodec copy output.mp3
Trim from 00:02:54.583 to the end of the file
ffmpeg -i input.mp3 -ss 00:02:54.583 -acodec copy output.mp3
Trim from 00:02:54.583 for 5 minutes (300 seconds)
ffmpeg -i input.mp3 -ss 00:02:54.583 -t 300 -acodec copy output.mp3
I've had great success with both CBR and VBR mp3 files using mp3cut.
mp3cut -o output.mp3 -t 00:10-00:16 input.mp3
http://manpages.ubuntu.com/manpages/lucid/man1/mp3cut.1.html