After spending some time in the gophers slack chat, I ended up changing the
fuction to this
func pipeThruFfmpegToMp4(vi *VideoInfo, rw web.ResponseWriter) error {
var ffmpeg *exec.Cmd
ffmpeg = exec.Command(
"ffmpeg",
"-i", "-",
"-i", "pipe:3",
"-c:v", "copy", "-c:a", "copy",
"-preset", "veryfast",
"-metadata", fmt.Sprintf(`title=%s`, vi.GetTitle()),
"-movflags", "frag_keyframe+empty_moov",
"-f", "mp4",
"-")
youtubevideo := exec.Command(YoutubeDLPath, "-c", "-f", fmt.Sprintf(
"%s/bestvideo[ext=mp4]/bestvideo/best", vi.GetFormat()), "--no-cache-dir",
"--restrict-filenames", "--hls-prefer-native", "-o", "-", fmt.Sprintf("%s",
vi.GetVideoUrl()))
fmt.Println(youtubevideo)
youtube := exec.Command(YoutubeDLPath, "-c", "-f",
"bestaudio[ext=m4a]/bestaudio/best", "--no-cache-dir",
"--restrict-filenames", "--hls-prefer-native", "-o", "-", fmt.Sprintf("%s",
vi.GetVideoUrl()))
fmt.Println(youtube)
var ytvbuf, ytbuf, ffbuf bytes.Buffer
youtubevideo.Stderr = &ytvbuf
youtube.Stderr = &ytbuf
ffmpeg.Stderr = &ffbuf
video, err := youtubevideo.StdoutPipe()
if err != nil {
log.Printf("pipeThruFfmpegToMp4: %v\n", err)
return err
}
pipe3, err := youtube.StdoutPipe()
if err != nil {
log.Printf("pipeThruFfmpegToMp4: %v\n", err)
return err
}
ffmpeg.Stdin = video
ffmpeg.ExtraFiles = []*os.File{pipe3.(*os.File)}
ffmpeg.Stdout = rw
// Headers sent, no turning back now
rw.Header().Set("Content-Type", "video/mp4")
rw.Header().Set("Content-Disposition", fmt.Sprintf(
"attachment;filename=\"%s.mp4\"", vi.GetSlug()))
rw.Flush()
ffmpeg.Start()
youtubevideo.Start()
youtube.Start()
ffmpeg.Wait()
youtubevideo.Wait()
youtube.Wait()
// check ytvbuf, ytbuf, ffbuf for stderr errors
if ffbuf.Len() != 0 {
rollbar.Error(rollbar.ERR, err, &rollbar.Field{"stderr", ffbuf.
String()})
log.Printf("pipeThruFfmpegToMp4: %v\n", ffbuf.String())
}
if ytvbuf.Len() != 0 {
rollbar.Error(rollbar.ERR, err, &rollbar.Field{"stderr", ytvbuf.
String()})
log.Printf("pipeThruYouTubevDLToMp4: %v\n", ytvbuf.String())
}
if ytbuf.Len() != 0 {
rollbar.Error(rollbar.ERR, err, &rollbar.Field{"stderr", ytbuf.
String()})
log.Printf("pipeThruYouTubeDLToMp4: %v\n", ytbuf.String())
}
return nil
}
But it still ends up crashing.
On Tuesday, February 4, 2020 at 6:50:32 AM UTC-7, Robert Engels wrote:
>
> When you reassign the file descriptors you need to close the old ones -
> this does not happen automatically. You also need to close the ffmpeg fds.
>
> By not closing the descriptors the pipe structures are remaining in the
> kernel.
>
> That’s my first guess anyway.
>
> On Feb 4, 2020, at 7:21 AM, [email protected] <javascript:> wrote:
>
>
> Hi everyone, I posted this question on StackOverfow here
> <https://stackoverflow.com/questions/60023789/runtime-cgo-pthread-create-failed-resource-temporarily-unavailable>
>
> with a 200 point bounty, but per the git issue I opened here
> <https://github.com/golang/go/issues/37006>, someone suggested I post it
> here as well. I have included at the end of the SO question a gist with
> the entire program. I would greatly appreciate any help
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected] <javascript:>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/457ad5bc-d650-4a44-97e4-3af3ee7eb0a1%40googlegroups.com
>
> <https://groups.google.com/d/msgid/golang-nuts/457ad5bc-d650-4a44-97e4-3af3ee7eb0a1%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/69ce0816-6705-4795-9da2-a79203334cde%40googlegroups.com.