OpenCV 2.4 in python - Video processing

前端 未结 2 723
天命终不由人
天命终不由人 2021-02-01 10:33

The Project: Add a running date/time stamp on each and every frame of a video. (The result of digital video camera, and my father asked me how can he add the timestamp(to the mi

2条回答
  •  一向
    一向 (楼主)
    2021-02-01 11:03

    Used hachoir-metadata to read metadata of video file(including Framerate, height and width .

    importing:

    from hachoir_core.error import HachoirError
    from hachoir_core.cmd_line import unicodeFilename
    from hachoir_parser import createParser
    from hachoir_core.tools import makePrintable
    from hachoir_metadata import extractMetadata
    from hachoir_core.i18n import getTerminalCharset
    from hachoir_metadata.metadata_item import QUALITY_BEST
    

    function:

    def metaDataFile(filePath):
        filename, realname = unicodeFilename(filePath), filePath
        parser = createParser(filename, realname)
        try:
            metadata = extractMetadata(parser, QUALITY_BEST)
        except HachoirError, err:
            print "Metadata extraction error: %s" % unicode(err)
            metadata = None
        if not metadata:
            print metadata
            print "Unable to extract metadata"
            exit(1)
        return metadata
    

    usage:

    metadata = metaDataFile(videoPath)
    width = metadata.get('width')
    height = metadata.get('height')
    fps = metadata.get('frame_rate')
    

    to see relevant properties:

    for data in sorted(metadata):
        if len(data.values ) > 0:
            print data.key, data.values[0].value
    

提交回复
热议问题