The ffmpeg thread

A (n internet) friend of mine is doing an online ffmpeg class: Video Art with FFMPEG starting Saturday May 22nd | BustBright - Machine Learning Art

He usually teaches ML classes, so this is not his first rodeo. There is a cheaper audit option open as well.

1 Like

(admin note: this post and the 2 following ones have been moved here from this thread)

We now have an ffmpeg thread which works on Mac, Linux and probably PC (at least on Windows Subsystem for Linux but possibly also in the Cmd prompt?).

To make a short clip, you can trim a video from a given start time mm:ss to an end time mm2:ss2. You can also convert between formats simply by changing the output file extension.

ffmpeg -ss {{mm:ss}} -to {{mm2:ss2}} -i {{input-video.mp4}} -codec copy {{output.mp4}}
2 Likes

Yea, this works on Windows as well. To trim a video down, I use ffmpeg -i INPUT -c:v copy -ss 00:00:10 -to 00:01:00 OUTPUT for example. If you want to trim a duration instead of to a specific time, use -t instead of -to. Replace 00:00:00 with duration of seconds. It would look like this… ffmpeg -i INPUT -c:v copy -ss 00:00:10 -t 50 OUTPUT. Those each accomplish the same task.

Also, for looping clips together, I create a text file with the video file listed however many times I want it repeated like this…

file ‘video1.mp4’
file ‘video1.mp4’
file ‘video1.mp4’

I usually save it as list.txt or something similar, then run… ffmpeg -f concat -i list.txt -c copy output.mp4

Hopefully that helps.

2 Likes

For quite some years I have been using this script to extract short clips (usually 1 second) out of a video. A script to perform a random cut on a video · GitHub

It takes an input video and chooses a random start point and makes a video of between 0.999 seconds to a user defined maximum duration. (I originally made it to make this series of videos

Hope it helps!

7 Likes

For interactive use (the holy grail, for some) I believe Serato (not sure if that’s software or hardware - maybe both) allows for video looping, effecting and scratching like a DJ. But I don’t know nothing anything more about it than that. @decipher__ on twitch usually has a video scratch section of his streams, but he doesn’t save his videos or broadcast to a schedule so you need to get lucky and catch him live.

1 Like

how to get ffmpeg edge detection filters like sobel and prewitt to work correctly, courtesy of @robp:

3 Likes

I had some video captures with intermittent blank frames recently, and this really helped:

Remove blank (black) frames from videos

for I in *.mp4; do
	ffmpeg -i "$I" -vf blackframe=1,metadata=select:key=lavfi.blackframe.pblack:value=0:function=less -vsync cfr -c:a copy "$I-noblanks.mp4"
done

Hello there, I’m new to ffmpeg, and I’m trying to crop videos into grids of any size (2x2, 3x3 etc). This code works well for 2x2 grids but not for any number of grids greater than 2. Could you please tell me what I’m doing wrong?

for filename in os.listdir(path):
    if filename.endswith(".mp4"):
        video_w = 1280
        video_h = 720
        count = 0
        w_count = 2
        h_count = 2
        cw=video_w/w_count
        ch=video_h/h_count
        for y in range(h_count):
            y = video_w * y
            for x in range(w_count):
                x = video_w * x
                command = "ffmpeg -i " + os.path.join(path,filename) + f"  -vcodec h264_nvenc  -vf crop={cw}:{ch}:{x}:{y} " + os.path.join(path, f"crop-{count}.mp4")
                os.system(command)
                count += 1```
1 Like

this is the command I use when I want something unique like cutting out a 2x2 grid of 640x480 frames from the center of a 1920x1080 frame

ffmpeg -i gc.mov -filter_complex "[0]crop=640:480:380:60[tl];[0]crop=640:480:1020:60[tr];[0]crop=640:480:380:540[bl];[0]crop=640:480:1020:540[br]" -map "[tl]" topleft.mp4 -map "[tr]" topright.mp4 -map "[bl]" bottomleft.mp4 -map "[br]" -c:a copy bottomright.mp4

I’ve been wanting to try out https://chat.openai.com to see how it handles ffmpeg and it works pretty well.

this will give you a 3x3 grid.

ffmpeg -i wal.mp4 -filter_complex "[0]crop=iw/3:ih/3:0:0[a1];[0]crop=iw/3:ih/3:iw/3:0[b1];[0]crop=iw/3:ih/3:2*iw/3:0[c1];[0]crop=iw/3:ih/3:0:ih/3[d1];[0]crop=iw/3:ih/3:iw/3:ih/3[e1];[0]crop=iw/3:ih/3:2*iw/3:ih/3[f1];[0]crop=iw/3:ih/3:0:2*ih/3[g1];[0]crop=iw/3:ih/3:iw/3:2*ih/3[h1];[0]crop=iw/3:ih/3:2*iw/3:2*ih/3[i1]" -map "[a1]" output_a.mp4 -map "[b1]" output_b.mp4 -map "[c1]" output_c.mp4 -map "[d1]" output_d.mp4 -map "[e1]" output_e.mp4 -map "[f1]" output_f.mp4 -map "[g1]" output_g.mp4 -map "[h1]" output_h.mp4 -map "[i1]" output_i.mp4

it would be great to have a couple params to change to make different grid sizes but I’ve never had much luck with that.

Anyone here know how I might write to and read from a single video buffer in realtime (while respecting the actual bitstream) using ffmpeg? I’ve been trying to hack my way into this using the concat demuxer but it’s not preserving the bitstream as I would hope.

apologies but i had to add this video to the thread because it is hilarious:

5 Likes