use ffmpeg to cut video,the video will have extra duration - ffmpeg

ffmpeg -ss 2 -i input.mp4 -c copy -t 5 out.mp4
after I executed the ffmpeg command.
the out.mp4 total have 7 seconds,it starts from the second frame of input.mp4 to the seventh frame of input.mp4.
It only has 5 effective seconds of the input.mp4, the last 2 seconds of input.mp4 is empty.

ffmpeg -ss 00:00:02.00 -i input.mp4 -t 5 out_5seconds.mp4

Related

How to merge a video vertically by taking specific time slots from two different videos with a single ffmpeg command?

I have three ffmpeg commands. Two of those commands will trim the input videos and the third will merge into a single video.
I want to run them as a single command instead of three, which consumes a lot of time because I'm taking output of the 1st and 2nd videos individually.
Instead, I want to take specific parts from the videos which I need and merge them as a single video.
The commands which I use for singie videos trim:-
ffmpeg -y -i video1.mp4 -ss 4 -t 10000 -qscale:v 8 -strict -2 video1out.mp4
ffmpeg -y -i video2.mp4 -ss 4 -t 10000 -qscale:v 8 -strict -2 video2out.mp4
ffmpeg -i video1out.mp4 -i video2out.mp4 -filter_complex vstack -strict -2 merge.mp4
Use
ffmpeg -ss 4 -t 10000 -i video1.mp4 -ss 4 -t 10000 -i video2.mp4 -filter_complex vstack -c:a copy merge.mp4
-strict -2 hasn't been required for AAC encoder use since 2016. You should upgrade ffmpeg.

FFmpeg remove 2 sec from middle of video and concat the parts. Single line solution

I have a video file that is 22 seconds long.
I want to remove the segment from 10 seconds to 12 seconds.
Then return a concatenated video file of seconds 1-10 and 12-22.
I want to do this in a single FFmpeg command.
This is the easy way
Source
https://www.labnol.org/internet/useful-ffmpeg-commands/28490/
ffmpeg -i input.mp4 -ss 00:00:00.0 -codec copy -t 10 output_1.mp4
and
ffmpeg -i input.mp4 -ss 00:00:12.0 -codec copy -t 10 output_2.mp4
then create an input file with all the source file names and run
ffmpeg -f concat -i file-list.txt -c copy output.mp4
But I'm looking for a one line solution
Any help would be appreciated.
For exact trimming, you'll have to re-encode
Use
ffmpeg -i input.mp4 -vf select='not(between(t,10,12))',setpts=N/FRAME_RATE/TB -af aselect='not(between(t,10,12))',asetpts=N/SR/TB out.mp4

ffmpeg concat video and image issue

I have a video it's 190 seconds long.
I want to show a part of the video with audio and a watermark (from 28th second to 154th second)
and then the video fades out, and then show an image for 5 seconds at the end of the video.
everything was working fine until i added concat and endpic.jpg
Here is the script it wrote but it's not working. It's really driving me crazy.
ffmpeg -y -ss 28 -i input.mp4 -loop 1 -i watermark.png -loop 1 -t 5 -i endpic.jpg -f lavfi -t 5 -i anullsrc -filter_complex "[1]fade=in:st=3:d=1:alpha=1,fade=out:st=20:d=1:alpha=1[w]; [0][w]overlay=main_w-overlay_w-10:main_h-overlay_h-10[sonh];[sonh]fade=out:st=154:d=1[sonhh];[sonhh:v][sonhh:a][2:v][3:a]concat=n=2:v=1:a=1[v][a]" -t 155 -map "[v]" -map "[a]" output.mp4
Use
ffmpeg -y -ss 28 -to 154 -i input.mp4 -loop 1 -t 22 -i watermark.png -loop 1 -t 5 -i endpic.jpg -f lavfi -t 5 -i anullsrc -filter_complex "[1]fade=in:st=3:d=1:alpha=1,fade=out:st=20:d=1:alpha=1[w]; [0][w]overlay=main_w-overlay_w-10:main_h-overlay_h-10,fade=out:st=154:d=1[sonhh];[sonhh][0:a][2:v][3:a]concat=n=2:v=1:a=1[v][a]" -t 155 -map "[v]" -map "[a]" output.mp4
If you don't limit the input duration, ffmpeg will feed till 190s of the input, and due to -t 155, the output will never get to the end of the input and the start of endpic.
Linklabels assigned within a filtergraph don't represent the original inputs so [sonhh:v][sonhh:a] isn't valid. The input audio remains [0:a].
Input -to was added a few months ago, so ensure you're using a recent build of ffmpeg.

How how can i frame cut between, using ffmpeg?

ffmpeg -i in.mp4 -vf "select='if(gt(scene,0.03),st(1,t),lte(t-ld(1),4))',setpts=N/FRAME_RATE/TB" -an trimmed2.mp4
my code but, it did not work for my case. help pls
Say you want to trim from 1.25 seconds in to 5 seconds in:
ffmpeg -ss 1.25 -i in.mp4 -to 5 -an trimmed2.mp4
Same thing but specifying duration instead of end point (preferred probably):
ffmpeg -ss 1.25 -i in.mp4 -t 3.75 -an trimmed2.mp4
Or if you only wanted exactly 40 frames:
ffmpeg -ss 1.25 -i in.mp4 -frames:v 40 -an trimmed2.mp4
More info on seeking / trimming here: https://trac.ffmpeg.org/wiki/Seeking#Cuttingsmallsections

Ffmpeg show an image for multiple seconds before a video without re-encoding

I've been looking all around for this. Problem is that most google searches end up with being about creating a video from solely PNG files.
I've found this command which does the job :
ffmpeg -y -loop 1 -framerate 60 -t 5 -i firstimage.jpg -t 5 -f lavfi -i aevalsrc=0 -loop 1 -framerate 60 -t 5 -i secondimage.png -t 5 -f lavfi -i aevalsrc=0 -loop 1 -framerate 60 -t 5 -i thirdimage.png -t 5 -f lavfi -i aevalsrc=0 -i "shadowPlayVid.mp4" -filter_complex "[0:0][1:0][2:0][3:0][4:0][5:0][6:0][6:1] concat=n=4:v=1:a=1 [v] [a]" -map [v] -map [a] output.mp4 >> log_file1.txt 2>&1
But it seems to reencode the whole video, the input video is H.264 without CFR, but it seems to me that putting just some images before the video shouldn't take too long.
Because it ends up encoding the whole thing, this takes about 2 hours with a video of 30 minutes on a strong computer, while I feel like without encoding this should be able to be done much quicker. How do I make sure it doesn't re-encode while maintaining every image showing for 5 seconds first?
Generate your playervid.mp4 via
ffmpeg -y -loop 1 -framerate 60 -t 5 -i sample-out3.jpg -f lavfi -t 5 -i aevalsrc=0 -vf settb=1/60000 -video_track_timescale 60000 -c:v libx264 -pix_fmt yuv420p playervid.mp4

Resources