-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Screen recording #10832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Screen recording #10832
Changes from 13 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
5dfff7a
first pass
dawoodkhan82 92e92e7
Merge branch 'main' into screen-recording
dawoodkhan82 99eda92
canvas version comp
dawoodkhan82 1bd8626
add changeset
gradio-pr-bot 706e863
process video backend using ffmpeg
dawoodkhan82 07d52a3
fix
dawoodkhan82 2059eaa
remove zoom effects
dawoodkhan82 97fafe9
Merge branch 'main' into screen-recording
dawoodkhan82 39febed
fixes
dawoodkhan82 1a991a7
format
dawoodkhan82 7ef6dbf
mp4
dawoodkhan82 ce5e8c2
add changeset
gradio-pr-bot a342fe6
remove watermark
dawoodkhan82 f870faf
add back processing
dawoodkhan82 4dfb2b5
Merge branch 'main' into screen-recording
dawoodkhan82 83641fd
zoom working
dawoodkhan82 f7d6b2e
gradual zoom
dawoodkhan82 b3c66c3
zoom fix
dawoodkhan82 806ecdf
convert to mp4
dawoodkhan82 a924c82
zoom speed
dawoodkhan82 87dd4bd
remove padding
dawoodkhan82 dfb55ed
resolution and fps fix
dawoodkhan82 2037af3
Merge branch 'main' into screen-recording
dawoodkhan82 28a84a3
zoom level
dawoodkhan82 52a5070
remove comments
dawoodkhan82 732fbc2
adjust zoom level + format
dawoodkhan82 bf8aac7
fix
dawoodkhan82 6151e1d
Merge branch 'main' into screen-recording
dawoodkhan82 864fadf
fix
dawoodkhan82 4a174e6
Merge branch 'main' into screen-recording
dawoodkhan82 a7454c6
notebooks
dawoodkhan82 f22710a
changes
dawoodkhan82 0d8ae75
adjust pan
dawoodkhan82 99882c2
format
dawoodkhan82 455a253
Merge branch 'main' into screen-recording
dawoodkhan82 d7a1e53
lint
dawoodkhan82 37d393f
ui changes
dawoodkhan82 3123392
format
dawoodkhan82 2aefa95
fix examples issue
dawoodkhan82 101ee21
better centering
dawoodkhan82 d55867f
merge
dawoodkhan82 ff2f6c9
fix time remap issue
dawoodkhan82 0b3ad9e
check for overlapping zooms
dawoodkhan82 12ed8bc
Merge branch 'main' into screen-recording
dawoodkhan82 41451ab
show ffmpeg error message
dawoodkhan82 2403257
enfore 30 fps
dawoodkhan82 1d0b448
Merge branch 'main' into screen-recording
dawoodkhan82 f73e48d
remove info toast + better zoom on safari
dawoodkhan82 4f6c57f
Merge branch 'main' into screen-recording
dawoodkhan82 e02b1b6
fix tests
dawoodkhan82 fd6691f
format
dawoodkhan82 5452caf
Merge branch 'main' into screen-recording
dawoodkhan82 5fb7f7a
Merge branch 'main' into screen-recording
abidlabs dbffed8
examples + trim start
dawoodkhan82 a6bf4e7
move recording to settings
dawoodkhan82 6cdb60e
Merge branch 'main' into screen-recording
dawoodkhan82 d949e7f
add settings for zoom/trim
dawoodkhan82 833363b
temp file fix
dawoodkhan82 b763c13
Merge branch 'main' into screen-recording
dawoodkhan82 1f0ee69
tempfile
dawoodkhan82 4165cd1
format
dawoodkhan82 a67ffa9
Merge branch 'main' into screen-recording
dawoodkhan82 31d5c51
test fix
dawoodkhan82 2814878
Merge branch 'main' into screen-recording
dawoodkhan82 76dd5d4
format
dawoodkhan82 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@gradio/core": minor | ||
| "gradio": minor | ||
| --- | ||
|
|
||
| feat:Screen recording |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| import gradio as gr | ||
|
|
||
|
|
||
| def greet(name): | ||
| return "Hello " + name + "!" | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| import asyncio | ||
| import os | ||
| import shutil | ||
| import tempfile | ||
| import traceback | ||
|
|
||
|
|
||
| async def process_video_with_ffmpeg(input_path, output_path, params): | ||
| """Process a video with ffmpeg based on the provided parameters.""" | ||
| current_input = input_path | ||
| temp_files = [input_path] | ||
|
|
||
| try: | ||
| if params.get("remove_segment_start") and params.get("remove_segment_end"): | ||
| start = float(params["remove_segment_start"]) | ||
| end = float(params["remove_segment_end"]) | ||
|
|
||
| if start < end: | ||
| segment_output = tempfile.mktemp(suffix="_trimmed.mp4") | ||
| before_segment = tempfile.mktemp(suffix="_before.mp4") | ||
| after_segment = tempfile.mktemp(suffix="_after.mp4") | ||
|
|
||
| temp_files.extend([segment_output, before_segment, after_segment]) | ||
|
|
||
| if start > 0: | ||
| cmd_before = [ | ||
| "ffmpeg", | ||
| "-y", | ||
| "-i", | ||
| current_input, | ||
| "-t", | ||
| str(start), | ||
| "-c:v", | ||
| "libx264", | ||
| "-preset", | ||
| "fast", | ||
| "-crf", | ||
| "22", | ||
| "-c:a", | ||
| "aac", | ||
| before_segment, | ||
| ] | ||
|
|
||
| process = await asyncio.create_subprocess_exec( | ||
| *cmd_before, | ||
| stdout=asyncio.subprocess.PIPE, | ||
| stderr=asyncio.subprocess.PIPE, | ||
| ) | ||
| stdout, stderr = await process.communicate() | ||
|
|
||
| if process.returncode != 0: | ||
| print(f"FFmpeg before segment error: {stderr.decode()}") | ||
|
|
||
| cmd_after = [ | ||
| "ffmpeg", | ||
| "-y", | ||
| "-i", | ||
| current_input, | ||
| "-ss", | ||
| str(end), | ||
| "-c:v", | ||
| "libx264", | ||
| "-preset", | ||
| "fast", | ||
| "-crf", | ||
| "22", | ||
| "-c:a", | ||
| "aac", | ||
| after_segment, | ||
| ] | ||
|
|
||
| process = await asyncio.create_subprocess_exec( | ||
| *cmd_after, | ||
| stdout=asyncio.subprocess.PIPE, | ||
| stderr=asyncio.subprocess.PIPE, | ||
| ) | ||
| stdout, stderr = await process.communicate() | ||
|
|
||
| if process.returncode != 0: | ||
| print(f"FFmpeg after segment error: {stderr.decode()}") | ||
|
|
||
| concat_file = tempfile.mktemp(suffix="_concat.txt") | ||
| temp_files.append(concat_file) | ||
|
|
||
| with open(concat_file, "w") as f: | ||
| if ( | ||
| start > 0 | ||
| and os.path.exists(before_segment) | ||
| and os.path.getsize(before_segment) > 0 | ||
| ): | ||
| f.write(f"file '{before_segment}'\n") | ||
| if ( | ||
| os.path.exists(after_segment) | ||
| and os.path.getsize(after_segment) > 0 | ||
| ): | ||
| f.write(f"file '{after_segment}'\n") | ||
|
|
||
| if os.path.exists(concat_file) and os.path.getsize(concat_file) > 0: | ||
| cmd_concat = [ | ||
| "ffmpeg", | ||
| "-y", | ||
| "-f", | ||
| "concat", | ||
| "-safe", | ||
| "0", | ||
| "-i", | ||
| concat_file, | ||
| "-c", | ||
| "copy", | ||
| segment_output, | ||
| ] | ||
|
|
||
| process = await asyncio.create_subprocess_exec( | ||
| *cmd_concat, | ||
| stdout=asyncio.subprocess.PIPE, | ||
| stderr=asyncio.subprocess.PIPE, | ||
| ) | ||
| stdout, stderr = await process.communicate() | ||
|
|
||
| if process.returncode != 0: | ||
| print(f"FFmpeg concat error: {stderr.decode()}") | ||
| else: | ||
| current_input = segment_output | ||
|
|
||
| for file in [before_segment, after_segment, concat_file]: | ||
| try: | ||
| if os.path.exists(file): | ||
| os.unlink(file) | ||
| except: | ||
| pass | ||
| if not current_input.endswith(".webm"): | ||
| final_webm = output_path | ||
| cmd = [ | ||
| "ffmpeg", | ||
| "-y", | ||
| "-i", | ||
| current_input, | ||
| "-c:v", | ||
| "libvpx-vp9", | ||
| "-crf", | ||
| "30", | ||
| "-b:v", | ||
| "0", | ||
| "-c:a", | ||
| "libopus", | ||
| final_webm, | ||
| ] | ||
|
|
||
| process = await asyncio.create_subprocess_exec( | ||
| *cmd, | ||
| stdout=asyncio.subprocess.PIPE, | ||
| stderr=asyncio.subprocess.PIPE, | ||
| ) | ||
| stdout, stderr = await process.communicate() | ||
|
|
||
| if process.returncode != 0: | ||
| print(f"FFmpeg final conversion error: {stderr.decode()}") | ||
| shutil.copy(current_input, final_webm) | ||
|
|
||
| current_input = final_webm | ||
| except Exception as e: | ||
| print(f"Error in process_video_with_ffmpeg: {str(e)}") | ||
| traceback.print_exc() | ||
| return input_path, temp_files |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.