def testNbSamplesAudioTranscode():
    """
    Transcode one audio stream (to wave24b48kmono), check nb samples.
    """
    inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
    outputFileName = "testNbSamplesAudioTranscode.wav"

    ouputFile = av.OutputFile(outputFileName)
    transcoder = av.Transcoder(ouputFile)

    # create custom profile
    customProfile = av.ProfileMap()
    customProfile[av.avProfileIdentificator] = "customProfile"
    customProfile[av.avProfileIdentificatorHuman] = "custom profile"
    customProfile[av.avProfileType] = av.avProfileTypeAudio
    customProfile[av.avProfileCodec] = "pcm_s16le"

    transcoder.addStream(av.InputStreamDesc(inputFileName), customProfile)

    progress = av.ConsoleProgress()
    transcoder.process(progress)

    # get src file of transcode
    src_inputFile = av.InputFile(inputFileName)
    src_properties = src_inputFile.getProperties()
    src_audioStream = src_properties.getAudioProperties()[0]

    # get dst file of transcode
    dst_inputFile = av.InputFile(outputFileName)
    dst_properties = dst_inputFile.getProperties()
    dst_audioStream = dst_properties.getAudioProperties()[0]

    assert_equals(src_audioStream.getNbSamples(),
                  dst_audioStream.getNbSamples())
Beispiel #2
0
def testProcessWithStatistics():
    """
    Process one video stream with a custom profile of encoding to activate statistics.
    """
    inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
    outputFileName = "testProcessWithStatistics.mov"

    ouputFile = av.OutputFile(outputFileName)
    transcoder = av.Transcoder(ouputFile)

    # create custom profile
    customProfile = av.ProfileMap()
    customProfile[av.avProfileIdentificator] = "customProfile"
    customProfile[av.avProfileIdentificatorHuman] = "custom profile"
    customProfile[av.avProfileType] = av.avProfileTypeVideo
    customProfile[av.avProfileCodec] = "mpeg2video"
    customProfile[av.avProfileProcessStat] = "processStat"

    src_inputFile = av.InputFile(inputFileName)
    src_properties = src_inputFile.getProperties()
    src_videoStream = src_properties.getVideoProperties()[0]
    videoStreamIndex = src_videoStream.getStreamIndex()
    transcoder.add(inputFileName, videoStreamIndex, customProfile)

    progress = av.ConsoleProgress()
    processStat = transcoder.process(progress)

    # check process stat returned
    videoStat = processStat.getVideoStat(0)
    assert_equals(videoStat.getDuration(), src_videoStream.getDuration())
    assert_equals(
        videoStat.getNbFrames(),
        int(src_videoStream.getDuration() * src_videoStream.getFps()))
    assert_not_equals(videoStat.getQuality(), 0)
    assert_not_equals(videoStat.getPSNR(), 0)
def testSetVideoFrame():
    """
    Generate a video stream, and set its frame during process.
    """
    # create output
    outputFileName = "testSetVideoFrame.mov"
    ouputFile = av.OutputFile(outputFileName)

    # create custom profile
    encodingProfile = av.ProfileMap()
    encodingProfile[av.avProfileIdentificator] = "encodingProfile"
    encodingProfile[av.avProfileIdentificatorHuman] = "custom profile"
    encodingProfile[av.avProfileType] = av.avProfileTypeVideo
    encodingProfile[av.avProfileCodec] = "mpeg2video"
    encodingProfile[av.avProfilePixelFormat] = "yuv422p"
    encodingProfile[av.avProfileWidth] = "1920"
    encodingProfile[av.avProfileHeight] = "1080"

    # create transcoder and add a video stream
    transcoder = av.Transcoder(ouputFile)
    transcoder.addGenerateStream(encodingProfile)
    videoDecoder = transcoder.getStreamTranscoder(0).getCurrentDecoder()

    # start process
    ouputFile.beginWrap()
    transcoder.preProcessCodecLatency()
    p = av.ConsoleProgress()

    # process 51 frames
    nbFrames = 255
    for i in range(0, nbFrames, 5):
        transcoder.processFrame()
        p.progress(i, nbFrames)

        # set video frame
        frame = av.VideoFrame(av.VideoFrameDesc(1920, 1080, "rgb24"))
        frame.assignValue(i)
        videoDecoder.setNextFrame(frame)

    # end process
    ouputFile.endWrap()

    # get dst file of transcode
    dst_inputFile = av.InputFile(outputFileName)
    progress = av.NoDisplayProgress()
    dst_inputFile.analyse(progress, av.eAnalyseLevelHeader)
    dst_properties = dst_inputFile.getProperties()
    dst_videoStream = dst_properties.getVideoProperties()[0]

    assert_equals("mpeg2video", dst_videoStream.getCodecName())
    assert_equals(1920, dst_videoStream.getWidth())
    assert_equals(1080, dst_videoStream.getHeight())
    assert_equals(16, dst_videoStream.getDar().num)
    assert_equals(9, dst_videoStream.getDar().den)
Beispiel #4
0
def testVideoTranscodeWithFilter():
    """
    A video transcode with a yadif filter.
    """
    inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
    outputFileName = "testVideoTranscodeWithFilter.avi"

    ouputFile = av.OutputFile(outputFileName)
    transcoder = av.Transcoder(ouputFile)

    inputFile = av.InputFile(inputFileName)
    src_videoStream = inputFile.getProperties().getVideoProperties()[0]

    # transcode the video stream
    videoStreamIndex = src_videoStream.getStreamIndex()
    customProfile = av.ProfileMap()
    customProfile[av.avProfileIdentificator] = "customProfile"
    customProfile[av.avProfileIdentificatorHuman] = "custom profile"
    customProfile[av.avProfileType] = av.avProfileTypeVideo
    customProfile[av.avProfileCodec] = "mpeg2video"
    customProfile[av.avProfilePixelFormat] = "yuv420p"
    transcoder.add(inputFileName, videoStreamIndex, customProfile)

    # add yadif filter
    streamTranscoder = transcoder.getStreamTranscoder(0)
    filterGraph = streamTranscoder.getFilterGraph()
    filterGraph.addFilter("yadif")

    progress = av.ConsoleProgress()
    processStat = transcoder.process(progress)

    # check process stat returned
    videoStat = processStat.getVideoStat(0)
    assert_equals(src_videoStream.getDuration(), videoStat.getDuration())
    assert_equals(
        int(src_videoStream.getDuration() * src_videoStream.getFps()),
        videoStat.getNbFrames())

    # get dst file of transcode
    dst_inputFile = av.InputFile(outputFileName)
    dst_properties = dst_inputFile.getProperties()
    dst_videoStream = dst_properties.getVideoProperties()[0]

    assert_equals("mpeg2video", dst_videoStream.getCodecName())
    assert_equals("yuv420p",
                  dst_videoStream.getPixelProperties().getPixelName())
def testTranscodeYUV420():
    """
    Process one video stream (custom profile of encoding, with pixel format YUV420).
    """
    inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
    outputFileName = "testTranscodeYUV420.avi"

    ouputFile = av.OutputFile(outputFileName)
    transcoder = av.Transcoder(ouputFile)

    # create custom profile
    customProfile = av.ProfileMap()
    customProfile[av.avProfileIdentificator] = "customProfile"
    customProfile[av.avProfileIdentificatorHuman] = "custom profile"
    customProfile[av.avProfileType] = av.avProfileTypeVideo
    customProfile[av.avProfileCodec] = "mpeg2video"
    customProfile[av.avProfilePixelFormat] = "yuv420p"

    inputFile = av.InputFile(inputFileName)
    src_videoStream = inputFile.getProperties().getVideoProperties()[0]
    videoStreamIndex = src_videoStream.getStreamIndex()
    transcoder.addStream(av.InputStreamDesc(inputFileName, videoStreamIndex),
                         customProfile)

    progress = av.ConsoleProgress()
    processStat = transcoder.process(progress)

    # check process stat returned
    videoStat = processStat.getVideoStat(0)
    assert_equals(src_videoStream.getDuration(), videoStat.getDuration())
    assert_equals(
        int(src_videoStream.getDuration() * src_videoStream.getFps()),
        videoStat.getNbFrames())

    # get dst file of transcode
    dst_inputFile = av.InputFile(outputFileName)
    dst_properties = dst_inputFile.getProperties()
    dst_videoStream = dst_properties.getVideoProperties()[0]

    assert_equals("mpeg2video", dst_videoStream.getCodecName())
    assert_equals("yuv420p",
                  dst_videoStream.getPixelProperties().getPixelName())
def testTranscodeMovVariableNbSamplesPerFrame():
    """
    Transcode the audio stream of a MOV file which contains a video stream.
    The number of samples per frame can vary to fit the gop size.
    AudioTransform must manage these cases.
    """
    inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE']
    outputFileName = "testTranscodeMovVariableNbSamplesPerFrame.wav"

    ouputFile = av.OutputFile(outputFileName)
    transcoder = av.Transcoder(ouputFile)

    # create custom profile
    customProfile = av.ProfileMap()
    customProfile[av.avProfileIdentificator] = "customProfile"
    customProfile[av.avProfileIdentificatorHuman] = "custom profile"
    customProfile[av.avProfileType] = av.avProfileTypeAudio
    customProfile[av.avProfileCodec] = "pcm_s24le"

    inputFile = av.InputFile(inputFileName)
    src_audioStream = inputFile.getProperties().getAudioProperties()[0]
    audioStreamIndex = src_audioStream.getStreamIndex()
    transcoder.add(inputFileName, audioStreamIndex, customProfile)

    progress = av.ConsoleProgress()
    processStat = transcoder.process(progress)

    # check process stat returned
    audioStat = processStat.getAudioStat(0)
    assert_equals(src_audioStream.getDuration(), audioStat.getDuration())

    # get dst file of transcode
    dst_inputFile = av.InputFile(outputFileName)
    dst_properties = dst_inputFile.getProperties()
    dst_audioStream = dst_properties.getAudioProperties()[0]

    assert_equals("pcm_s24le", dst_audioStream.getCodecName())
    assert_equals("PCM signed 24-bit little-endian",
                  dst_audioStream.getCodecLongName())
Beispiel #7
0
av.preloadCodecsAndFormats()

# create input file
inputFile = av.InputFile(args.inputFileName)
if len(inputFile.getProperties().getVideoProperties()) == 0:
    print "No video stream found in file ", args.inputFileName
    exit(1)

# seek in file
if args.frame:
    inputFile.seekAtFrame(args.frame, av.AVSEEK_FLAG_BACKWARD)
elif args.time:
    inputFile.seekAtTime(args.time, av.AVSEEK_FLAG_BACKWARD)

# create output file (need to set format profile of encoding to force output format to mjpeg)
formatProfile = av.ProfileMap()
formatProfile[av.avProfileIdentificator] = "thumbnailFormatPreset"
formatProfile[av.avProfileIdentificatorHuman] = "Thumbnail format preset"
formatProfile[av.avProfileType] = av.avProfileTypeFormat
formatProfile[av.avProfileFormat] = "mjpeg"
outputFile = av.OutputFile(args.outputFileName)
outputFile.setupWrapping(formatProfile)

# create input stream
videoStreamIndex = inputFile.getProperties().getVideoProperties(
)[0].getStreamIndex()
inputStream = av.InputStream(inputFile, videoStreamIndex)
inputStream.activate()

# create output stream
videoProfile = av.ProfileMap()
Beispiel #8
0
    if args.inputFileName is None:
        parser.print_help()
        exit(1)

# setup avtranscoder
logger = av.Logger().setLogLevel(av.AV_LOG_QUIET)
av.preloadCodecsAndFormats()

# create input file
inputFile = av.InputFile(args.inputFileName)
if len(inputFile.getProperties().getVideoProperties()) == 0:
    print("No video stream found in file ", args.inputFileName)
    exit(1)

# create output file (need to set format profile of encoding to force output format to mp4)
formatProfile = av.ProfileMap()
formatProfile[av.avProfileIdentificator] = "mp4WrapFormatPreset"
formatProfile[av.avProfileIdentificatorHuman] = "MP4 rewraping format preset"
formatProfile[av.avProfileType] = av.avProfileTypeFormat
formatProfile[av.avProfileFormat] = args.format
if args.faststart:
    formatProfile["movflags"] = "+faststart"
outputFile = av.OutputFile(args.outputFileName)
outputFile.setupWrapping(formatProfile)

# create transcoder
transcoder = av.Transcoder(outputFile)
transcoder.add(args.inputFileName)

# launch process
progress = av.ConsoleProgress()
Beispiel #9
0
def get_thumbnail_on_file():
    path = request.args.get('path')
    frame = float(request.args.get('frame', 0))

    if path == None:
        abort(400)

    analyse_gop = request.args.get('analyse_gop', False)

    analyse_gop_state = "disabled"
    if analyse_gop:
        analyse_gop_state = "enabled"

    app.logger.info('Analyse path: %s - GOP analysis: %s', path,
                    analyse_gop_state)
    av.preloadCodecsAndFormats()
    inputFile = av.InputFile(str(path))

    # inputFile.seekAtFrame(frame, av.AVSEEK_FLAG_FRAME)
    # inputFile.seekAtFrame(frame, av.AVSEEK_FLAG_ANY)
    # inputFile.seekAtFrame(frame, av.AVSEEK_FLAG_BACKWARD)

    tmpFilename = "/tmp/thumbnails.jpg"

    # create output file (need to set format profile of encoding to force output format to mjpeg)
    formatProfile = av.ProfileMap()
    formatProfile[av.avProfileIdentificator] = "thumbnailFormatPreset"
    formatProfile[av.avProfileIdentificatorHuman] = "Thumbnail format preset"
    formatProfile[av.avProfileType] = av.avProfileTypeFormat
    formatProfile[av.avProfileFormat] = "mjpeg"
    outputFile = av.OutputFile(tmpFilename)
    outputFile.setupWrapping(formatProfile)

    # create input stream
    videoProperties = inputFile.getProperties().getVideoProperties()[0]
    videoStreamIndex = videoProperties.getStreamIndex()
    videoWidth = videoProperties.getWidth()
    videoHeight = videoProperties.getHeight()
    videoFps = videoProperties.getFps()
    dar = videoProperties.getDar()

    # inputStream = av.InputStream(inputFile, videoStreamIndex)
    # inputStream.activate()

    inputStreamDesc = av.InputStreamDesc(str(path), videoStreamIndex)

    # create output stream
    videoProfile = av.ProfileMap()
    videoProfile[av.avProfileIdentificator] = "thumbnailVideoPreset"
    videoProfile[av.avProfileIdentificatorHuman] = "Thumbnail video preset"
    videoProfile[av.avProfileType] = av.avProfileTypeVideo
    videoProfile[av.avProfileCodec] = "mjpeg"
    # videoProfile[av.avProfilePixelFormat] = "yuvj420p"
    videoProfile[av.avProfilePixelFormat] = "yuvj422p"
    if 'width' in request.args:
        videoProfile[av.avProfileWidth] = str(request.args["width"])
        videoProfile[av.avProfileHeight] = str(
            videoHeight * int(request.args["width"]) / videoWidth)
    # if 'height' in request.args:
    #     videoProfile[av.avProfileHeight] = str(request.args["height"])

    # create transcoder
    transcoder = av.Transcoder(outputFile)
    transcoder.addStream(inputStreamDesc, videoProfile, -frame / 25)

    # launch process
    outputFile.beginWrap()
    transcoder.preProcessCodecLatency()
    transcoder.processFrame()
    outputFile.endWrap()

    return send_file(tmpFilename, mimetype='image/gif')