I am appending 2 mp4 files together using the following routine:
ffmpeg -y -i one.mp4 -vcodec copy -vbsf h264_mp4toannexb -acodec copy one.ts
ffmpeg -y -i two.mp4 -vcodec copy -vbsf h264_mp4toannexb -acodec copy two.ts
cat one.ts two.ts >> joined.ts
ffmpeg -y -i joined.ts -vcodec copy -acodec copy -absf aac_adtstoasc joined.mp4
This works fine, however when one.mp4 has no audio stream (the file is created using ffmpeg from a single jpeg, so no sound), the routine appends the files but the audio of two.mp4 starts at the beginning of the video. how should I solve this problem? Should I add switches to my append routine so that the audio in two.mp4 starts playing where it should, or should I add something to the ffmpeg command which creates the video from jpg?
here is the command I use to create one.mp4 which contains no sound:
ffmpeg -y -loop 1 -i blah.jpg -t 3 -vcodec libx264 one.mp4
Related
there are what i done:
download a full mp4 file.
due to it's watermark(0s-10s), i split the full video into 2 parts from 10second. the first part with watermark.
use ffmpeg delogo the first part.
merge the two video into a full again.
wget -O download.mp4
ffmpeg -i download.mp4 -vcodec copy -acodec copy -t 00:00:10 tmp1.mp4
ffmpeg -i download.mp4 -vcodec copy -acodec copy -ss 00:00:10 tmp2.mp4
ffmpeg -i tmp1.mp4 -vf "delogo=x=432:y=44:w=1060:h=108" -c:a copy tmp3.mp4
echo file tmp3.mp4 > mergelist.txt && echo file tmp2.mp4 >> mergelist.txt
ffmpeg -f concat -i mergelist.txt -c copy output.mp4
problem i faced:
in the last merged video, only one tmp part is fine, the other's video and voice not sync and play time more faster than before.
why i divide it, delogo(although only the first 10 seconds shows) full video more than 1h, re-encode takes much time, 10s part fine to me.
Have you tried this?
ffmpeg -i download.mp4 -vf "delogo=enable='lte(t,10)':x=432:y=44:w=1060:h=108" -c:a copy output.mp4
I'm assuming delogo filter is timeline editing enabled.
I have 2 files:
video_orginal.ts,
sound_outside.wav
video_orginal have own sound track. I wants to turn down the volume of the sound from video_orginal and next merge sound_outside.wav with sound in video_orginal to finally get a video with mixed audio. Now I execute 4 working commands:
ffmpeg -i video_orginal.ts -map 0:a -c copy sound_from_video.wav -map 0:v -c copy video_clean.ts --exteract audio and video
ffmpeg -i sound_from_video.wav -filter:a "volume=0.3" sound_from_video_quiet.wav --quiet sound
ffmpeg -i sound_from_video_quiet.wav -i sound_outside.wav -filter_complex amix=inputs=2:duration=longest sound_mixed.wav --merge sounds
ffmpeg -i video_clean.ts -i sound_mixed.wav -c copy video_final.mkv --final merge video and sound
It is possible to execute only one command which will do all these steps with as little encoding as possible?
This code is combining 3 mp4 files using ffmpeg command. Each file has audio.
After combining, I can listen audio for only first part.
How can I solve this problem?
===========================================================================
ffmpeg -y -i "tmp/titled-0c33a83dc70534c67f66.mp4" -i "tmp/titled-1c2fc9a95e644ab135a3.mp4" -i "tmp/titled-73c3fb1a3ea435cacdd2.mp4" -i "logo/logo.png" -filter_complex "
nullsrc=s=1280x720[bg];
[0:v]setpts=PTS-STARTPTS+0/TB[v0];
[1:v]setpts=PTS-STARTPTS+4.039/TB[v1];
[2:v]setpts=PTS-STARTPTS+8.078/TB[v2];
[bg][v0]overlay=x='if(lte(t,4.039),0,min(0,-w*min(1,max(0,0.98*(t-4.039)^2))))':y=0,trim=duration=13.145[bg];
[bg][v1]overlay=x='if(gte(t,8.078),-w*min(1,max(0,0.98*(t-8.078)^2)),max(0,1280*(1-min(1,max(0,0.69*(atan(8*(t-4.039)^2.7)))))))':y=0[bg];
[bg][v2]overlay=x='max(0,1280*(1-min(1,max(0,0.69*(atan(8*(t-8.078)^2.7))))))':y=0"
-y -vcodec h264 -crf 13 -acodec aac -strict -2 "out.mp4"
I would really appreciate if someone could give some pointers regarding the use of itsoffset with ffmpeg. I have read a number of posts on this subject, some of them explain very clearly how to re-synchronize audio and video with -itsoffset, but I haven't been able to make it work.
My avi file is encoded with ffmpeg, in two passes, using the following command for the second pass:
ffmpeg -i whole-vts_01.avs -pass 2 -y -vcodec libxvid -vtag XVID -b:v 1300K -g 240 -trellis 2 -mbd rd -flags +mv4+aic -acodec ac3 -ac 2 -ar 48000 -b:a 128k output.avi
For whatever reason, I end up with a 1 sec delay in the video (or the audio is 1 sec early). It doesn't happen too often but I see it from time to time.
Among other attempts, I have tried the following:
(1) ffmpeg -i output.avi -itsoffset 00:00:01.0 -i output.avi -vcodec copy -acodec copy -map 0:0 -map 1:1 output-resynched.avi
(2) ffmpeg -i output.avi -itsoffset 00:00:01.0 -i output.ac3 -vcodec copy -acodec copy -map 0:0 -map 1:0 output-resynched2.avi
(3) ffmpeg -itsoffset -00:00:01.00 -i output.avi output-resynched8.avi
(4) ffmpeg -i output.avi -itsoffset -1.0 -i output.avi -vcodec copy -acodec copy -map 0:1 -map 1:0 output-resynched13.avi
Here are the results:
Audio garbled and only 5m 35 s long vs. 1h 41m.
(Output.ac3 is audio component of output.avi) Video and audio
identical to original, offset didn't work
Audio did get shifted, but original encoding parameters replaced with default ones (as expected).
Audio garbled and only 9m 56s long vs. 1h 41m.
I see that many people explain, and apparently use the process described above, but it doesn't seem to be working for me. Am I missing something obvious? I would very much like to be able to use -itsoffset as it is cleaner than my workaround solution.
FWIW, here is a different, and longer way of obtaining the desired result:
First create a shifted video only file using -ss:
ffmpeg -i output.avi -ss 1.0 -vcodec copy -an oupput_videoshifted.avi
Then extract the audio:
ffmpeg -i output.avi -vn -acodec copy outputaudioonly.ac3
And finally remux both components:
ffmpeg -i output_videoshifted.avi -i output_audioonly.ac3 -vcodec copy -acodec copy -map 0:0 -map 1:0 output-resynched14.avi
The process works, is fast enough, but I would really prefer to use the one pass -itsoffset solution.
Here is what I did and it work for me
The first input setting -i and the second input is come from the same one video file.
Delay 1 second in first input video and the second input audio just make a copy
ffmpeg -y -itsoffset 00:00:01.000 -i "d:\Video1.mp4" -i "d:\Video1.mp4"
-map 0:v -map 1:a -vcodec copy -acodec copy
-f mp4 -threads 2 -v warning "Video2.mp4"
Delay 1 second in second input audio and the first input video just make a copy
ffmpeg -y -i "d:\Video1.mp4" -itsoffset 00:00:01.000 -i "d:\Video1.mp4"
-map 0:v -map 1:a -vcodec copy -acodec copy
-f mp4 -threads 2 -v warning "Video2.mp4"
The problem is located on -vcodec copy -acodec copy because the shifting will only work on keyframes. I have had the same problem.
Just don't copy (audio/)video, try the thing with -itsoffset, but use
-vcodec libxvid -vtag XVID -b:v 1300K -g 240 -trellis 2 -mbd rd -flags +mv4+aic -acodec ac3 -ac 2 -ar 48000 -b:a 128k
for re-encoding. It should work.
I would like to script this command
ffmpeg -i concat:file1.mp3\|file2.mp3 -acodec copy output.mp3
which merges file1.mp3 and file2.mp3 to become output.mp3.
The problem is that I have a lot more than 2 files that I would like to merge.
Example
ffmpeg -i concat:file1.mp3\|file2.mp3 -acodec copy output1.mp3
ffmpeg -i concat:output1.mp3\|file3.mp3 -acodec copy output2.mp3
ffmpeg -i concat:output2.mp3\|file4.mp3 -acodec copy output3.mp3
ffmpeg -i concat:output3.mp3\|file5.mp3 -acodec copy output4.mp3
output4.mp3 is the result I am looking for.
The files are not actually nicely called "file" adn then a number, but ls lists them in the order they should be merged in.
Question
How can this be scripted, so I can execute it in a directory with either an even or odd number of files?
if ffmpeg supports more then two files and no file contains |, and there are not too many, you can do:
ffmpeg -i concat:"$(ls|tr '\n' '|')" -acodec copy out.mp3
if not:
for cfile in *.mp3; do
ffmpeg -i concat:myout.mp3tmp1\|$cfile -acodec copy myout.mp3tmp2
mv myout.mp3tmp2 myout.mp3tmp1
done
mv myout.mp3tmp1 <your final file name>
If you can just concatenate all files in one wash, that'd be best. But a generic answer for your Bash question:
ffmpeg -i concat:file1.mp3\|file2.mp3 -acodec copy output1.mp3
for i in $(seq 1 10); do
ffmpeg -i concat:output${i}.mp3\|file$((i + 2)).mp3 -acodec copy output$((i + 1)).mp3
done
Here 10 is two less than your total number of input files.