ffmpeg: drop duplicate frames and the audio within each frame - audio

I used ffmpeg to drop duplicated video frames using ffmpeg -i in.mp4 -vf mpdecimate,setpts=N/FRAME_RATE/TB out.mp4, but I want to also drop the audio between the frames. How can I do this?

Related

ffmpeg image watermark on video first half of video on Bottom left and next half of video on Top Right

I was playing with this for several hours, I couldn't make so thought of reaching for help, Can you please help me in framing the ffmpeg command to display the watermark Image on the video, For the Initial half video the watermark should be on the bottom left and for the rest half video the watermark shop be on the right top.
Bottom left: ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -codec:a copy output.mp4
Top right:
ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=main_w-overlay_w-5:5" -codec:a copy output.mp4
Also, I had a look on this for Timeoverlay ffmpeg watermark first 30 second.
How to merge all these and satisfy my requirements as mentioned above?
In this example the duration of input.mp4 is 30 seconds. The overlay filter supports the enable option.
ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2:enable='lte(t,15)'[bg];[bg][1]overlay=main_w-overlay_w-5:5:enable='gte(t,15)'" -codec:a copy output.mp4
To get duration see How to get video duration in seconds?. On Linux one method to calculate 50% duration is with bc. See example at Use ffmpeg to get middle frame of a video?
Alternative method is to use the sendcmd filter, but it is more complicated. See example at Sendcmd in ffmpeg.
See available functions at FFmpeg Expression Evaluation.

Extracting Y only (of YUV420p) frame from an MP4 file using fmpeg?

My main objective is to extract the I'th, I+1'th (next), I-1'th (previous) frames in the form of Y only (of YUV 420) from an mp4 video. The procedure which I am using right now is
I extracted the list of all the I frames from a video using the command - ffprobe "input.mp4" -show_frames | grep 'pict_type=I' -A 1 > frame_info.txt
Next, I used a python script to parse through this txt file to find the numbers of all of the I frames and then extracting all of the frames using the command - ffmpeg -i input.mp4 -vf select='eq(n\,{1}),setpts=N/25/TB,extractplanes=y' -vsync 0 -pix_fmt gray {1}.yuv This is happening via a subprocess call from python.
This is working fine for small resolution videos like 240p or 480p but as soon as I move to 1080p videos the time to extract even a single frame increases exponentially. As the ffmpeg seeks to that frame number to extract it and it has to decode the mp4 file till that point.
I have a lot of 1080p files and I was looking to decrease the time. The solution which I was thinking was to extract all of the Y frames (of YUV 420) from mp4 and then selecting only I frames as I've got the list of all of the I frames from step 1.. The command I am using for this is - ffmpeg -y -i input.mp4 -vf "fps=59.94" -pix_fmt gray file_name.yuv
The problem with the above code is that it continuously appends the to yuv file only but I want an individual y file for one frame of the mp4 video.
My restriction is to use FFmpeg only as FFmpeg's Y value is matching with what I want.
TL:DR - I want to extract the Y part only (of YUV 420p) from an mp4 video. The y frames are the I'th and I-1th and I+1th frames.
Thanks for helping out.
In step 1, instead of storing the frame numbers, store the pts_time.
Then, in step 2, run
ffmpeg -copyts -ss X -i input.mp4 -vf select='eq(t\,X),extractplanes=y' -vsync 0 -pix_fmt gray -vframes 1 {1}.yuv
where X is the pts_time.

Use ffmpeg to sequentially add multiple audio tracks and pin a specific track to the end

I have a single video with no audio tracks and want to add several audio tracks sequentially (each track starts immediately after the other).
The basic case might look something like this:
|-----------VIDEO-----------VIDEO-------------VIDEO-----------VIDEO-----------|
|---FULL AUDIO TRACK 1---|---FULL AUDIO TRACK 2---|---PARTIAL AUDIO TRACK 3---|
Here is my attempt to achieve this:
ffmpeg -i video.mov -i audio1.mp3 -i audio2.mp3 -i audio3.mp3 -map 0:0 -map 1:0 -map 2:0 -map 3:0 out.mp4
Of course it doesn't produced the desired result. It only uses the first music clip in out.mp4, and no other audio tracks are started when it ends.
Question 1
What am I missing in order to add multiple audio tracks sequentially? I assume it's specifying starting and end points of audio clips but I'm coming up short on locating the syntax.
...
In addition, I'm looking for a way to ensure that the video ends with the full duration of AUDIO TRACK 3, as seen below:
|-----------VIDEO-----------VIDEO-------------VIDEO-----------VIDEO-----------|
|---FULL AUDIO TRACK 1---|---PARTIAL AUDIO TRACK 2---|---FULL AUDIO TRACK 3---|
In this case, AUDIO TRACK 2 gets trimmed so that the full AUDIO TRACK 3 is pinned to the end.
Question 2
Can this type of audio pinning be done in FFmpeg, or would I have to trim AUDIO TRACK 2 with another program first?
Use the atrim, asetpts, and concat filters:
ffmpeg -i video.mov -i audio1.mp3 -i audio2.mp3 -i audio3.mp3
-filter_complex "[2:a]atrim=duration=5,asetpts=PTS-STARTPTS[a2];[1:a][a2][3:a]concat=n=3:a=1:v=0[a]"
-map 0:v -map "[a]" -c copy -c:a aac -shortest output.mp4
atrim trims the audio. You can also use the start and/or end options if you prefer them over duration.
asetpts resets the timestamps (required by concat).
concat concatenates each audio segment.
If you want to automate this you'll have to script it. You can get the duration of each input with ffprobe:
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4
Then use that to determine the duration of whatever audio stream you want to trim.

Using ffmpeg to remove duplicate frames and connected audio

Using ffmpeg, I was able to remove duplicate frames from a video using ffmpeg -i in.mp4 -vf mpdecimate,setpts=N/FRAME_RATE/TB out.mp4. However, the audio went on for longer than the video, obviously because the command only removed the video portion. How would I remove the segments of audio which accompany the removed frames?

Merge 2 video use ffmpeg but i want

I have two videos of different lengths Video one: 12 minutes Video two: 6 minutes I want to take audio of video one I want to take image of video two And put them together Output video length = 6 minutes. Use ffmpeg one command please help me - thanks ( watch image )____
Use
ffmpeg -i 12m.mp4 -i 6m.mp4 -vf setpts=(PTS-STARTPTS)/1.1 -af atempo=1.1 -map 1:v -map 0:a -shortest new.mp4
The setpts filter alters the video frame timestamps to 1/1.1 of their present value. FFmpeg will drop frames in the cadence needed to preserve source framerate.
The atempo filter speeds up the audio to 1.1 times the original speed.
-map 1:v -map 0:a tells ffmpeg to include the video stream from the 2nd input (6m.mp4) and the audio from the first input.
-shortest tells ffmpeg to conclude conversion when the shorter (of the audio and video) stream ends.

Resources