コード例 #1
0
ファイル: models.py プロジェクト: kamilnazar1/OwnTube
    def encode_media(self):
        """ This is used to tell ffmpeg what to do """
        kind = self.kind
        path = self.originalFile.path
        outputdir = settings.ENCODING_OUTPUT_DIR + self.slug
        if not os.path.exists(outputdir):
            os.makedirs(outputdir)
        outputdir = outputdir + "/"
        if (kind == 0) or (kind == 2):
            logfile = outputdir + "encoding_mp4_log.txt"
            outfile_mp4 = outputdir + self.slug + ".mp4"
            # Create the command line
            cl_mp4 = ffmpeg(path, outfile_mp4, logfile, OWNTUBE_MP4_VIDEO, OWNTUBE_MP4_AUDIO).build_command_line()

            logfile = outputdir + "encoding_webm_log.txt"
            outfile_webm = outputdir + self.slug + ".webm"

            cl_webm = ffmpeg(path, outfile_webm, logfile, OWNTUBE_WEBM_VIDEO, OWNTUBE_WEBM_AUDIO).build_command_line()

            self.mp4URL = settings.ENCODING_VIDEO_BASE_URL + self.slug + "/" + self.slug + ".mp4"
            self.webmURL = settings.ENCODING_VIDEO_BASE_URL + self.slug + "/" + self.slug + ".webm"
            self.videoThumbURL = settings.ENCODING_VIDEO_BASE_URL + self.slug + "/" + self.slug + ".jpg"
            outcode = subprocess.Popen(cl_mp4, shell=True)

            while outcode.poll() == None:
                pass

            if outcode.poll() == 0:
                self.mp4Size = os.path.getsize(outfile_mp4)
                self.duration = getLength(outfile_mp4)
            else:
                raise StandardError("Encoding MP4 Failed")

            print(cl_mp4)
            print(cl_webm)
            outcode = subprocess.Popen(cl_webm, shell=True)

            while outcode.poll() == None:
                pass

            if outcode.poll() == 0:
                self.wembSize = os.path.getsize(outfile_webm)
            else:
                raise StandardError("Encoding WEBM Failed")

            outcode = subprocess.Popen(
                [
                    "/usr/local/bin/ffmpeg -i "
                    + self.originalFile.path
                    + " -ss 5.0 -vframes 1 -f image2 "
                    + outputdir
                    + self.slug
                    + ".jpg"
                ],
                shell=True,
            )

            while outcode.poll() == None:
                pass

            if outcode.poll() == 0:
                pass
            else:
                raise StandardError("Making Thumb Failed")

        if (kind == 1) or (kind == 2):
            logfile = outputdir + "encoding_mp3_log.txt"
            outfile_mp3 = outputdir + self.slug + ".mp3"
            # Create the command line
            cl_mp3 = ffmpeg(path, outfile_mp3, logfile, OWNTUBE_NULL_VIDEO, OWNTUBE_MP3_AUDIO).build_command_line()

            logfile = outputdir + "encoding_ogg_log.txt"
            outfile_ogg = outputdir + self.slug + ".ogg"

            cl_ogg = ffmpeg(path, outfile_ogg, logfile, OWNTUBE_NULL_VIDEO, OWNTUBE_OGG_AUDIO).build_command_line()

            self.mp3URL = settings.ENCODING_VIDEO_BASE_URL + self.slug + "/" + self.slug + ".mp3"
            self.oggURL = settings.ENCODING_VIDEO_BASE_URL + self.slug + "/" + self.slug + ".ogg"

            outcode = subprocess.Popen(cl_mp3, shell=True)

            while outcode.poll() == None:
                pass

            if outcode.poll() == 0:
                self.mp3Size = os.path.getsize(outfile_mp3)
                self.duration = getLength(outfile_mp3)
            else:
                raise StandardError("Encoding MP3 Failed")

            outcode = subprocess.Popen(cl_ogg, shell=True)

            while outcode.poll() == None:
                pass

            if outcode.poll() == 0:
                self.oggSize = os.path.getsize(outfile_ogg)
            else:
                raise StandardError("Encoding OGG Failed")

        if kind == 1:
            file = File(self.originalFile.path)  # mutagen can automatically detect format and type of tags
            if file.tags and "APIC:" in file.tags and file.tags["APIC:"]:
                artwork = file.tags["APIC:"].data  # access APIC frame and grab the image
                with open(outputdir + self.slug + "_cover.jpg", "wb") as img:
                    img.write(artwork)

                self.audioThumbURL = settings.ENCODING_VIDEO_BASE_URL + self.slug + "/" + self.slug + "_cover.jpg"

        self.encodingDone = True
        self.torrentDone = settings.USE_BITTORRENT
        if settings.USE_BITTORRENT:
            self.torrentURL = settings.BITTORRENT_FILES_BASE_URL + self.slug + ".torrent"

        self.published = self.autoPublish
        self.save()
コード例 #2
0
ファイル: models.py プロジェクト: puzzlet/OwnTube
    def encode_media(self):
        ''' This is used to tell ffmpeg what to do '''
        kind = self.kind
        path = self.originalFile.path
        outputdir = settings.ENCODING_OUTPUT_DIR + self.slug
        if not os.path.exists(outputdir):
            os.makedirs(outputdir)
        outputdir = outputdir + '/'
        if ((kind == 0) or (kind == 2)):
            logfile = outputdir + 'encoding_mp4_log.txt'
            outfile_mp4 = outputdir + self.slug + '.mp4'
            # Create the command line
            cl_mp4 = ffmpeg(path, outfile_mp4, logfile, OWNTUBE_MP4_VIDEO, OWNTUBE_MP4_AUDIO).build_command_line()
            
            logfile = outputdir + 'encoding_webm_log.txt'
            outfile_webm = outputdir + self.slug + '.webm'
    
            cl_webm = ffmpeg(path, outfile_webm, logfile, OWNTUBE_WEBM_VIDEO, OWNTUBE_WEBM_AUDIO).build_command_line()
            
            self.mp4URL = settings.ENCODING_VIDEO_BASE_URL + self.slug + '/' + self.slug + '.mp4'
            self.webmURL = settings.ENCODING_VIDEO_BASE_URL + self.slug + '/' + self.slug + '.webm' 
            self.videoThumbURL = settings.ENCODING_VIDEO_BASE_URL + self.slug + '/' + self.slug + '.jpg'
            outcode = subprocess.Popen(cl_mp4, shell=True)
            
            while outcode.poll() == None:
                pass
    
            if outcode.poll() == 0:
                self.mp4Size = os.path.getsize(outfile_mp4)
                self.duration = getLength(outfile_mp4)
            else:
                raise StandardError('Encoding MP4 Failed')
            
            print(cl_mp4)
            print(cl_webm)    
            outcode = subprocess.Popen(cl_webm, shell=True)
            
            while outcode.poll() == None:
                pass
    
            if outcode.poll() == 0:
                self.wembSize = os.path.getsize(outfile_webm)
            else:
                raise StandardError('Encoding WEBM Failed')
    
            outcode = subprocess.Popen(['ffmpeg -i '+ self.originalFile.path + ' -ss 5.0 -vframes 1 -f image2 ' + outputdir + self.slug + '.jpg'],shell = True)
            
            while outcode.poll() == None:
                pass
    
            if outcode.poll() == 0:
                pass 
            else:
                raise StandardError('Making Thumb Failed')
            
            
        if((kind == 1) or (kind == 2)):
            logfile = outputdir + 'encoding_mp3_log.txt'
            outfile_mp3 = outputdir + self.slug + '.mp3'
            # Create the command line
            cl_mp3 = ffmpeg(path, outfile_mp3, logfile, OWNTUBE_NULL_VIDEO , OWNTUBE_MP3_AUDIO).build_command_line()
            
            logfile = outputdir + 'encoding_ogg_log.txt'
            outfile_ogg = outputdir + self.slug + '.ogg'

            cl_ogg = ffmpeg(path, outfile_ogg, logfile, OWNTUBE_NULL_VIDEO, OWNTUBE_OGG_AUDIO).build_command_line()
            
            self.mp3URL = settings.ENCODING_VIDEO_BASE_URL + self.slug +  '/' + self.slug + '.mp3'
            self.oggURL = settings.ENCODING_VIDEO_BASE_URL + self.slug +  '/' + self.slug + '.ogg'
            
            outcode = subprocess.Popen(cl_mp3, shell=True)
            
            while outcode.poll() == None:
                pass
    
            if outcode.poll() == 0:
                self.mp3Size = os.path.getsize(outfile_mp3)
                self.duration = getLength(outfile_mp3)
            else:
                raise StandardError('Encoding MP3 Failed')
                
            outcode = subprocess.Popen(cl_ogg, shell=True)
            
            while outcode.poll() == None:
                pass
    
            if outcode.poll() == 0:
                self.oggSize = os.path.getsize(outfile_ogg)
            else:
                raise StandardError('Encoding OGG Failed')
                
        if (kind == 1):
            file = File(self.originalFile.path) # mutagen can automatically detect format and type of tags
            artwork = file.tags['APIC:'].data # access APIC frame and grab the image
            with open(outputdir + self.slug + '_cover.jpg', 'wb') as img:
                img.write(artwork)
            
            self.audioThumbURL = settings.ENCODING_VIDEO_BASE_URL + self.slug + '/' + self.slug + '_cover.jpg'
            
        self.encodingDone = True
        self.torrentDone = settings.USE_BITTORRENT
        if settings.USE_BITTORRENT:
            self.torrentURL = settings.BITTORRENT_FILES_BASE_URL + self.slug + '.torrent'
            
        self.published = self.autoPublish
        self.save()
コード例 #3
0
ファイル: models.py プロジェクト: aarontaylor/OwnTube
    def encode_media(self):
        ''' This is used to tell ffmpeg what to do '''
        kind = self.kind
        path = self.originalFile.path
        name_array = os.path.basename(self.originalFile.path).partition('.')
        name = slugify(name_array[0])
        outputdir = settings.ENCODING_OUTPUT_DIR + slugify(name)
        if not os.path.exists(outputdir):
            os.makedirs(outputdir)
        outputdir = outputdir + '/'
        if ((kind == 0) or (kind == 2)):
            logfile = settings.ENCODING_OUTPUT_DIR + 'encoding_mp4_log.txt'
            outfile_mp4 = outputdir + slugify(name) + '.mp4'
            # Create the command line
            cl_mp4 = ffmpeg(path, outfile_mp4, logfile, OWNTUBE_MP4_VIDEO, OWNTUBE_MP4_AUDIO).build_command_line()
            
            logfile = settings.ENCODING_OUTPUT_DIR + 'encoding_webm_log.txt'
            outfile_webm = outputdir + slugify(name) + '.webm'
    
            cl_webm = ffmpeg(path, outfile_webm, logfile, OWNTUBE_WEBM_VIDEO, OWNTUBE_WEBM_AUDIO).build_command_line()
            
            self.mp4URL = settings.ENCODING_VIDEO_BASE_URL + slugify(name) + '/' + slugify(name) + '.mp4'
            self.webmURL = settings.ENCODING_VIDEO_BASE_URL + slugify(name) + '/' + slugify(name) + '.webm' 
            self.videoThumbURL = settings.ENCODING_VIDEO_BASE_URL + slugify(name) + '/' + slugify(name) + '.jpg'
            outcode = subprocess.Popen(cl_mp4, shell=True)
            
            while outcode.poll() == None:
                pass
    
            if outcode.poll() == 0:
                self.mp4Size = os.path.getsize(outfile_mp4)
                self.duration = getLength(outfile_mp4)
            else:
                raise StandardError('Encoding MP4 Failed')
            
            print(cl_mp4)
            print(cl_webm)    
            outcode = subprocess.Popen(cl_webm, shell=True)
            
            while outcode.poll() == None:
                pass
    
            if outcode.poll() == 0:
                self.wembSize = os.path.getsize(outfile_webm)
            else:
                raise StandardError('Encoding WEBM Failed')
    
            outcode = subprocess.Popen(['ffmpeg -i '+ self.originalFile.path + ' -ss 1.0 -vframes 1 -f image2 ' + outputdir + slugify(name) + '.jpg'],shell = True)
            
            while outcode.poll() == None:
                pass
    
            if outcode.poll() == 0:
                pass 
            else:
                raise StandardError('Making Thumb Failed')
            
            
        if((kind == 1) or (kind == 2)):
            logfile = settings.ENCODING_OUTPUT_DIR + 'encoding_mp3_log.txt'
            outfile_mp3 = outputdir + slugify(name) + '.mp3'
            # Create the command line
            cl_mp3 = ffmpeg(path, outfile_mp3, logfile, OWNTUBE_NULL_VIDEO , OWNTUBE_MP3_AUDIO).build_command_line()
            
            logfile = settings.ENCODING_OUTPUT_DIR + 'encoding_ogg_log.txt'
            outfile_ogg = outputdir + slugify(name) + '.ogg'

            cl_ogg = ffmpeg(path, outfile_ogg, logfile, OWNTUBE_NULL_VIDEO, OWNTUBE_OGG_AUDIO).build_command_line()
            
            self.mp3URL = settings.ENCODING_VIDEO_BASE_URL + slugify(name) +  '/' + slugify(name) + '.mp3'
            self.oggURL = settings.ENCODING_VIDEO_BASE_URL + slugify(name) +  '/' + slugify(name) + '.ogg'
                        
            outcode = subprocess.Popen(cl_mp3, shell=True)
            
            while outcode.poll() == None:
                pass
    
            if outcode.poll() == 0:
                self.mp3Size = os.path.getsize(outfile_mp3)
                self.duration = getLength(outfile_mp3)
            else:
                raise StandardError('Encoding MP3 Failed')
                
            outcode = subprocess.Popen(cl_ogg, shell=True)
            
            while outcode.poll() == None:
                pass
    
            if outcode.poll() == 0:
                self.oggSize = os.path.getsize(outfile_ogg)
            else:
                raise StandardError('Encoding OGG Failed')
            
        self.encodingDone = True
        if settings.USE_BITTORRENT:
            self.torrentURL = settings.BITTORRENT_FILES_BASE_URL + self.slug + '.torrent'
            
        self.published = True
        self.save()
コード例 #4
0
    def encode_media(self):
        ''' This is used to tell ffmpeg what to do '''
        kind = self.kind
        path = self.originalFile.path
        outputdir = settings.ENCODING_OUTPUT_DIR + self.slug
        if not os.path.exists(outputdir):
            os.makedirs(outputdir)
        outputdir = outputdir + '/'
        if ((kind == 0) or (kind == 2)):
            logfile = outputdir + 'encoding_mp4_log.txt'
            outfile_mp4 = outputdir + self.slug + '.mp4'
            # Create the command line
            cl_mp4 = ffmpeg(path, outfile_mp4, logfile, OWNTUBE_MP4_VIDEO,
                            OWNTUBE_MP4_AUDIO).build_command_line()

            logfile = outputdir + 'encoding_webm_log.txt'
            outfile_webm = outputdir + self.slug + '.webm'

            cl_webm = ffmpeg(path, outfile_webm, logfile, OWNTUBE_WEBM_VIDEO,
                             OWNTUBE_WEBM_AUDIO).build_command_line()

            self.mp4URL = settings.ENCODING_VIDEO_BASE_URL + self.slug + '/' + self.slug + '.mp4'
            self.webmURL = settings.ENCODING_VIDEO_BASE_URL + self.slug + '/' + self.slug + '.webm'
            self.videoThumbURL = settings.ENCODING_VIDEO_BASE_URL + self.slug + '/' + self.slug + '.jpg'
            outcode = subprocess.Popen(cl_mp4, shell=True)

            while outcode.poll() == None:
                pass

            if outcode.poll() == 0:
                self.mp4Size = os.path.getsize(outfile_mp4)
                self.duration = getLength(outfile_mp4)
            else:
                raise StandardError('Encoding MP4 Failed')

            print(cl_mp4)
            print(cl_webm)
            outcode = subprocess.Popen(cl_webm, shell=True)

            while outcode.poll() == None:
                pass

            if outcode.poll() == 0:
                self.wembSize = os.path.getsize(outfile_webm)
            else:
                raise StandardError('Encoding WEBM Failed')

            outcode = subprocess.Popen([
                '/usr/local/bin/ffmpeg -i ' + self.originalFile.path +
                ' -ss 5.0 -vframes 1 -f image2 ' + outputdir + self.slug +
                '.jpg'
            ],
                                       shell=True)

            while outcode.poll() == None:
                pass

            if outcode.poll() == 0:
                pass
            else:
                raise StandardError('Making Thumb Failed')

        if ((kind == 1) or (kind == 2)):
            logfile = outputdir + 'encoding_mp3_log.txt'
            outfile_mp3 = outputdir + self.slug + '.mp3'
            # Create the command line
            cl_mp3 = ffmpeg(path, outfile_mp3, logfile, OWNTUBE_NULL_VIDEO,
                            OWNTUBE_MP3_AUDIO).build_command_line()

            logfile = outputdir + 'encoding_ogg_log.txt'
            outfile_ogg = outputdir + self.slug + '.ogg'

            cl_ogg = ffmpeg(path, outfile_ogg, logfile, OWNTUBE_NULL_VIDEO,
                            OWNTUBE_OGG_AUDIO).build_command_line()

            self.mp3URL = settings.ENCODING_VIDEO_BASE_URL + self.slug + '/' + self.slug + '.mp3'
            self.oggURL = settings.ENCODING_VIDEO_BASE_URL + self.slug + '/' + self.slug + '.ogg'

            outcode = subprocess.Popen(cl_mp3, shell=True)

            while outcode.poll() == None:
                pass

            if outcode.poll() == 0:
                self.mp3Size = os.path.getsize(outfile_mp3)
                self.duration = getLength(outfile_mp3)
            else:
                raise StandardError('Encoding MP3 Failed')

            outcode = subprocess.Popen(cl_ogg, shell=True)

            while outcode.poll() == None:
                pass

            if outcode.poll() == 0:
                self.oggSize = os.path.getsize(outfile_ogg)
            else:
                raise StandardError('Encoding OGG Failed')

        if (kind == 1):
            file = File(
                self.originalFile.path
            )  # mutagen can automatically detect format and type of tags
            if file.tags and 'APIC:' in file.tags and file.tags['APIC:']:
                artwork = file.tags[
                    'APIC:'].data  # access APIC frame and grab the image
                with open(outputdir + self.slug + '_cover.jpg', 'wb') as img:
                    img.write(artwork)

                self.audioThumbURL = settings.ENCODING_VIDEO_BASE_URL + self.slug + '/' + self.slug + '_cover.jpg'

        self.encodingDone = True
        self.torrentDone = settings.USE_BITTORRENT
        if settings.USE_BITTORRENT:
            self.torrentURL = settings.BITTORRENT_FILES_BASE_URL + self.slug + '.torrent'

        self.published = self.autoPublish
        self.save()