yt-dlp in combination with ffmpeg returns wrong PID
See original GitHub issueChecklist
- I’m asking a question and not reporting a bug/feature request
- I’ve looked through the README
- I’ve read the guidelines for opening an issue
- I’ve searched the bugtracker for similar questions including closed ones
Question
Hi there,
we have a problem with the returned PID’s from ffmpeg in combination with yt-dlp. We need a valid PID from ffmpeg to terminate the process via timer later.
Test the following little Python program and then you will see the problem:
#!/usr/bin/env python3
import subprocess
import time
link = "https://fashiontv-fashiontv-4-de.samsung.wurl.com/manifest/playlist.m3u8"
cmd_string = 'ffmpeg -i $(yt-dlp -g "' + link + '") -c:v copy -c:a copy "out.ts" 2> /dev/null'
#cmd_string = 'ffmpeg -i $(youtube-dl -g "' + link + '") -c:v copy -c:a copy "out.ts" 2> /dev/null'
for z in range(3):
try:
last_pid = int(subprocess.check_output(["pidof", "-s", "ffmpeg"]))
except:
last_pid = 0
subprocess.Popen(cmd_string, shell=True)
print("\n0.00 - 000 - {:d}".format(last_pid))
start = time.time()
new_pid = 0
for x in range(700):
try:
new_pid = int(subprocess.check_output(["pidof", "-s", "ffmpeg"]))
except:
pass
if not new_pid == last_pid:
print("{:.2f} - {:3d} - {:d}".format(time.time()-start, x, new_pid))
last_pid = new_pid
print("{:.2f} - {:3d} - {:d}".format(time.time()-start, x, new_pid))
print(subprocess.check_output(["pidof", "ffmpeg"]))
subprocess.Popen('killall ffmpeg', shell=True)
You can see that after about 0.5 seconds it returns an wrong PID, then it switched back to the old one and after some time the correct PID is returned. This is not how we can reliably determine a valid PID. If you try the same with youtube-dl everything is fine. What is it?
Thanks for your effort
Verbose log
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
FFMPEG: Too many packets buffered for output stream 0:1
I disabled the audio stream on my camera and it works fine without this option. In manual I read about ffmpeg that will...
Read more >Modules on CPAN alphabetically
The list contains modules distribution files on CPAN for modules that are not included in the perl standard distribution but are included in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The problem is that you have poor code. It’s just as ill-advised to do the same in production:
https://github.com/sc44/Stream-Recorder/blob/34dab4113c14860da33272d535a2985e4c9f4b87/srecorder.py#L927-L933
https://github.com/sc44/Stream-Recorder/blob/34dab4113c14860da33272d535a2985e4c9f4b87/srecorder.py#L1003
subprocess.Popen
has apid
attribute. Use that one and never touch any other PID.This is some extremely poor code.
pidof
andkillall
are tools for sysadmins, not programmers.