Using multi-thread to convert video

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stone1126
    New Member
    • Jun 2007
    • 3

    Using multi-thread to convert video

    Dear All

    I am a beginner using python. My boss asks me to write a Python script to call ffmpeg to converter video to flash using multi-thread. the program uses database to be the queue and the thread must be reused after each tread completed convertion.
    the program has been completed but "Reuse" part. Anyone has any idea how to write that part

    Sean
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by stone1126
    Dear All

    I am a beginner using python. My boss asks me to write a Python script to call ffmpeg to converter video to flash using multi-thread. the program uses database to be the queue and the thread must be reused after each tread completed convertion.
    the program has been completed but "Reuse" part. Anyone has any idea how to write that part

    Sean
    The most common meaning for the term "Reuse" is code reuse. Object reuse is something that is not dificult because objects hang around in memory. On the third hand, thread reuse could be achieved but it would be smarter to reuse the code that creates a single thread each time you need a new thread (IMHO).

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      I did something quite similar, I had two threads going. Both of these threads were basically while loops, checking the state of each other to determine if they should continue running. Inside the loop one would perform database queries, and build a queue of data to be handled, and the other one would process the queue. This method will allow you to do all of your ffmpeg conversions in one thread, saving a lot of processing (and headache).

      Comment

      • stone1126
        New Member
        • Jun 2007
        • 3

        #4
        Originally posted by Motoma
        I did something quite similar, I had two threads going. Both of these threads were basically while loops, checking the state of each other to determine if they should continue running. Inside the loop one would perform database queries, and build a queue of data to be handled, and the other one would process the queue. This method will allow you to do all of your ffmpeg conversions in one thread, saving a lot of processing (and headache).
        Dear Motoma
        I have a silly question that " while loops" needs to be coded in the thread`s "Run()" function or Main "__name__=="__m ain__":" function

        thanks a lot again

        by the way, if its not troubling you, can you post this code architecture for the beginner like me

        Comment

        • Motoma
          Recognized Expert Specialist
          • Jan 2007
          • 3236

          #5
          Originally posted by stone1126
          Dear Motoma
          I have a silly question that " while loops" needs to be coded in the thread`s "Run()" function or Main "__name__=="__m ain__":" function

          thanks a lot again

          by the way, if its not troubling you, can you post this code architecture for the beginner like me
          I don't have the exact code kicking around, but I will whip up some fresh pseudocode for you!

          [code=python]
          # fresh squeezed python code, straight from the source!

          import DataHandler #Name says it all.
          import LibDB # Database Abstraction Layer
          import threading
          import Queue

          class Parser:
          def __init__(self):
          self.db = mysqldal()
          self.db.connect ("localhost" , "database", "username", "password")
          self.qData = Queue.Queue(0)
          self.dh = dataHandler()

          def DoQuery(self):
          self.running = True
          self.min = 0
          numresults = -1
          while self.running and numresults != 0:
          numresults = self.db.query(" SELECT * FROM myDataTable LIMIT " + self.min + ", 50")
          self.db.populat eQueue(self.qDa ta)
          self.min = self.min + 50
          self.running = False

          def ParseData(self) :
          while self.Running or self.qData.empt y == False:
          self.dh.HandleD ata(self.qData. get(false))

          def Begin(self):
          threading.Threa d(none, self.DoQuery).s tart()
          self.ParseData( )

          dItem = Parser()
          dItem.Begin()
          [/code]

          Hope this gives you an idea, I am quite sure none of this will work :P

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by stone1126
            Dear Motoma
            I have a silly question that " while loops" needs to be coded in the thread`s "Run()" function or Main "__name__=="__m ain__":" function

            thanks a lot again

            by the way, if its not troubling you, can you post this code architecture for the beginner like me
            To try to further explain:
            Originally posted by Python Manuals - Threading:Threa d Objects
            run( )

            Method representing the thread's activity.
            You may override this method in a subclass. The standard run() method invokes the callable object passed to the object's constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
            So: When an instance of the base class is created, it is given a "callable object" (that's the function that you want run in this thread). The base class's run() calls your function. When your function returns (reaches its end), run() will also return.
            If you are creating a subclass of Threading.threa d, then you would define your function as an override of run() (which gets called by the base class's start() function.

            Hope that helps clear things up a bit.

            Comment

            • stone1126
              New Member
              • Jun 2007
              • 3

              #7
              Dear Motoma and Bartonc

              Thank you guys for this great replies. These help a lot
              Thanks again

              Sean

              Comment

              • bartonc
                Recognized Expert Expert
                • Sep 2006
                • 6478

                #8
                Originally posted by stone1126
                Dear Motoma and Bartonc

                Thank you guys for this great replies. These help a lot
                Thanks again

                Sean
                (Another satified customer.) You are welcome. I have the feeling that TheScripts.com is going to be around a good long time and your partisipation helps us grow. So, thank you. Drop on in any ol' time.

                Comment

                Working...