Skip to content

Instantly share code, notes, and snippets.

@Nerixyz
Created July 11, 2020 19:23
Show Gist options
  • Save Nerixyz/411955c5481de6d927bf22cae06cb25a to your computer and use it in GitHub Desktop.
Save Nerixyz/411955c5481de6d927bf22cae06cb25a to your computer and use it in GitHub Desktop.
Chingari Highlights to Video

Description

This is a small script to automatically scrape the tranding section of the indian TikTok alternative Chingari. It uses ffmpeg to transcode and concatenate videos. As a performance optimization, cuvid and nvenc are used to offload work to the GPU which results in 5 to 10 times higher transcoding/concatenation speeds.

Required

  • ffmpeg (built with nvenc and cuvid support
  • Graphics Card supporting nvenc and cuvid
New-Item -ItemType Directory -Force 'temp' | Out-Null;
$videos = Invoke-RestMethod 'https://api.chingari.io/post/trending-video-update' -Method 'POST' -Headers @{'User-Agent' = 'Okayge' } -Body "limit=100&skip=$(Get-Random 100000)&language=english&userId=$(Get-Random 100000000000000)" |
Select-Object -ExpandProperty data |
Select-Object -ExpandProperty TrendingFeedData;
$concatFile = @($videos | ForEach-Object { "file 'temp/$($_._id).mp4" }) -join "`r";
$i = 0;
$commands = $videos | ForEach-Object {
"ffmpeg -loglevel warning -y -c:v h264_cuvid -i `"https://media.chingari.io/apipublic$($_.mediaLocation.path)`" -c:a aac -c:v h264_nvenc -r 30 temp/`"$($_._id).mp4`""
};
$commands | ForEach-Object {
Write-Progress "Downloading and Transcoding" -Id 1 -PercentComplete ((($i++) / $videos.Count) * 100);
Invoke-Expression $_
};
Write-Progress "Done" -Id 1 -Completed
Write-Output "Concatenating";
$concatFile | ffmpeg -hwaccel_output_format cuda -loglevel warning -y -auto_convert 1 -f concat -safe 0 -protocol_whitelist file,pipe -i pipe:0 -vf scale=-1:1080 -c:v h264_nvenc -c:a aac "Chingari.mp4";
Write-Output "Removing Files";
Remove-Item 'temp' -Recurse -Force | Out-Null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment