Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Segmentation fault when starting multithread transcoding #219

@Deformer

Description

@Deformer

Describe the bug
Starting multithread transcoding

To Reproduce
After running command:
python SampleTranscodeMiltiThread.py 0 20
printing in console:

Decoding on GPU 0
Encoding on GPU 0
Decoding on GPU 0
Encoding on GPU 0
Decoding on GPU 0
Encoding on GPU 0
Decoding on GPU 0
Encoding on GPU 0
Decoding on GPU 0
Encoding on GPU 0
Decoding on GPU 0
Encoding on GPU 0
Decoding on GPU 0
Encoding on GPU 0
Decoding on GPU 0
Encoding on GPU 0
Decoding on GPU 0
Encoding on GPU 0
Decoding on GPU 0
Encoding on GPU 0
Decoding on GPU 0
Encoding on GPU 0
Decoding on GPU 0
Encoding on GPU 0
Decoding on GPU 0
Encoding on GPU 0
Decoding on GPU 0
Encoding on GPU 0
Segmentation fault (core dumped)

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Linux
  • Nvidia driver version
  • CUDA Version: Cuda compilation tools, release 11.3, V11.3.109
  • Video Codec SDK Version: 11.0.10
  • Python Version: 3.8.5

Additional context
SampleTranscodeMiltiThread.py code:

import sys
import os

if os.name == 'nt':
    # Add CUDA_PATH env variable
    cuda_path = os.environ["CUDA_PATH"]
    if cuda_path:
        os.add_dll_directory(cuda_path)
    else:
        print("CUDA_PATH environment variable is not set.", file = sys.stderr)
        print("Can't set CUDA DLLs search path.", file = sys.stderr)
        exit(1)

    # Add PATH as well for minor CUDA releases
    sys_path = os.environ["PATH"]
    if sys_path:
        paths = sys_path.split(';')
        for path in paths:
            if os.path.isdir(path):
                os.add_dll_directory(path)
    else:
        print("PATH environment variable is not set.", file = sys.stderr)
        exit(1)

import PyNvCodec as nvc
from enum import Enum
import time
import numpy as np
from threading import Thread


class Transcoder(Thread):
    def __init__(self, n, gpuID):
        Thread.__init__(self)
        self.demuxer = nvc.PyFFmpegDemuxer('./%d.mp4' % n)
        self.decoder = nvc.PyNvDecoder(self.demuxer.Width(), self.demuxer.Height(), self.demuxer.Format(), self.demuxer.Codec(), gpuID)
        self.encoder = nvc.PyNvEncoder(
            {'preset': 'll_hp', 'codec': 'h264', 'vsync': '0', 'profile': 'high',
             's': '720x1280', 'bitrate': '2700K'}, gpuID)

    def run(self):
        inputPacket = np.ndarray(shape=(0), dtype=np.uint8)
        encodedFrame = np.ndarray(shape=(0), dtype=np.uint8)
        while True:
            if not self.demuxer.DemuxSinglePacket(inputPacket):
                break
            surface = self.decoder.DecodeSurfaceFromPacket(inputPacket)
            if surface.Empty():
                continue
            if not self.encoder.EncodeSingleSurface(surface, encodedFrame, sync=True):
                break
        print("Transcoding finished")

if __name__ == "__main__":
    if(len(sys.argv) < 2):
        print("Provide gpuID an N of threads")
        exit(1)

    gpuID = int(sys.argv[1])
    n = 0
    if sys.argv[2]:
        n = int(sys.argv[2])

    threads = []
    for i in range(n):
        th = Transcoder(n, gpuID)
        th.start()
        threads.append(th)
    for th in threads:
        th.join()

    exit(0)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions