By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,929 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,929 IT Pros & Developers. It's quick & easy.

Using multi-thread to convert video

P: 3
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
Jun 1 '07 #1
Share this Question
Share on Google+
7 Replies


bartonc
Expert 5K+
P: 6,596
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).
Jun 1 '07 #2

Motoma
Expert 2.5K+
P: 3,235
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).
Jun 1 '07 #3

P: 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).
Dear Motoma
I have a silly question that " while loops" needs to be coded in the thread`s "Run()" function or Main "__name__=="__main__":" function

thanks a lot again

by the way, if its not troubling you, can you post this code architecture for the beginner like me
Jun 5 '07 #4

Motoma
Expert 2.5K+
P: 3,235
Dear Motoma
I have a silly question that " while loops" needs to be coded in the thread`s "Run()" function or Main "__name__=="__main__":" 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!

Expand|Select|Wrap|Line Numbers
  1. # fresh squeezed python code, straight from the source!
  2.  
  3. import DataHandler #Name says it all.
  4. import LibDB     # Database Abstraction Layer
  5. import threading
  6. import Queue
  7.  
  8. class Parser:
  9.     def __init__(self):
  10.         self.db = mysqldal()
  11.         self.db.connect("localhost", "database", "username", "password")
  12.         self.qData = Queue.Queue(0)
  13.         self.dh = dataHandler()
  14.  
  15.     def DoQuery(self):
  16.         self.running = True
  17.         self.min = 0
  18.         numresults = -1
  19.         while self.running and numresults != 0:
  20.             numresults = self.db.query("SELECT * FROM myDataTable LIMIT " + self.min + ", 50")
  21.             self.db.populateQueue(self.qData)
  22.             self.min = self.min + 50
  23.         self.running = False
  24.  
  25.     def ParseData(self):
  26.         while self.Running or self.qData.empty == False:
  27.             self.dh.HandleData(self.qData.get(false))
  28.  
  29.     def Begin(self):
  30.         threading.Thread(none, self.DoQuery).start()
  31.         self.ParseData()
  32.  
  33. dItem = Parser()
  34. dItem.Begin()
  35.  
Hope this gives you an idea, I am quite sure none of this will work :P
Jun 5 '07 #5

bartonc
Expert 5K+
P: 6,596
Dear Motoma
I have a silly question that " while loops" needs to be coded in the thread`s "Run()" function or Main "__name__=="__main__":" 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:
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.thread, 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.
Jun 5 '07 #6

P: 3
Dear Motoma and Bartonc

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

Sean
Jun 7 '07 #7

bartonc
Expert 5K+
P: 6,596
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.
Jun 7 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.