Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f2d9636

Browse files
Merge pull request #238 from Humzafazal72/main
added a basic video editor
2 parents 1ce9311 + e3975e5 commit f2d9636

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Video Editor with FFmpeg
2+
3+
This is a Python project that utilizes the FFmpeg library to perform various video operations, including format conversion, audio extraction, frame extraction, video trimming, and adjusting video speed.
4+
5+
## Prerequisites
6+
7+
Before running this project, ensure that you have FFmpeg installed on your system. You can download FFmpeg from the official website: [FFmpeg](https://ffmpeg.org/download.html).
8+
9+
## Usage
10+
11+
1. Place the video file you want to edit in the same directory as `video_editor.py`.
12+
13+
2. Run the script `video_editor.py` and follow the prompts to select the desired video editing options.
14+
15+
### Video Editing Options
16+
17+
- **Change Video Format**: Convert the video to a different format (e.g., mov, mp4, m4a, 3gp, 3g2, mj2).
18+
19+
- **Convert Video to MP3**: Extract the audio from the video and save it as an MP3 file.
20+
21+
- **Extract Frames**: Extract frames from the video and save them as individual images.
22+
23+
- **Trim Video**: Trim the video by specifying a start and end time (in the format hh:mm:ss).
24+
25+
- **Adjust Video Speed**: Change the speed of the video, which can be useful for creating slow-motion or fast-motion videos.
26+
27+
## Examples
28+
29+
Here are some examples of how to use the video editing options:
30+
31+
```bash
32+
# Change the format of the video to mp4
33+
Do you want to change the format of the video (y/n): y
34+
Input the valid output format (mov, mp4, m4a, 3gp, 3g2, mj2): mp4
35+
36+
# Convert the video to MP3 audio
37+
Do you want to convert the video to MP3 (y/n): y
38+
39+
# Extract frames from the video
40+
Do you want to extract frames from the video (y/n): y
41+
42+
# Trim the video
43+
Do you want to trim the video (y/n): y
44+
Enter the starting time (hh:mm:ss): 00:01:00
45+
Enter the ending time (hh:mm:ss): 00:02:00
46+
47+
# Adjust the speed of the video
48+
Do you want to change the speed of the video (y/n): y
49+
Input the speed (0.5, 1, 1.5, etc): 1.5
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import ffmpeg
2+
import os
3+
4+
def change_video_format(input_file, output_file, format):
5+
print(format)
6+
input_stream = ffmpeg.input(input_file)
7+
output_stream = ffmpeg.output(input_stream, output_file, vcodec="libx264")
8+
ffmpeg.run(output_stream)
9+
10+
def convert_video_to_audio(input_file, output_file):
11+
input_stream = ffmpeg.input(input_file)
12+
output_stream = ffmpeg.output(input_stream, output_file, acodec='mp3')
13+
ffmpeg.run(output_stream)
14+
15+
def convert_video_to_frames(input_file, output_folder):
16+
input_stream = ffmpeg.input(input_file)
17+
ffmpeg.output(input_stream, f'{output_folder}/frame%04d.png').run()
18+
19+
def cut_video(input_file, output_file, start_time, end_time):
20+
input_stream = ffmpeg.input(input_file, ss=start_time, to=end_time)
21+
output_stream = ffmpeg.output(input_stream, output_file, acodec='copy', vcodec='copy')
22+
ffmpeg.run(output_stream)
23+
24+
def adjust_video_speed(input_file, output_file, speed):
25+
input_stream = ffmpeg.input(input_file)
26+
output_stream = ffmpeg.output(input_stream, output_file, filter_complex=f'[0]setpts={1/speed}*PTS', map='0')
27+
ffmpeg.run(output_stream)
28+
29+
if __name__=="__main__":
30+
input_=input("Place The video in the same directory as video_editor.py\nand Input the video name (e.g. input_video.mp4): ")
31+
32+
change_format_opt=input("Do you want to change the format of the video(y/n): ")
33+
if change_format_opt=='y' or change_format_opt=='Y':
34+
format=input("Input the valid output format (mov,mp4,m4a,3gp,3g2,mj2): ")
35+
print(f"output_vids/{input_[0:-4]}.{format}")
36+
change_video_format(input_, f"output_vids/{input_[0:-4]}.{format}", format)
37+
38+
cvt_to_audio_opt=input("Do you want to convert the video to mp3(y/n): ")
39+
if cvt_to_audio_opt=='y' or cvt_to_audio_opt=='Y':
40+
convert_video_to_audio(input_, f"output_vids/{input_[0:-4]}.mp3")
41+
42+
cvt_vid_to_frames=input("Do you want to extract frames from the video(y/n): ")
43+
if cvt_vid_to_frames=='y' or cvt_vid_to_frames=='Y':
44+
path = f"./{input_}_frames"
45+
os.mkdir(path)
46+
print(path)
47+
convert_video_to_frames(input_, path)
48+
49+
cut_opt=input("Do you want to trim the video(y/n): ")
50+
if cut_opt=='y' or cut_opt=='Y':
51+
st=input("Enter the starting time(hh:mm:ss): ")
52+
et=input("Enter the ending time(hh:mm:ss): ")
53+
cut_video(input_, f"output_vids/trimmed_{input_}", st, et)
54+
55+
adjust_speed_opt=input("Do you want to change the speed of video(y/n): ")
56+
if adjust_speed_opt=='y' or adjust_speed_opt=='Y':
57+
speed=float(input("Input the speed(0.5,1,1.5 etc): "))
58+
adjust_video_speed(input_, f'output_vids/sped_up_{input_}', speed)

‎password.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import random
2+
import string
3+
4+
def generate_password(length=12):
5+
characters = string.ascii_letters + string.digits + string.punctuation
6+
password = ''.join(random.choice(characters) for _ in range(length))
7+
return password
8+
9+
# Example: Generate a random password of length 12
10+
password = generate_password()
11+
print("Random Password:", password)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /