ljubomir38
New member
Video
Why?
I'm scrolling through Instagram every day, and I'm like, can I do some cool videos or edits?
But I've never used any video editing software...
But I can code!
So here it goes...
What?
- Take an arbitrary amount of clips and one audio.
- Combine it in a short video where small clips are switching one after another when next beat comes in.
Try it yourself
- Clone code from GitHub Gist to some folder,
Code:
video_edits
- Install dependencies.
- Change
Code:
video_file_paths
Code:audio_file_path
Code:main.py
- Run
Code:
python ./video_edits/main.py
- Open generated
Code:
video.mp4
- Enjoy!
Main ideas
![Musical note :musical_note: 🎵](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f3b5.png)
Code:
Librosa
Code:
y, sr = librosa.load(audio_file_path)
beat_times = librosa.beat.beat_track(y=y, sr=sr, units="time")[1].tolist()
![Movie camera :movie_camera: 🎥](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f3a5.png)
Code:
crop='
if(
gte(
in_h,
1920 * (in_w / 1080)
),
in_w,
1080 * (in_h / 1920)
)
':'
if(
gte(
in_h,
1920 * (in_w / 1080)
),
1920 * (in_w / 1080),
in_h
)
',
scale=w=1080:h=1920,
setsar=1
Crop looks like:
Code:
crop='width':'height'
Crop, as it's present in code, will crop starting from middle of the video, so central part.
Code:
in_h
Code:
in_w
Logic is next:
- If it's extremely high video, we want to preserve width and crop height.
- If it's extremely wide video, we want to preserve height and crop width.
- Otherwise we preserve height and crop width.
Code:
scale
Code:
setsar
![Snake :snake: 🐍](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f40d.png)
- Resize each video with FFMPEG and trim time to duration of a beat, which is duration from previous beat to current one.
- All videos then concatenated to one video clip.
- Audio part with selected beats is added to a resulting video.
Links
Media sources HERE.
Librosa documentation: https://librosa.org/doc/0.10.1/.
FFMPEG guide: https://img.ly/blog/ultimate-guide-to-ffmpeg.
What's next?
I'll continue to share interesting edits and how I did it!
Maybe will create repo where I'll be keeping all utils for edits.
OF COURSEEEEE
Check my socials, if you want!