The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ragdog on February 18, 2008, 08:10:33 AM

Title: calc Duration:
Post by: ragdog on February 18, 2008, 08:10:33 AM
   
Hi

I would like ffmeg  into my program now calculate the progress  status
I found only this source  can your help me this translate in masm32
Duration: 00:03:30.3, start: 0.000000, bitrate: 64 kb/s

the original source found here http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/


def execute_ffmpeg(command)
  progress = nil
  Open3.popen3(command) do |pipe|
    pipe.each("\r") do |line|
      if line =~ /Duration: (\d{2}):(\d{2}):(\d{2}).(\d{1})/
        duration = (($1.to_i * 60 + $2.to_i) * 60 + $3.to_i) * 10 + $4.to_i
      end
      if line =~ /time=(\d+).(\d+)/
        if not duration.nil? and duration != 0
          p = ($1.to_i * 10 + $2.to_i) * 100 / duration
        else
          p = 0
        end
        p = 100 if p > 100
        if progress != p
          progress = p
          print "PROGRESS: #{progress}\n"
          $defout.flush
        end
      end
    end
  end
  raise MediaFormatException if $?.exitstatus != 0
end


greets
ragdog
Title: Re: calc Duration:
Post by: ragdog on February 18, 2008, 07:54:23 PM
My problem is solved as far as to the calculation

calc 00:03:30.3 in millisecond (210.4)
can your help me please

greets
Title: Re: calc Duration:
Post by: Tedd on February 18, 2008, 08:17:41 PM
00*(60*60) + 03*(60) + 30.3 = 210.3
Title: Re: calc Duration:
Post by: ragdog on February 18, 2008, 08:27:22 PM
thanks!! i how to do this!

I just do not know how I should be solved in masm32


H = 00
    M = 3
    S = 303
    mov eax, H*(60*60) + M*(60) + S


   invoke wsprintf,addr hBuffer,CTEXT ("%02d"),eax
invoke MessageBox,0,addr hBuffer,0,MB_OK


sorry for my english
Title: Re: calc Duration:
Post by: Tedd on February 19, 2008, 11:59:57 AM
Okay, so you'll actually want the time in milliseconds, rather than seconds, so it's 210300 (so you don't need to play with decimal fractions.)

msec = H*(60*60*1000) + M*(60*1000) + S*1000 + ms = (  (H*60 + M)*60 + S  )*1000 + ms

Remember the MUL instruction?

I'll start you off..

mov eax,H
mov ecx,60
mul ecx        ;eax = H*60
add eax,M      ;eax = H*60 + M
mul ecx        ;eax = (H*60 + M)*60
    :
    :
Title: Re: calc Duration:
Post by: ragdog on February 19, 2008, 04:38:20 PM
thanks for your help

here is my source


Time2Ms proc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      h dd 0
      m dd 0
      s dd 0
   
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
;00:03:30.3
;00*(60*60) + 03*(60) + 30.3 = 210.3
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    H = 0
    M = 03
    S = 30
   
    xor ebx, ebx
    xor eax, eax
    xor edx, edx
   
    mov edx, 60*60
    mov eax, H 
    mul edx     
   push ebx
    mov ebx,eax
   
   
    mov edx, 60
    mov eax, M   
    mul edx       
   push eax
    add ebx,eax
    add ebx,S
   
invoke wsprintf,addr hBuffer,CTEXT ("%02d"),ebx
    pop eax
    pop ebx
invoke MessageBox,0,addr hBuffer,0,MB_OK
ret
Time2Ms endp


   
Works well with the comma if parsing the time (00:03:30.3)

greets
ragdog