* *

Coding

User

Welcome, Guest. Please login or register.
May 24, 2013, 06:43:42 AM

Login with username, password and session length

Menu

Stats

Members
  • Total Members: 491
  • Latest: TOPMO3
Stats
  • Total Posts: 12061
  • Total Topics: 1688
  • Online Today: 94
  • Online Ever: 150
  • (September 26, 2012, 02:29:19 PM)
Users Online
Users: 1
Guests: 50
Spiders: 2
Total: 53
Google
Baidu

Recent Topics

Author Topic: Viewing AVI files  (Read 1218 times)

0 Members and 2 Guests are viewing this topic.

Offline rosslcs

  • Newbie
  • *
  • Posts: 30
  • Bananas: 0
Viewing AVI files
« on: July 05, 2012, 05:35:50 AM »
I am having some problems using the following program when viewing AVI files.

Some AVI files play Ok while other files are displayed speeded up.

REM an example of using Windows MCI to play and control media files.
REM Original code by Paul Turley badly botched by Alyce Watson.
REM Also includes stuff borrowed from here and there - the IBasic WIKI,
REM Jerry Muelver, Pyxia forum, etc.
REM Shows how to play an animation (AVI or MPEG) inside of your program window, plus
REM MIDI, WAV, and MP3 files.
rem all changes are marked with update
DECLARE "winmm",mciSendStringA(lpszCommand:STRING,lpszReturnString:STRING,cchReturn:INT,hwndCallback:INT),INT
DECLARE parsepath(pfull:STRING,ppath:STRING,pfile:STRING)
DECLARE "user32",GetDlgItem(hwnd:INT,nID:INT),INT

DEF filename:STRING
DEF filter:STRING
DEF mypath$:STRING
DEF myfile$:STRING
DEF m$:STRING
DEF e$:STRING
DEF command,statusBuf:STRING
DEF mType:STRING
DEF w1:WINDOW
DEF hw1,r,g,b:INT
DEF playLength:DOUBLE
'update this is for the color
def fcr,fcg,fcb:int
def bcr,bcg,bcb:int
WINDOW w1,0,0,650,450,|@SYSMENU|@SIZE|@MAXBOX|@MINBOX,0,"Media Player",mainwindow
'upate changes the color
floodfill w1,1,1,rgb(0,0,50)
MENU w1,"T,&File,0,0","I,A&ll Media Files,0,7","I,&WAV,0,1","I,&MP3,0,2","I,M&IDI,0,3","I,MPE&G,0,4","I,&AVI,0,5","I,&Quit,0,6"
INSERTMENU w1,1,"T,&Help,0,0","I,&About,0,20"
CONTROL w1,"T,,210,30,400,360,0,12"
SETCONTROLCOLOR w1,12,RGB(0,0,255),0

'upate add .bmp and buttons
CONTROL w1,"B,Resume,10,100,80,26,@CTLBTNBITMAP,13"
SETCONTROLTEXT w1,13,("rusume",@RESBITMAP)

CONTROL w1,"B,Pause,10,140,80,24,@CTLBTNBITMAP,14"
SETCONTROLTEXT w1,14,("pause",@RESBITMAP)

CONTROL w1,"B,Restart,10,180,80,24,@CTLBTNBITMAP,15"
SETCONTROLTEXT w1,15,("restart",@RESBITMAP)

CONTROL w1,"B,Quit,10,220,80,24,@CTLBTNBITMAP,16"
SETCONTROLTEXT w1,16,("quit",@RESBITMAP)

CONTROL w1,"B,play,10,260,80,24,@CTLBTNBITMAP,17"
SETCONTROLTEXT w1,17,("play",@RESBITMAP)

CONTROL w1,"B,play,10,350,80,24,@CTLBTNBITMAP,18"
SETCONTROLTEXT w1,18,("volume",@RESBITMAP)

'update set new color
bcr=0
bcg=0
bcb=50
bcolor=rgb(bcr,bcg,bcb)
'update set new color
fcr=255
fcg=0
fcb=0
fcolor=RGB(fcr,fcg,fcb)

run = 1
WAITUNTIL run=0
command = "close all"
mciSendStringA(command,"",0,0)
closewindow w1
end

SUB mainwindow
select @class
     CASE @IDCREATE
        centerwindow w1   
   CASE @IDCLOSEWINDOW
      run = 0
   CASE @IDMENUPICK
      SELECT @MENUNUM
        CASE 20
            m$="Poorly kludged together from code "
            m$=m$+"borrowed from the IBasic community, "
            m$=m$+"by Alyce Watson, 2003"
            messagebox w1,m$,"Media Player in IBasic",0

        CASE 1
            filter = "WAV files (*.wav)|*.wav||"
           filename = FILEREQUEST("Open WAV file",w1,1,filter)
            if(len(filename))
               mType="WaveAudio"
               gosub GetGoing
            endif

         CASE 2
           filter = "MP3 files (*.mp3)|*.mp3||"
           filename = FILEREQUEST("Open MP3 file",w1,1,filter)
            if(len(filename))
               mType="MpegVideo"
                gosub GetGoing
             endif

         CASE 3
            filter = "MIDI files (*.mid)(*.midi)|*.mid;*.midi||"
            filename = FILEREQUEST("Open MIDI file",w1,1,filter)
            if(len(filename))
               mType="Sequencer"
                gosub GetGoing
              endif

         CASE 4
           filter =  "MPEG files (*.mpeg)(*.mpg)|*.mpeg;*.mpg||"
           filename = FILEREQUEST("Open Movie file",w1,1,filter)
            if(len(filename))
               mType="MpegVideo"
                gosub GetGoing
             endif

         CASE 5
           filter = "AVI files (*.avi)|*.avi||"
           filename = FILEREQUEST("Open AVI file",w1,1,filter)
            if(len(filename))
               mType="AviVideo"
                gosub GetGoing
              endif

         CASE 6
            run = 0

         CASE 7
            filter = "All Media Files|*.mid;*.midi;*.mp3;*.mpeg;*.mpg;*.wav;*.avi||"
            filename = FILEREQUEST("Open media file",w1,1,filter)
            if(len(filename))
               mType=""
               e$=lcase$(right$(filename,4))
                if (e$=".mid")|(e$="midi")
                    mType="Sequencer"
                    gosub GetGoing
                endif
                if (e$=".wav")
                    mType="WaveAudio"
                    gosub GetGoing
                endif
                if (e$=".avi")
                    mType="AviVideo"
                    gosub GetGoing
                endif
                if (e$=".mpg")|(e$="mpeg")|(e$=".mp3")
                    mType="MpegVideo"
                    gosub GetGoing
                endif
              endif
      ENDSELECT

   CASE @IDTIMER
      mciSendStringA("status sfx position",statusBuf,254,0)
      MOVE w1,10,50
      'upate changes the color and front
      frontpen w1, fcolor
       backpen w1, bcolor
       SETFONT w1, "Times New Roman",10,700
      'PRINT w1,"Time: ",statusBuf, " ms                    "
      if val(statusBuf) >= playLength
        MOVE w1,10,50
        'upate changes the color and front
        frontpen w1, fcolor
        backpen w1, bcolor
        'SETFONT w1, "Times New Roman",10,700
        'PRINT w1, "Done                                       "
        stoptimer w1
       endif

    CASE @IDCONTROL
        IF @CONTROLID = 13 THEN    mciSendStringA("play sfx","",0,0)
        IF @CONTROLID = 14 THEN mciSendStringA("pause sfx","",0,0)
        if @CONTROLID = 16 THEN run=0
        IF @CONTROLID = 15
            mciSendStringA("play sfx from 0","",0,0)
            starttimer w1,200
        endif
        IF @CONTROLID = 17
          mciSendStringA("play sfx","",0,0)
          starttimer w1,200
        endif
        'update opens the Volume control 
       IF @CONTROLID = 18 THEN SYSTEM "sndvol32.exe", "/tiny"
        endif
    endselect
RETURN


SUB MovieInWindow
    'get handle of statictext control,make it hold movie,size movie to fit control
    hw1=GetDlgItem(w1,2024+12)
    command = "window sfx handle " + str$(hw1)
    mciSendStringA(command,"",0,0)
    mciSendStringA("put sfx destination at 0 0 400 360","",0,0)
    RETURN

SUB parsepath(pfull,ppath,pfile)
    DEF done:INT
    done = 0
    ppath = pfull
    IF (INSTR(ppath,"\") | INSTR(ppath,"/"))
        WHILE done = 0
         IF(RIGHT$(ppath,1) <> "\") & (RIGHT$(ppath,1) <> "/")
            ppath = LEFT$(ppath,LEN(ppath)-1)
         ELSE
            done = 1
         ENDIF
        ENDWHILE
        pfile = MID$(pfull,LEN(ppath)+1)
    ENDIF
    RETURN

sub GetGoing
    SETCONTROLTEXT w1,12,""
    mciSendStringA("close all","",0,0)
    command="open "+CHR$(34)+filename+CHR$(34)+" type "+mType+" alias sfx"
    mciSendStringA(command,"",0,0)
    gosub MovieInWindow
    mciSendStringA("set sfx time format ms" ,"",0,0)
    mciSendStringA("info sfx file wait",statusBuf,254,0)
    move w1,10,10
    mypath$=""
    myfile$=""
    parsepath(filename,mypath$,myfile$)
    'upate changes the color and front
    frontpen w1, fcolor
     backpen w1, bcolor
'     SETFONT w1, "Times New Roman",10,700
'    print w1,myfile$,"          "
    mciSendStringA("status sfx length",statusBuf,254,0)
    playLength=val(statusBuf)
    move w1,10,30
     'upate changes the color and front
    frontpen w1, fcolor
     backpen w1, bcolor
'     SETFONT w1, "Times New Roman",10,700
'    print w1,"Length: ",statusBuf, " ms               "
   
    RETURN
 
 


Offline Larry McCaughn

  • Administrator
  • Full Member
  • *****
  • Posts: 192
  • Bananas: 4
  • Gender: Male
Re: Viewing AVI files
« Reply #1 on: July 05, 2012, 06:21:23 AM »
Quote
Some AVI files play Ok while other files are displayed speeded up.
For anyone to be able to help you, you probably need to post examples of avi's that work for you and those that don't work correctly.
« Last Edit: July 05, 2012, 06:21:47 AM by Larry McCaughn »
Admin - Here and @ Ionic Wind Software Forums
Author of Custom Button Designer, Custom Chart Designer, Snippet Manager, and IWB+ (A Visual Designer for IWBasic 2.x)

Offline rosslcs

  • Newbie
  • *
  • Posts: 30
  • Bananas: 0
Re: Viewing AVI files
« Reply #2 on: July 06, 2012, 08:14:29 AM »
Thanks for your reply.

I have included 2 links - example 1.zip is displayed speeded up and example 2.zip is displayed at normal speed.

http://www.vectrotech.com/example 1.zip
http://www.vectrotech.com/example 2.zip
 
« Last Edit: July 06, 2012, 09:31:35 AM by Larry McCaughn, Reason: to properly format links »

Offline Larry McCaughn

  • Administrator
  • Full Member
  • *****
  • Posts: 192
  • Bananas: 4
  • Gender: Male
Re: Viewing AVI files
« Reply #3 on: July 06, 2012, 09:52:06 AM »
I played both videos in my pc's media player and they both appeared to display at the proper speed.
I tried to play them in your program and the piano one wouldn't play - said it needed vids:MP43.
Quick search of internet and it appears that is a common problem.
Looked at the properties of both avi files.
The one you say is at proper speed is recorded at 16 fps and the piano one is 30 fps.
I did come across info in the SDK that indicates there is a way to use the SET mci command to set the framerate . 
That's about all the help I can be.
 
Admin - Here and @ Ionic Wind Software Forums
Author of Custom Button Designer, Custom Chart Designer, Snippet Manager, and IWB+ (A Visual Designer for IWBasic 2.x)

Offline Larry McCaughn

  • Administrator
  • Full Member
  • *****
  • Posts: 192
  • Bananas: 4
  • Gender: Male
Re: Viewing AVI files
« Reply #4 on: July 07, 2012, 01:15:45 AM »
did a little more looking.
this will change the playback speed
   
Code: [Select]
mciSendStringA("set sfx speed amount" ,"",0,0)where ammount =
1000 = normal speed
2000=double speed
500=1/2 speed
and so on...
 
also
 
Code: [Select]
mciSendStringA("status sfx speed" ,statusBuf,254,0)will return the current playback speed setting(like above) into statusBuf
 
 
Code: [Select]
mciSendStringA("status sfx frame rate" ,statusBuf,254,0)will return the fps the video was recorded at times 1000
Admin - Here and @ Ionic Wind Software Forums
Author of Custom Button Designer, Custom Chart Designer, Snippet Manager, and IWB+ (A Visual Designer for IWBasic 2.x)

Offline rosslcs

  • Newbie
  • *
  • Posts: 30
  • Bananas: 0
Re: Viewing AVI files
« Reply #5 on: July 10, 2012, 09:01:07 AM »
 Thanks for your reply ...

Where do you include the following line of code within the program example to change the playback speed.

mciSendStringA("set sfx speed amount" ,"",0,0)

Is this the correct way to use the above code?

DEF amount:int
amount=1000
mciSendStringA("amount" ,"",0,0)


Offline Larry McCaughn

  • Administrator
  • Full Member
  • *****
  • Posts: 192
  • Bananas: 4
  • Gender: Male
Re: Viewing AVI files
« Reply #6 on: July 10, 2012, 11:35:39 AM »
Use either
Code: [Select]
mciSendStringA("set sfx speed 1000" ,"",0,0)or
Code: [Select]
DEF amount:int
amount=1000
mciSendStringA("set sfx speed"+str$(amount) ,"",0,0)

Place the line after the following line in your GetGoing subroutine:
Code: [Select]
  mciSendStringA("set sfx time format ms" ,"",0,0)
« Last Edit: July 10, 2012, 11:36:24 AM by Larry McCaughn »
Admin - Here and @ Ionic Wind Software Forums
Author of Custom Button Designer, Custom Chart Designer, Snippet Manager, and IWB+ (A Visual Designer for IWBasic 2.x)

Offline BWS

  • Newbie
  • *
  • Posts: 40
  • Bananas: 2
  • Gender: Male
Re: Viewing AVI files
« Reply #7 on: July 19, 2012, 01:57:41 PM »
rosslcs,


Could you post the bitmaps for this program, please, as I am trying to update
the code to run in IWB, just for the hell of doing it!


Many thanks,


Brian

Offline BWS

  • Newbie
  • *
  • Posts: 40
  • Bananas: 2
  • Gender: Male
Re: Viewing AVI files
« Reply #8 on: July 21, 2012, 05:15:37 AM »
It's OK about the bitmaps, I've converted them to normal buttons


I can display a video file, but it doesn't display in the IWB window, but in its own
window. What's going on?


Brian

Offline Larry McCaughn

  • Administrator
  • Full Member
  • *****
  • Posts: 192
  • Bananas: 4
  • Gender: Male
Re: Viewing AVI files
« Reply #9 on: July 21, 2012, 08:40:00 AM »
I can display a video file, but it doesn't display in the IWB window, but in its own
window. What's going on?
Hard to tell without seeing your converted code.
My guess is this line:
Code: [Select]
hw1=GetDlgItem(w1,2024+12)In IWB is would be:
Code: [Select]
hw1=GetDlgItem(w1,12)
Admin - Here and @ Ionic Wind Software Forums
Author of Custom Button Designer, Custom Chart Designer, Snippet Manager, and IWB+ (A Visual Designer for IWBasic 2.x)

Offline BWS

  • Newbie
  • *
  • Posts: 40
  • Bananas: 2
  • Gender: Male
Re: Viewing AVI files
« Reply #10 on: July 23, 2012, 01:31:34 PM »
Well, you were half right, Larry. I had messed with the control handle before,
and changed it to what you suggested, with no luck


This time, when I had changed it, and pressed the Resume button by mistake, it played,
so I swapped a bit of code around, and got it working (just)


Seems to play AVIs not too bad, but not great on mpegs


Needs another eye on the code for the other formats now, as I'm fed up now!


Brian

 

To link to us use this code/button on your site

http://www.codingmonkeys.com/images/cm_link.gif