Connecting Tech Pros Worldwide Forums | Help | Site Map

Server Side Video Transcoding!

Newbie
 
Join Date: Nov 2007
Posts: 2
#1: Nov 24 '07
Hello all!

I have this server side video transcoding script that works on all video files uploaded and transcodes them to the .flv format. The problem is when a video file that is already in the.flv format is uploaded, the script tries to transcode it also and an error occurs. Is there a way to have the script not try to transcode .flv files? I would appreciate any help given.

Expand|Select|Wrap|Line Numbers
  1.  
  2. use IO::Socket::UNIX;
  3. use IO::File;
  4.  
  5. my $vbrate = 64;
  6.  
  7. my $mplayer = "mplayer";
  8. my $mencoder = "mencoder";
  9.  
  10. sub get_length {
  11.   my ($file) = @_;
  12.  
  13.   my $pipe = IO::File->new("$mplayer -vo null -ao null -identify -ss 100:00:00 $file 2>&1|");
  14.   while (<$pipe>) {
  15.     if (/^ID_LENGTH=([\d\.]+)/) {
  16.       return $1;
  17.     } elsif (/^V:\s*(\d+\.\d+)/) {
  18.       return $1;
  19.     }
  20.   }
  21.   undef;
  22. }
  23.  
  24.  
  25. my $listen_path = "/tmp/transcode_socket";
  26. unlink($listen_path);
  27.  
  28. my $listen = IO::Socket->new(Type => SOCK_STREAM,
  29.                  Local => $listen_path,
  30.                  Listen => 1,
  31.                  Domain => AF_UNIX
  32.                 );
  33.  
  34.  
  35. my $sock;
  36. while (($sock = $listen->accept)) {
  37.   my $buf = $sock->getline;
  38.   my ($ifile, $ofile) = split(/\s+/, $buf);
  39.  
  40.   my $pid = fork();
  41.   if ($pid == 0) {
  42.     my $len = get_length($ifile);
  43.     my $ss = 0;
  44.     if ($len) {
  45.       $ss = $len / 2;
  46.     }
  47. #    system("mplayer -ss $ss -vo jpeg -frames 1 $ifile >/dev/null 2>&1");
  48.     exec "mencoder -vf scale=320:240 -ofps 15 -o $ofile -of lavf -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -oac lavc -lavcopts acodec=mp3:abitrate=32 -srate 22050 -ovc lavc -lavcopts vcodec=flv:vbitrate=${vbrate}:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:vmax_b_frames=0:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2:qns=2 -lavcopts vpass=1 $ifile";
  49.   }
  50. }
  51.  
  52. exit (0);
  53.  
  54.  

KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#2: Nov 24 '07

re: Server Side Video Transcoding!


check the filename with a reexp:

Expand|Select|Wrap|Line Numbers
  1. if ($filename =~ /\.flv/) {
  2.    skip it somehow
  3. }
Newbie
 
Join Date: Nov 2007
Posts: 2
#3: Nov 25 '07

re: Server Side Video Transcoding!


Quote:

Originally Posted by KevinADC

check the filename with a reexp:

Expand|Select|Wrap|Line Numbers
  1. if ($filename =~ /\.flv/) {
  2.    skip it somehow
  3. }


I really do not know how to go about doing that. It may be just some simple addition additional code to add or edit but am not at all in any sense of the word a programmer.
Reply