1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Convert to FLV?

Discussion in 'PHP' started by papa_face, Apr 22, 2007.

Thread Status:
Not open for further replies.
  1. dzysyak

    dzysyak Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #21
    I think I have already writen about that somewhere on the forum and there were good answers, but here is what I have used for several projects. You will need mencoder installed on the server and flvtool2 to fix the time of the flv movie.
    SEMrush
    
    exec("mencoder {$in_file_path} -o {$in_file_path}.flv -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=9600:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -srate 22050");
    
    exec("flvtool2 -Uv {$in_file_path}.flv {$in_file_path}_res.flv");
    
    PHP:
    But I think it is a good idea to write cgi script and run it by cron. This will prevent server overloads and script will encode only 1 file at a time . Just do not forget to check that script is not runing already.
     
    dzysyak, Apr 26, 2007 IP
    SEMrush
  2. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #22
    With this function that you have wrote krakjoe which is great thanks, how will i get this to interact with a users upload will i have to run the function on the file after the user uploads? Is there a way to run this on the fly?
     
    adamjblakey, Apr 27, 2007 IP
  3. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #23
    If the files you were converting were on a server somewhere, then yeah maybe, but when you upload files to a server php cannot interact with those files untill they are completely uploaded, nor can ffmpeg.

    If the files were on another server, it could (may)be done, you could use curl callbacks to write the data of the video to ffmpegs stdin and have ffmpeg write it's stdout back to another php class for streaming or zipping or just have ffmpeg write to the filesystem with the data it produces.

    It's highly unlikely you're talking about the latter.....
     
    krakjoe, Apr 27, 2007 IP
  4. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #24
    Cheers for that it works great. The only thing i need to do is add the feature so that a thumbnail is taken of the video as well as converting it. Any idea how this can be done?
     
    adamjblakey, Apr 30, 2007 IP
  5. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #25
    
    <?
    //nick_thumb( string $video, [ string $out, [ string $time, [ string $format ]]] )
    function nick_thumb( $video, $out = null, $time = '0.001', $format = 'image2' )
    {
    	if( is_null( $out ) ) $out = preg_replace('#\.(.*?[^\.])$#si', '.jpg', basename( $video ) );
    	
    	exec( sprintf( 'ffmpeg -i %s -f %s -t %s %s',
    					$video,
    					$format,
    					$time,
    					$out ), $output, $return );
    	return !$return ? true : false;
    }
    if( nick_thumb( 'stealingthumbnails.avi' ) ) :
    	echo "Thumnail created\r\n";
    else:
    	echo "No thumbnail created\r\n";
    endif;
    //nick_thumb( string $video, [ string $out, [ string $time, [ string $format ]]] )
    ?>
    
    PHP:
     
    krakjoe, May 1, 2007 IP
    sundaybrew likes this.
  6. monsterclips

    monsterclips Banned

    Messages:
    759
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #26
    I understand that i need this software to be installed on my server to convert the movie files to flv and create a thumbnail image.

    My question is this : do i need to add a code to my script so that it will automatically add the image files to the movie clips and to convert the movie files?
     
    monsterclips, May 1, 2007 IP
  7. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #27
    Thanks a lot for that Joe,

    Just one more question though. How would i go about saving that image to e.g. videos/thumbs on my server with that function you wrote?
     
    adamjblakey, May 1, 2007 IP
  8. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #28
    2nd [ 1st optional ] paramter of the function is the output image

    
    <?
    //nick_thumb( string $video, [ string $out, [ string $time, [ string $format ]]] )
    function nick_thumb( $video, $out = null, $time = '0.001', $format = 'image2' )
    {
        if( is_null( $out ) ) $out = preg_replace('#\.(.*?[^\.])$#si', '.jpg', basename( $video ) );
       
        exec( sprintf( 'ffmpeg -i %s -f %s -t %s %s',
                        $video,
                        $format,
                        $time,
                        $out ), $output, $return );
        return !$return ? true : false;
    }
    if( nick_thumb( 'stealingthumbnails.avi', 'videos/thumbs/stealingthumbs.jpg' ) ) :
        echo "Thumnail created\r\n";
    else:
        echo "No thumbnail created\r\n";
    endif;
    //nick_thumb( string $video, [ string $out, [ string $time, [ string $format ]]] )
    ?>
    
    PHP:
    @monsterclips, sorry, I don't understand the question .....
     
    krakjoe, May 1, 2007 IP
  9. monsterclips

    monsterclips Banned

    Messages:
    759
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #29
    Sorry, i forgot to add the list of software

    GD Library 2 or higher
    FFmpeg (http://ffmpeg.mplayerhq.hu)
    Mplayer + Mencoder (http://www.mplayerhq.hu/design7/dload.html)
    Flv2tool (http://inlet-media.de/flvtool2)
    Libogg + Libvorbis (http://www.xiph.org/downloads)
    LAME MP3 Encoder (http://lame.sourceforge.net)


    I understand if these software is installed on my server it will
    convert my avi,mpeg,wmv ...ect to flv but do i need to add some
    sort of code in my script so that it knows where to add the image files
    and so on?
     
    monsterclips, May 1, 2007 IP
  10. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #30
    show me script .....
     
    krakjoe, May 1, 2007 IP
  11. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #31
    Thanks for the fast reply Joe and sorry to bother you again but i am having problems. This is how i have set-up my code:

       
    
           //get the file extension.
           $getExt = explode ('.', $file_name);
           $file_ext = $getExt[count($getExt)-1];
    	   
           //create a random file name
           $rand_name = md5(time());
           $rand_name= rand(0,999999999);
    	   
    	//upload the big image
        	move_uploaded_file ($file_tmp, "upload/videos/$rand_name.$file_ext");
    
    		
    //convert video to .flv
    		ffmpeg_c("upload/videos/$rand_name.$file_ext","upload/flv/$rand_name.$file_ext.flv");
    
    		 //Take a thumbnail
    		if( nick_thumb( 'upload/flv/$rand_name.$file_ext.flv', 'upload/thumbs/$rand_name.jpg' ) ) :
    			echo "Thumnail created\r\n";
    		else:
    			echo "No thumbnail created\r\n";
    		endif; 
    
    Code (markup):
    It uploads, converts and does every thing fine but when it gets to the thumbnail it displays "No thumbnail created"

    Any ideas what i am doing wrong?

    Cheers,
    Adam
     
    adamjblakey, May 1, 2007 IP
  12. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #32
    Variables won't be parsed between single quotes. Use double quotes instead.
     
    nico_swd, May 1, 2007 IP
  13. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #33
    Works a treat.. Thanks everyone :)
     
    adamjblakey, May 1, 2007 IP
  14. monsterclips

    monsterclips Banned

    Messages:
    759
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #34
    Here is my site:

    Humour
     
    monsterclips, May 1, 2007 IP
  15. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #35
    no good, I mean code
     
    krakjoe, May 1, 2007 IP
  16. monsterclips

    monsterclips Banned

    Messages:
    759
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #36
    monsterclips, May 1, 2007 IP
  17. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #37
    The PHP code, not the HTML.

    The code of THIS script.
     
    nico_swd, May 1, 2007 IP
  18. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #38
    Does anyone know how to play .flv file within a webpage?
     
    adamjblakey, May 1, 2007 IP
  19. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
  20. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #40
    Thank you for that. From reading it appears that you have to buy this, and is only a free trial . Is there no way to do this free?
     
    adamjblakey, May 1, 2007 IP
Thread Status:
Not open for further replies.