roju/tiktok-live-recorder

A concatenation error occurs with -out_dir argument

Marksmanship256 opened this issue · 1 comments

Description:

When an argument contains the -out_dir property, a concatenation error occurs. The video is successfully written to the designated folder, and a concat.txt file is created. However, an error arises during the video concatenation process.

Example
python ttlr.py -user Username -ffmpeg -combine -store_logs -out_dir v

Error result

INFO - Concatenating 4 video files
ERROR - ffmpeg error (see stderr output for detail)
Spoiler error screenshot

2023-08-25_210426

Minor request: (Logs Enhancement)

Additionally, if possible, please consider adding the username of the user to the logs for better clarity.

For instance:

03:39:10 - INFO - Stream lagging User1 
03:39:22 - INFO - Started recording User1 
03:41:03 - INFO - Stream lagging User2
03:41:12 - INFO - Started recording User2 
03:42:36 - INFO - Stream lagging User3
03:42:44 - INFO - Started recording User3
03:47:22 - INFO - Stream lagging User1 

Observation:

When reviewing the logs, after recording multiple broadcasts concurrently, the log entries can become intermixed, making it unclear which broadcast was experiencing lag at any given time.

Through some experimentation, it seems I've cracked the issue. The problem stemmed from incorrect pathways. The FFmpeg was referring to the concat.txt file within the video folder, and within that concat.txt file were also paths to the folder, causing the video folder to be duplicated.

My solution was straightforward: I created a text file right at the project's root. This workaround has proven effective for me.

    def finish_recording(self):
        """Combine multiple videos into one if needed"""
        try:
            if self.combine and len(self.video_list) > 1:
                current_date = time.strftime('%Y.%m.%d_%H-%M-%S', time.localtime())
                self.out_file = f'{self.out_dir}TK_{self.user}_{current_date}_concat.mp4'
                logging.info(f'Concatenating {len(self.video_list)} video files')
                with open(f'concat.txt', 'w') as file:
                    for v in self.video_list: file.write(f"file '{v}'\n")
                (ffmpeg.input(f'concat.txt', **{'f': 'concat'}, **{'safe': 0})
                 .output(self.out_file, c='copy')
                 .run(quiet=True))
                os.remove(f'concat.txt')
                for v in self.video_list: os.remove(v)
            if os.path.isfile(self.out_file):
                logging.info(f'Recording finished: {self.out_file}\n')
        except Exception as ex:
            logging.error(ex)
        self.video_list = []
        self.out_file = None