Skip to content

Instantly share code, notes, and snippets.

@FarisHijazi
Last active October 18, 2022 16:25
Show Gist options
  • Save FarisHijazi/eff7a7979440faa84a63657e085ec504 to your computer and use it in GitHub Desktop.
Save FarisHijazi/eff7a7979440faa84a63657e085ec504 to your computer and use it in GitHub Desktop.
detect and remove black parts of a video using ffmpeg `trim`.
print("""
this file is has migrated to https://github.com/FarisHijazi/deblack/blob/master/deblack.py
Please go head over to the repository and contribute to the project
""")
@AurelieEspoir
Copy link

yes, thats actually the way to go, or cut it first in segments then run all the segments . thanks a lot for your reply!

@Stanley-Michael
Copy link

Stanley-Michael commented Oct 15, 2022

Hey, thanks for this. I'm recording things with Nvidia shadow play and seem to get a lot of black flickering. I tried this solution however and I get no error message but the output file does not appear to be getting written. Any help would be greatly appreciated.:

ffprobe_cmd: ffprobe -f lavfi -i "movie=vid1.mp4,blackdetect[out0]" -show_entries tags=lavfi.black_start,lavfi.black_end -of default=nw=1 -v quiet
ffmpeg -i "vid1.mp4" -y -filter_complex "[0:v]trim=start=0:end=0.0333556,setpts=PTS-STARTPTS,format=yuv420p[0v]; [0:a]atrim=start=0:end=0.0333556,asetpts=PTS-STARTPTS[0a]; [0:v]trim=start=0.0662667:end=0.100756,setpts=PTS-
............
[671a][672v][672a][673v][673a][674v][674a][675v][675a][676v][676a][677v][677a][678v][678a][679v][679a][680v][680a][681v][681a][682v][682a][683v][683a][684v][684a][685v][685a][686v][686a][687v][687a][688v][688a][689v][689a][690v][690a][691v][691a][692v][692a][693v][693a][694v][694a][695v][695a][696v][696a][697v][697a][698v][698a][699v][699a][700v][700a][701v][701a][702v][702a][703v][703a][704v][704a][705v][705a][706v][706a][707v][707a][708v][708a][709v][709a][710v][710a][711v][711a][712v][712a][713v][713a][714v][714a][715v][715a][716v][716a][717v][717a][718v][718a][719v][719a]concat=n=720:v=1:a=1[outv][outa]"
-map [outv] -map [outa] "vid1.out.mp4"

@FarisHijazi
Copy link
Author

FarisHijazi commented Oct 18, 2022

since so many people are using this, I created an entire repository based around this https://github.com/FarisHijazi/deblack, I haven't had much time to go over these issues, but I plan to do that in the future

Please go ahead and post your issues there and also maybe star the repository

@combs
Copy link

combs commented Oct 18, 2022

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment