VideoRecordRepeat::VideoRecordRepeat(
    std::string uri, std::string save_filename, int buffer_size_bytes
    ) : video_src(0), video_file(0), video_recorder(0),
    filename(save_filename), buffer_size_bytes(buffer_size_bytes), frame_num(0)
{
    video_src = OpenVideo(uri);
}
Example #2
0
int AccessOpen( vlc_object_t *obj )
{
    access_t *access = (access_t *)obj;

    /* Only when selected */
    if( *access->psz_access == '\0' ) return VLC_EGENERIC;

    access_InitFields( access );

    demux_sys_t *sys = calloc( 1, sizeof( demux_sys_t ));
    if( unlikely(sys == NULL) )
        return VLC_ENOMEM;
    access->p_sys = (access_sys_t *)sys;

    ParseMRL( obj, access->psz_location );
    sys->i_fd = OpenVideo( obj, sys, false );
    if( sys->i_fd == -1 )
    {
        free( sys );
        return VLC_EGENERIC;
    }

    if( sys->io == IO_METHOD_READ )
        access->pf_read = AccessReadStream;
    else
        access->pf_block = AccessRead;
    access->pf_seek = NULL;
    access->pf_control = AccessControl;
    return VLC_SUCCESS;
}
Example #3
0
void VideoInput::Reset()
{
    Close();

    // Create video device
    video_src = OpenVideo(uri_input);
    Source();
}
Example #4
0
/*****************************************************************************
 * Open: probe the decoder and return score
 *****************************************************************************
 * Tries to launch a decoder and return score so that the interface is able
 * to choose.
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    decoder_t *p_dec = (decoder_t*)p_this;

    /* create a mutex */
    var_Create( p_this->p_libvlc, "qt_mutex", VLC_VAR_MUTEX );
    
    switch( p_dec->fmt_in.i_codec )
    {
        case VLC_FOURCC('S','V','Q','3'): /* Sorenson v3 */
    /*    case VLC_FOURCC('S','V','Q','1'):  Sorenson v1 
        case VLC_FOURCC('Z','y','G','o'):
        case VLC_FOURCC('V','P','3','1'):
        case VLC_FOURCC('3','I','V','1'): */
        case VLC_FOURCC('r','l','e',' '): /* QuickTime animation (RLE) */
        case VLC_FOURCC('r','p','z','a'): /* QuickTime Apple Video */
        case VLC_FOURCC('a','z','p','r'): /* QuickTime animation (RLE) */
#ifdef LOADER
            p_dec->p_sys = NULL;
            p_dec->pf_decode_video = DecodeVideo;
            return VLC_SUCCESS;
#else
            return OpenVideo( p_dec );
#endif

        case VLC_FOURCC('s','a','m','r'): /* 3GPP AMR audio */
        case VLC_FOURCC('m','p','4','a'): /* MPEG-4 audio */
        case VLC_FOURCC('Q','D','M','C'): /* QDesign */
        case VLC_FOURCC('Q','D','M','2'): /* QDesign* 2 */
        case VLC_FOURCC('Q','c','l','p'): /* Qualcomm Purevoice Codec */
        case VLC_FOURCC('Q','C','L','P'): /* Qualcomm Purevoice Codec */
        case VLC_FOURCC('M','A','C','3'): /* MACE3 audio decoder */
        case VLC_FOURCC('M','A','C','6'): /* MACE6 audio decoder */
        case VLC_FOURCC('d','v','c','a'): /* DV Audio */
        case VLC_FOURCC('s','o','w','t'): /* 16-bit Little Endian */
        case VLC_FOURCC('t','w','o','s'): /* 16-bit Big Endian */
        case VLC_FOURCC('a','l','a','w'): /* ALaw 2:1 */
        case VLC_FOURCC('u','l','a','w'): /* mu-Law 2:1 */
        case VLC_FOURCC('r','a','w',' '): /* 8-bit offset binaries */
        case VLC_FOURCC('f','l','3','2'): /* 32-bit Floating Point */
        case VLC_FOURCC('f','l','6','4'): /* 64-bit Floating Point */
        case VLC_FOURCC('i','n','2','4'): /* 24-bit Interger */
        case VLC_FOURCC('i','n','3','2'): /* 32-bit Integer */
        case 0x0011:                            /* DVI IMA */
        case 0x6D730002:                        /* Microsoft ADPCM-ACM */
        case 0x6D730011:                        /* DVI Intel IMAADPCM-ACM */
#ifdef LOADER
            p_dec->p_sys = NULL;
            p_dec->pf_decode_audio = DecodeAudio;
            return VLC_SUCCESS;
#else
            return OpenAudio( p_dec );
#endif

        default:
            return VLC_EGENERIC;
    }
}
Example #5
0
////////////////////////////////////////////////////////////////
// ビデオキャプチャ開始
//
// 引数:	filename	出力ファイル名
//			sw			スクリーンの幅
//			sh			スクリーンの高さ
//			vrate		フレームレート(fps)
//			arate		音声サンプリングレート(Hz)
//			bpp			色深度(16,24,32)
// 返値:	bool		true:成功 false:失敗
////////////////////////////////////////////////////////////////
bool AVI6::StartAVI( const char *filename, int sw, int sh, int vrate, int arate, int bpp )
{
#ifndef NOAVI
	cCritical::Lock();
	Init();
	
	ABPP = bpp;

	// オーディオバッファ作成
	ABuf.InitBuffer( arate / vrate * 2 );
	
	// 出力コンテキスト作成
	avformat_alloc_output_context2(&oc, NULL, NULL, filename);
	if (!oc) return false;

	fmt = oc->oformat;

	// 音声、ビデオストリームを作成
	if (fmt->video_codec != AV_CODEC_ID_NONE) {
		// ビデオコーデックにVP9を選択されると画像が崩れるため、暫定措置として強制的にVP8にする。
		fmt->video_codec = AV_CODEC_ID_VP8;
		AddStream(&video_st, oc, &video_codec, fmt->video_codec, sw, sh);
	}
	if (fmt->audio_codec != AV_CODEC_ID_NONE) {
		// オーディオコーデックにOPUSを選択されると落ちるため、暫定措置として強制的にVORBISにする。
		fmt->audio_codec = AV_CODEC_ID_VORBIS;
		AddStream(&audio_st, oc, &audio_codec, fmt->audio_codec, sw, sh);
	}

	OpenVideo(oc, video_codec, &video_st, opt);
	OpenAudio(oc, audio_codec, &audio_st, opt, arate);

	av_dump_format(oc, 0, filename, 1);

	int ret = 0;
	// ファイルを開く
	if (!(fmt->flags & AVFMT_NOFILE)) {
		ret = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE);
		if (0 > ret) {
			return false;
		}
	}

	// ストリームヘッダを書き込み
	ret = avformat_write_header(oc, &opt);
	if (0 > ret) {
		return false;
	}

	isAVI = true;
	cCritical::UnLock();
	return true;
#else
	return false;
#endif
}
Example #6
0
void VideoInput::Play(bool realtime)
{
    video_file.reset();
    video_src->Stop();
    video_recorder.reset();

    video_file = OpenVideo(
        realtime ? "file:[realtime]//" + uri_output.url :
                   uri_output.url
    );

    frame_num = 0;

    // Switch sub-video
    videos.resize(1);
    videos[0] = video_file.get();
}
Example #7
0
void VideoInput::Open(
    const std::string& input_uri,
    const std::string& output_uri
    ) 
{
    str_uri_input = input_uri;
    uri_input = ParseUri(input_uri);
    uri_output = ParseUri(output_uri);

    if (uri_output.scheme == "file") {
        // Default to pango output
        uri_output.scheme = "pango";
    }

    // Start off playing from video_src
    video_src = OpenVideo(input_uri);
    Source();
}
Example #8
0
File: demux.c Project: CSRedRat/vlc
int DemuxOpen( vlc_object_t *obj )
{
    demux_t *demux = (demux_t *)obj;
    demux_sys_t *sys = calloc( 1, sizeof( demux_sys_t ) );
    if( unlikely(sys == NULL) )
        return VLC_ENOMEM;
    demux->p_sys = sys;

    ParseMRL( obj, demux->psz_location );
    sys->i_fd = OpenVideo( obj, sys, true );
    if( sys->i_fd == -1 )
    {
        free( sys );
        return VLC_EGENERIC;
    }

    demux->pf_demux = Demux;
    demux->pf_control = DemuxControl;
    demux->info.i_update = 0;
    demux->info.i_title = 0;
    demux->info.i_seekpoint = 0;
    return VLC_SUCCESS;
}
Example #9
0
bool AVFormatWriter::Init(void)
{
    if (m_videoOutBuf)
        delete [] m_videoOutBuf;

    if (m_width && m_height)
        m_videoOutBuf = new unsigned char[m_width * m_height * 2 + 10];

    AVOutputFormat *fmt = av_guess_format(m_container.toAscii().constData(),
                                          NULL, NULL);
    if (!fmt)
    {
        LOG(VB_RECORD, LOG_ERR, LOC +
            QString("Init(): Unable to guess AVOutputFormat from container %1")
                    .arg(m_container));
        return false;
    }

    m_fmt = *fmt;

    if (m_width && m_height)
    {
        m_avVideoCodec = avcodec_find_encoder_by_name(
            m_videoCodec.toAscii().constData());
        if (!m_avVideoCodec)
        {
            LOG(VB_RECORD, LOG_ERR, LOC +
                QString("Init(): Unable to find video codec %1").arg(m_videoCodec));
            return false;
        }

        m_fmt.video_codec = m_avVideoCodec->id;
    }
    else
        m_fmt.video_codec = CODEC_ID_NONE;

    m_avAudioCodec = avcodec_find_encoder_by_name(
        m_audioCodec.toAscii().constData());
    if (!m_avAudioCodec)
    {
        LOG(VB_RECORD, LOG_ERR, LOC +
            QString("Init(): Unable to find audio codec %1").arg(m_audioCodec));
        return false;
    }

    m_fmt.audio_codec = m_avAudioCodec->id;

    m_ctx = avformat_alloc_context();
    if (!m_ctx)
    {
        LOG(VB_RECORD, LOG_ERR,
            LOC + "Init(): Unable to allocate AVFormatContext");
        return false;
    }

    m_ctx->oformat = &m_fmt;

    if (m_container == "mpegts")
        m_ctx->packet_size = 2324;

    snprintf(m_ctx->filename, sizeof(m_ctx->filename), "%s",
             m_filename.toAscii().constData());

    if (m_fmt.video_codec != CODEC_ID_NONE)
        m_videoStream = AddVideoStream();
    if (m_fmt.audio_codec != CODEC_ID_NONE)
        m_audioStream = AddAudioStream();

    m_pkt = new AVPacket;
    if (!m_pkt)
    {
        LOG(VB_RECORD, LOG_ERR, LOC + "Init(): error allocating AVPacket");
        return false;
    }

    if (av_set_parameters(m_ctx, NULL) < 0)
    {
        LOG(VB_RECORD, LOG_ERR, "Init(): Invalid output format parameters");
        return false;
    }

    if ((m_videoStream) && (!OpenVideo()))
    {
        LOG(VB_RECORD, LOG_ERR, LOC + "Init(): OpenVideo() failed");
        return false;
    }

    if ((m_audioStream) && (!OpenAudio()))
    {
        LOG(VB_RECORD, LOG_ERR, LOC + "Init(): OpenAudio() failed");
        return false;
    }

    return true;
}
Example #10
0
/*****************************************************************************
 * DecodeVideo:
 *****************************************************************************/
static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
{
    decoder_sys_t *p_sys = p_dec->p_sys;
    block_t       *p_block;
    picture_t     *p_pic;
    mtime_t       i_pts;

    ComponentResult cres;

#ifdef LOADER
    /* We must do open and close in the same thread (unless we do
     * Setup_LDT_Keeper in the main thread before all others */
    if( p_sys == NULL )
    {
        if( OpenVideo( p_dec ) )
        {
            /* Fatal */
            p_dec->b_error = true;
            return NULL;
        }
        p_sys = p_dec->p_sys;
    }
#endif

    if( pp_block == NULL || *pp_block == NULL )
    {
        return NULL;
    }
    p_block = *pp_block;
    *pp_block = NULL;
 
    i_pts = p_block->i_pts ? p_block->i_pts : p_block->i_dts;

    mtime_t i_display_date = 0;
    if( !(p_block->i_flags & BLOCK_FLAG_PREROLL) )
        i_display_date = decoder_GetDisplayDate( p_dec, i_pts );

    if( i_display_date > 0 && i_display_date < mdate() )
    {
        p_sys->i_late++;
    }
    else
    {
        p_sys->i_late = 0;
    }
#ifndef NDEBUG
    msg_Dbg( p_dec, "bufsize: %d", (int)p_block->i_buffer);
#endif

    if( p_sys->i_late > 10 )
    {
        msg_Dbg( p_dec, "late buffer dropped (%"PRId64")", i_pts );
        block_Release( p_block );
        return NULL;
    }
 
    vlc_mutex_lock( &qt_mutex );

    if( ( p_pic = decoder_NewPicture( p_dec ) ) )
    {
        p_sys->decpar.data                  = (Ptr)p_block->p_buffer;
        p_sys->decpar.bufferSize            = p_block->i_buffer;
        (**p_sys->framedescHandle).dataSize = p_block->i_buffer;

        cres = p_sys->ImageCodecBandDecompress( p_sys->ci, &p_sys->decpar );

        ++p_sys->decpar.frameNumber;

        if( cres &0xFFFF )
        {
            msg_Dbg( p_dec, "quicktime_video: ImageCodecBandDecompress"
                     " cres=0x%X (-0x%X) %d :(",
                     (int)cres,(int)-cres, (int)cres );
        }

        memcpy( p_pic->p[0].p_pixels, p_sys->plane,
                p_dec->fmt_in.video.i_width * p_dec->fmt_in.video.i_height * 2 );
        p_pic->date = i_pts;
    }
 
    vlc_mutex_unlock( &qt_mutex );

    block_Release( p_block );
    return p_pic;
}
Example #11
0
/*****************************************************************************
 * Open: probe the decoder and return score
 *****************************************************************************
 * Tries to launch a decoder and return score so that the interface is able
 * to choose.
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    decoder_t *p_dec = (decoder_t*)p_this;

#ifdef __APPLE__
    OSErr err;
    SInt32 qtVersion, macosversion;

    err = Gestalt(gestaltQuickTimeVersion, &qtVersion);
    err = Gestalt(gestaltSystemVersion, &macosversion);
#ifndef NDEBUG
    msg_Dbg( p_this, "Mac OS version is %#lx", macosversion );
    msg_Dbg( p_this, "Quicktime version is %#lx", qtVersion );
#endif

    /* bail out. This plugin is soo Carbon, that it can't be used on 10.5 at all */
    msg_Info( p_dec, "Your Mac OS version is to new to use this plugin for anything." );
    return VLC_EGENERIC;
#endif

    switch( p_dec->fmt_in.i_codec )
    {
        case VLC_CODEC_H264:
        case VLC_CODEC_CINEPAK:
        case VLC_FOURCC('I','V','4','1'): /* Indeo Video IV */
        case VLC_FOURCC('i','v','4','1'): /* dto. */
#ifdef __APPLE__
        case VLC_FOURCC('p','x','l','t'): /* Pixlet */
#endif
        case VLC_CODEC_DV:
        case VLC_CODEC_SVQ3: /* Sorenson v3 */
    /*    case VLC_CODEC_SVQ1:  Sorenson v1
        case VLC_FOURCC('Z','y','G','o'):
        case VLC_FOURCC('V','P','3','1'):
        case VLC_FOURCC('3','I','V','1'): */
        case VLC_CODEC_QTRLE:
        case VLC_CODEC_RPZA:
#ifdef LOADER
        p_dec->p_sys = NULL;
        p_dec->pf_decode_video = DecodeVideo;
        p_dec->fmt_out.i_cat = VIDEO_ES;
        return VLC_SUCCESS;
#else
        return OpenVideo( p_dec );
#endif

#ifdef __APPLE__
        case VLC_FOURCC('I','L','B','C'): /* iLBC */
            if ((err != noErr) || (qtVersion < 0x07500000)) 
                return VLC_EGENERIC;
        case VLC_FOURCC('i','l','b','c'): /* iLBC */
            if ((err != noErr) || (qtVersion < 0x07500000)) 
                return VLC_EGENERIC;
#endif
        case VLC_CODEC_AMR_NB: /* 3GPP AMR audio */
        case VLC_FOURCC('s','a','m','b'): /* 3GPP AMR-WB audio */
        case VLC_CODEC_MP4A: /* MPEG-4 audio */
        case VLC_FOURCC('Q','D','M','C'): /* QDesign */
        case VLC_CODEC_QDM2: /* QDesign* 2 */
        case VLC_CODEC_QCELP: /* Qualcomm Purevoice Codec */
        case VLC_FOURCC('Q','C','L','P'): /* Qualcomm Purevoice Codec */
        case VLC_CODEC_MACE3: /* MACE3 audio decoder */
        case VLC_CODEC_MACE6: /* MACE6 audio decoder */
        case VLC_FOURCC('d','v','c','a'): /* DV Audio */
        case VLC_FOURCC('s','o','w','t'): /* 16-bit Little Endian */
        case VLC_FOURCC('t','w','o','s'): /* 16-bit Big Endian */
        case VLC_CODEC_ALAW: /* ALaw 2:1 */
        case VLC_FOURCC('u','l','a','w'): /* mu-Law 2:1 */
        case VLC_FOURCC('r','a','w',' '): /* 8-bit offset binaries */
        case VLC_CODEC_FL32: /* 32-bit Floating Point */
        case VLC_CODEC_FL64: /* 64-bit Floating Point */
        case VLC_FOURCC('i','n','2','4'): /* 24-bit Interger */
        case VLC_FOURCC('i','n','3','2'): /* 32-bit Integer */
        case 0x0011:                            /* DVI IMA */
        case 0x6D730002:                        /* Microsoft ADPCM-ACM */
        case 0x6D730011:                        /* DVI Intel IMAADPCM-ACM */
#ifdef LOADER
        p_dec->p_sys = NULL;
        p_dec->pf_decode_audio = DecodeAudio;
        p_dec->fmt_out.i_cat = AUDIO_ES;
        return VLC_SUCCESS;
#else
        return OpenAudio( p_dec );
#endif

        default:
            return VLC_EGENERIC;
    }
}
Example #12
0
bool AVFormatWriter::Init(void)
{
    AVOutputFormat *fmt = av_guess_format(m_container.toLatin1().constData(),
                                          NULL, NULL);
    if (!fmt)
    {
        LOG(VB_RECORD, LOG_ERR, LOC +
            QString("Init(): Unable to guess AVOutputFormat from container %1")
                    .arg(m_container));
        return false;
    }

    m_fmt = *fmt;

    if (m_width && m_height)
    {
        m_avVideoCodec = avcodec_find_encoder_by_name(
            m_videoCodec.toLatin1().constData());
        if (!m_avVideoCodec)
        {
            LOG(VB_RECORD, LOG_ERR, LOC +
                QString("Init(): Unable to find video codec %1").arg(m_videoCodec));
            return false;
        }

        m_fmt.video_codec = m_avVideoCodec->id;
    }
    else
        m_fmt.video_codec = AV_CODEC_ID_NONE;

    m_avAudioCodec = avcodec_find_encoder_by_name(
        m_audioCodec.toLatin1().constData());
    if (!m_avAudioCodec)
    {
        LOG(VB_RECORD, LOG_ERR, LOC +
            QString("Init(): Unable to find audio codec %1").arg(m_audioCodec));
        return false;
    }

    m_fmt.audio_codec = m_avAudioCodec->id;

    m_ctx = avformat_alloc_context();
    if (!m_ctx)
    {
        LOG(VB_RECORD, LOG_ERR,
            LOC + "Init(): Unable to allocate AVFormatContext");
        return false;
    }

    m_ctx->oformat = &m_fmt;

    if (m_container == "mpegts")
        m_ctx->packet_size = 2324;

    snprintf(m_ctx->filename, sizeof(m_ctx->filename), "%s",
             m_filename.toLatin1().constData());

    if (m_fmt.video_codec != AV_CODEC_ID_NONE)
        m_videoStream = AddVideoStream();
    if (m_fmt.audio_codec != AV_CODEC_ID_NONE)
        m_audioStream = AddAudioStream();

    if ((m_videoStream) && (!OpenVideo()))
    {
        LOG(VB_RECORD, LOG_ERR, LOC + "Init(): OpenVideo() failed");
        return false;
    }

    if ((m_audioStream) && (!OpenAudio()))
    {
        LOG(VB_RECORD, LOG_ERR, LOC + "Init(): OpenAudio() failed");
        return false;
    }

    return true;
}
Example #13
0
/*****************************************************************************
 * DecodeVideo:
 *****************************************************************************/
static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
{
    decoder_sys_t *p_sys = p_dec->p_sys;
    vlc_value_t   lockval;
    block_t       *p_block;
    picture_t     *p_pic;
    mtime_t       i_pts;

    ComponentResult cres;

#ifdef LOADER
    /* We must do open and close in the same thread (unless we do
     * Setup_LDT_Keeper in the main thread before all others */
    if( p_sys == NULL )
    {
        if( OpenVideo( p_dec ) )
        {
            /* Fatal */
            p_dec->b_error = VLC_TRUE;
            return NULL;
        }
        p_sys = p_dec->p_sys;
    }
#endif

    if( pp_block == NULL || *pp_block == NULL )
    {
        return NULL;
    }
    p_block = *pp_block;
    *pp_block = NULL;
    
    i_pts = p_block->i_pts ? p_block->i_pts : p_block->i_dts;

    if( i_pts < mdate() )
    {
        p_sys->i_late++;
    }
    else
    {
        p_sys->i_late = 0;
    }
    msg_Dbg( p_dec, "bufsize: %d", p_block->i_buffer);

    if( p_sys->i_late > 10 )
    {
        msg_Dbg( p_dec, "too late buffer -> dropped" );
        block_Release( p_block );
        return NULL;
    }
    
    var_Get( p_dec->p_libvlc, "qt_mutex", &lockval );
    vlc_mutex_lock( lockval.p_address );

    if( ( p_pic = p_dec->pf_vout_buffer_new( p_dec ) ) )
    {
        p_sys->decpar.data                  = (Ptr)p_block->p_buffer;
        p_sys->decpar.bufferSize            = p_block->i_buffer;
        (**p_sys->framedescHandle).dataSize = p_block->i_buffer;

        cres = p_sys->ImageCodecBandDecompress( p_sys->ci, &p_sys->decpar );

        ++p_sys->decpar.frameNumber;

        if( cres &0xFFFF )
        {
            msg_Dbg( p_dec, "quicktime_video: ImageCodecBandDecompress"
                     " cres=0x%X (-0x%X) %d :(\n",
                     (int)cres,(int)-cres, (int)cres );
        }

        memcpy( p_pic->p[0].p_pixels, p_sys->plane,
                p_dec->fmt_in.video.i_width * p_dec->fmt_in.video.i_height * 2 );
        p_pic->date = i_pts;
    }
    
    vlc_mutex_unlock( lockval.p_address );

    block_Release( p_block );
    return p_pic;
}