Skip to content
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

Show FFMPEG Postprocessing Progress #1947

Closed
wants to merge 4 commits into from
Closed

Conversation

raggs1561
Copy link

@raggs1561 raggs1561 commented Dec 10, 2021

Please follow the guide below

  • You will be asked some questions, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your pull request (like that [x])
  • Use Preview tab to see how your pull request will actually look like

Before submitting a pull request make sure you have:

In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under Unlicense. Check one of the following options:

  • I am the original author of this code and I am willing to release it under Unlicense
  • I am not the original author of this code but it is in public domain or released under Unlicense (provide reliable evidence)

What is the purpose of your pull request?

  • Bug fix
  • Improvement
  • New extractor
  • New feature

Description of your pull request and other information

Explanation of your pull request in arbitrary form goes here. Please make sure the description explains the purpose and effect of your pull request and is worded well enough to be understood. Provide as much context and examples as possible.

FFMPEG uses same _hook_progress to track postprocessing progress.

Should close #1720

Ex: youtube downloading issues. I didn't do any changes to the youtube downloader side of things apart from changes that were already working in another commit.
@raggs1561 raggs1561 closed this Dec 10, 2021
@raggs1561 raggs1561 reopened this Dec 10, 2021
Forgot to run flake8 on the recent one. Fixed spacing.
@pukkandan pukkandan added the enhancement New feature or request label Dec 10, 2021
Lesmiscore added a commit to ytdl-patched/ytdl-patched that referenced this pull request Dec 14, 2021
@jmraker
Copy link

jmraker commented Dec 28, 2021

I opened #1720 in hopes of getting a progress for the sponsorblock ad removing code. Since ffmpeg is used in a way to make ffmpeg quick but create somewhat messy/invalid videos I change the concat code to make it re-encode the video instead of a copy which makes ffmpeg take a lot more time.

I downloaded the zip https://github.com/raggs1561/yt-dlp/archive/refs/heads/master.zip

And got this error:

pi@pi4:~/tmp/yt/yt-dlp-master $ bash ./yt-dlp.sh -v --sponsorblock-remove sponsor,outro,selfpromo,interaction  -f 22 KWKRYLQtdS0
[debug] Command-line config: ['-v', '--sponsorblock-remove', 'sponsor,outro,selfpromo,interaction', '-f', '22', 'KWKRYLQtdS0']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, err UTF-8, pref UTF-8
[debug] yt-dlp version 2021.12.01 [91f071af6] (source)
[debug] Lazy loading extractors is disabled
[debug] Plugins: ['SamplePluginIE', 'SamplePluginPP']
[debug] Python version 3.7.3 (CPython 32bit) - Linux-5.10.17-v7l+-armv7l-with-debian-10.9
[debug] exe versions: ffmpeg 4.1.8-0, ffprobe 4.1.8-0
[debug] Optional libraries: Cryptodome, keyring, mutagen, sqlite, websockets
[debug] Proxy map: {'no': 'localhost,127.0.0.1', 'https': 'http://192.168.1.44:8118', 'http': 'http://192.168.1.44:8118'}
[debug] [youtube] Extracting URL: KWKRYLQtdS0
[youtube] KWKRYLQtdS0: Downloading webpage
[youtube] KWKRYLQtdS0: Downloading android player API JSON
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, codec:vp9.2, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), acodec, lang, proto, filesize, fs_approx, tbr, vbr, abr, asr, vext, aext, hasaud, id
[SponsorBlock] Fetching SponsorBlock segments
[debug] SponsorBlock query: https://sponsor.ajay.app/api/skipSegments/354d?service=YouTube&categories=%5B%22interaction%22%2C+%22outro%22%2C+%22sponsor%22%2C+%22selfpromo%22%5D
[SponsorBlock] Found 2 segments in the SponsorBlock database
[info] KWKRYLQtdS0: Downloading 1 format(s): 22
[debug] Invoking downloader on "https://rr5---sn-vgqsrnls.googlevideo.com/videoplayback?expire=1640672756&ei=lFnKYexGjKiKvg-JsYvwDw&ip=172.86.15.149&id=o-AEkZbfIUqtgUSdPGOZ6Q_DP0EJnu5KmaCIyz1cxVQlsb&itag=22&source=youtube&requiressl=yes&mh=oS&mm=31%2C29&mn=sn-vgqsrnls%2Csn-vgqsknsk&ms=au%2Crdu&mv=m&mvi=5&pl=22&initcwndbps=1103750&vprv=1&mime=video%2Fmp4&cnr=14&ratebypass=yes&dur=836.150&lmt=1640643581468675&mt=1640650871&fvip=5&fexp=24001373%2C24007246&c=ANDROID&txp=5532434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Ccnr%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAKXfRg86byvEEsvatj2eZvKXoF0KrpnrwA8BHhbnnEnDAiEA1MLZQlwtcGOliqfThrakPvhp7YKhgCrR91Zl-SM6qtU%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhAODXWYs79vWkiIErCOeJ4zDpq1iT93KMJf2t4KxP3sxeAiEAvMa9XumaG57-HgtffWEjAwtbF6sSQq6PcojJQZqtldM%3D"
[download] Destination: I Spent $200 on WEIRD Nintendo Switch eShop Games! - ConnerTheWaffle [KWKRYLQtdS0].mp4
[download] 100% of 65.81MiB in 01:49                                      
[debug] ffprobe command line: ffprobe -hide_banner -show_format -show_streams -print_format json 'file:I Spent $200 on WEIRD Nintendo Switch eShop Games! - ConnerTheWaffle [KWKRYLQtdS0].mp4'
[ModifyChapters] Removing chapters from I Spent $200 on WEIRD Nintendo Switch eShop Games! - ConnerTheWaffle [KWKRYLQtdS0].mp4
[debug] Writing concat spec to I Spent $200 on WEIRD Nintendo Switch eShop Games! - ConnerTheWaffle [KWKRYLQtdS0].temp.mp4.concat
ERROR: real_run_ffmpeg() missing 1 required keyword-only argument: 'information'
Traceback (most recent call last):
  File "/home/pi/tmp/yt/yt-dlp-master/yt_dlp/YoutubeDL.py", line 1331, in wrapper
    return func(self, *args, **kwargs)
  File "/home/pi/tmp/yt/yt-dlp-master/yt_dlp/YoutubeDL.py", line 1414, in __extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "/home/pi/tmp/yt/yt-dlp-master/yt_dlp/YoutubeDL.py", line 1464, in process_ie_result
    ie_result = self.process_video_result(ie_result, download=download)
  File "/home/pi/tmp/yt/yt-dlp-master/yt_dlp/YoutubeDL.py", line 2508, in process_video_result
    self.process_info(new_info)
  File "/home/pi/tmp/yt/yt-dlp-master/yt_dlp/YoutubeDL.py", line 3003, in process_info
    info_dict = self.post_process(dl_filename, info_dict, files_to_move)
  File "/home/pi/tmp/yt/yt-dlp-master/yt_dlp/YoutubeDL.py", line 3167, in post_process
    info = self.run_pp(pp, info)
  File "/home/pi/tmp/yt/yt-dlp-master/yt_dlp/YoutubeDL.py", line 3110, in run_pp
    files_to_delete, infodict = pp.run(infodict)
  File "/home/pi/tmp/yt/yt-dlp-master/yt_dlp/postprocessor/common.py", line 23, in run
    ret = func(self, info, *args, **kwargs)
  File "/home/pi/tmp/yt/yt-dlp-master/yt_dlp/postprocessor/common.py", line 118, in wrapper
    return func(self, info)
  File "/home/pi/tmp/yt/yt-dlp-master/yt_dlp/postprocessor/modify_chapters.py", line 64, in run
    in_out_files = [remove_chapters(info['filepath'], False)]
  File "/home/pi/tmp/yt/yt-dlp-master/yt_dlp/postprocessor/modify_chapters.py", line 62, in remove_chapters
    return file, self.remove_chapters(file, cuts, concat_opts, self._force_keyframes and not is_sub)
  File "/home/pi/tmp/yt/yt-dlp-master/yt_dlp/postprocessor/modify_chapters.py", line 320, in remove_chapters
    self.concat_files([in_file] * len(concat_opts), out_file, concat_opts)
  File "/home/pi/tmp/yt/yt-dlp-master/yt_dlp/postprocessor/ffmpeg.py", line 494, in concat_files
    [(out_file, out_flags)])
TypeError: real_run_ffmpeg() missing 1 required keyword-only argument: 'information'

pi@pi4:~/tmp/yt/yt-dlp-master $ 

Copy link

@Kenshin9977 Kenshin9977 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is based at 90% on #1133. Though you say it in your first commit comment it's stated in your PR that you're the original author of this code. There is few ways to improve the clarity and the maintainability of this PR

Comment on lines +594 to +595
reg1 = re.match(r"((?P<H>\d\d?):)?((?P<M>\d\d?):)?(?P<S>\d\d?)(\.(?P<f>\d{1,3}))?", time_string)
reg2 = re.match(r"\d+(?P<U>s|ms|us)", time_string)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear var name for reg1 and reg2

Suggested change
reg1 = re.match(r"((?P<H>\d\d?):)?((?P<M>\d\d?):)?(?P<S>\d\d?)(\.(?P<f>\d{1,3}))?", time_string)
reg2 = re.match(r"\d+(?P<U>s|ms|us)", time_string)
hms_parsed = re.match(r"((?P<H>\d\d?):)?((?P<M>\d\d?):)?(?P<S>\d\d?)(\.(?P<f>\d{1,3}))?", time_string)
smu_parsed = re.match(r"\d+(?P<U>s|ms|us)", time_string)



def compute_prefix(match):
res = int(match.group('E'))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear var name

Suggested change
res = int(match.group('E'))
no_prefix_int = int(match.group('E'))

Comment on lines +285 to +316
def parse_ffmpeg_time_string(time_string):
time = 0
reg1 = re.match(r"((?P<H>\d\d?):)?((?P<M>\d\d?):)?(?P<S>\d\d?)(\.(?P<f>\d{1,3}))?", time_string)
reg2 = re.match(r"\d+(?P<U>s|ms|us)", time_string)
if reg1:
if reg1.group('H') is not None:
time += 3600 * int(reg1.group('H'))
if reg1.group('M') is not None:
time += 60 * int(reg1.group('M'))
time += int(reg1.group('S'))
if reg1.group('f') is not None:
time += int(reg1.group('f')) / 1_000
elif reg2:
time = int(reg2.group('U'))
if reg2.group('U') == 'ms':
time /= 1_000
elif reg2.group('U') == 'us':
time /= 1_000_000
return time

def compute_prefix(match):
res = int(match.group('E'))
if match.group('f') is not None:
res += int(match.group('f'))
if match.group('U') is not None:
if match.group('U') == 'g':
res *= 1_000_000_000
elif match.group('U') == 'm':
res *= 1_000_000
elif match.group('U') == 'k':
res *= 1_000
return res

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeat of the functions already present in yt_dlp/downloader/external.py.
Don't repeat yourself otherwise the day we'll have to make some changes it will have to be repeated within both files even though those are the exact same functions.

'status': 'finished',
'processed_bytes': total_filesize
})
self._hook_progress(status, information)
Copy link

@Kenshin9977 Kenshin9977 Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark applies. There is a way to factorize this chunk of code

res *= 1_000
return res

def real_run_ffmpeg(self, input_path_opts, output_path_opts, *, expected_retcodes=(0,), information):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

information isn't defined anywhere. It can't work as is

'status': 'finished',
'processed_bytes': total_filesize
})
self._hook_progress(status, information)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._hook_progress doesn't exist

@pukkandan
Copy link
Member

Superseded by #2475

@pukkandan pukkandan closed this Mar 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge enhancement New feature or request
Projects
Status: progress reporting
Development

Successfully merging this pull request may close these issues.

Showing ffmpeg postprocessing progress
4 participants