diff --git a/docker/tiktok/Dockerfile b/docker/tiktok/Dockerfile index 0486e8d..6127a41 100644 --- a/docker/tiktok/Dockerfile +++ b/docker/tiktok/Dockerfile @@ -8,6 +8,7 @@ RUN pip3 install numpy pandas browser_cookie3 ipdb asgiref RUN python3 -m playwright install-deps RUN python3 -m playwright install RUN pip3 install tqdm +RUN apt-get install -yy ffmpeg WORKDIR /app diff --git a/python/tasks/tiktok/__init__.py b/python/tasks/tiktok/__init__.py index 4cb3451..2603852 100644 --- a/python/tasks/tiktok/__init__.py +++ b/python/tasks/tiktok/__init__.py @@ -259,3 +259,43 @@ def tiktok_videos_fetch( stats['skipped'] += 1 return stats + +def tiktok_videos_process(meta: Iterable[dict[str, Any]]) -> dict[str, Any]: + import tqdm + stats = dict( + saved=0, + total=0, + skipped=0, + error=0, + ) + + for o in tqdm.tqdm(meta): + stats['total'] += 1 + + path = os.path.join( + o['result_dir'], + o['fname'], + ) + + try: + path_parts = os.path.splitext(path) + + processed_path = path_parts[0] + '-proc' + path_parts[1] + + if not os.path.exists(path) or os.path.exists(processed_path): + stats['skipped'] += 1 + continue + + subprocess.check_call([ + 'ffmpeg','-i', path, '-filter:v', 'setpts=0.5*PTS', processed_path, + ]) + stats['saved'] += 1 + except KeyboardInterrupt: + break + except: + logger.error(json.dumps(dict( + msg=traceback.format_exc(), + ))) + stats['error'] += 1 + + return stats