⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transcode.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** * transcode.c: transcoding stream output module ***************************************************************************** * Copyright (C) 2003-2008 the VideoLAN team * $Id: 7290b60524c206c631a2720cad836487e584c1d6 $ * * Authors: Laurent Aimar <fenrir@via.ecp.fr> *          Gildas Bazin <gbazin@videolan.org> *          Jean-Paul Saman <jpsaman #_at_# m2x dot nl> *          Antoine Cellerier <dionoea at videolan dot org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_input.h>#include <vlc_sout.h>#include <vlc_aout.h>#include <vlc_vout.h>#include <vlc_codec.h>#include <vlc_block.h>#include <vlc_filter.h>#include <vlc_osd.h>#include <math.h>#define MASTER_SYNC_MAX_DRIFT 100000#include <assert.h>/***************************************************************************** * Module descriptor *****************************************************************************/#define VENC_TEXT N_("Video encoder")#define VENC_LONGTEXT N_( \    "This is the video encoder module that will be used (and its associated "\    "options).")#define VCODEC_TEXT N_("Destination video codec")#define VCODEC_LONGTEXT N_( \    "This is the video codec that will be used.")#define VB_TEXT N_("Video bitrate")#define VB_LONGTEXT N_( \    "Target bitrate of the transcoded video stream." )#define SCALE_TEXT N_("Video scaling")#define SCALE_LONGTEXT N_( \    "Scale factor to apply to the video while transcoding (eg: 0.25)")#define FPS_TEXT N_("Video frame-rate")#define FPS_LONGTEXT N_( \    "Target output frame rate for the video stream." )#define DEINTERLACE_TEXT N_("Deinterlace video")#define DEINTERLACE_LONGTEXT N_( \    "Deinterlace the video before encoding." )#define DEINTERLACE_MODULE_TEXT N_("Deinterlace module")#define DEINTERLACE_MODULE_LONGTEXT N_( \    "Specify the deinterlace module to use." )#define WIDTH_TEXT N_("Video width")#define WIDTH_LONGTEXT N_( \    "Output video width." )#define HEIGHT_TEXT N_("Video height")#define HEIGHT_LONGTEXT N_( \    "Output video height." )#define MAXWIDTH_TEXT N_("Maximum video width")#define MAXWIDTH_LONGTEXT N_( \    "Maximum output video width." )#define MAXHEIGHT_TEXT N_("Maximum video height")#define MAXHEIGHT_LONGTEXT N_( \    "Maximum output video height." )#define VFILTER_TEXT N_("Video filter")#define VFILTER_LONGTEXT N_( \    "Video filters will be applied to the video streams (after overlays " \    "are applied). You must enter a comma-separated list of filters." )#define AENC_TEXT N_("Audio encoder")#define AENC_LONGTEXT N_( \    "This is the audio encoder module that will be used (and its associated "\    "options).")#define ACODEC_TEXT N_("Destination audio codec")#define ACODEC_LONGTEXT N_( \    "This is the audio codec that will be used.")#define AB_TEXT N_("Audio bitrate")#define AB_LONGTEXT N_( \    "Target bitrate of the transcoded audio stream." )#define ARATE_TEXT N_("Audio sample rate")#define ARATE_LONGTEXT N_( \ "Sample rate of the transcoded audio stream (11250, 22500, 44100 or 48000).")#define ACHANS_TEXT N_("Audio channels")#define ACHANS_LONGTEXT N_( \    "Number of audio channels in the transcoded streams." )#define AFILTER_TEXT N_("Audio filter")#define AFILTER_LONGTEXT N_( \    "Audio filters will be applied to the audio streams (after conversion " \    "filters are applied). You must enter a comma-separated list of filters." )#define SENC_TEXT N_("Subtitles encoder")#define SENC_LONGTEXT N_( \    "This is the subtitles encoder module that will be used (and its " \    "associated options)." )#define SCODEC_TEXT N_("Destination subtitles codec")#define SCODEC_LONGTEXT N_( \    "This is the subtitles codec that will be used." )#define SFILTER_TEXT N_("Overlays")#define SFILTER_LONGTEXT N_( \    "This allows you to add overlays (also known as \"subpictures\" on the "\    "transcoded video stream. The subpictures produced by the filters will "\    "be overlayed directly onto the video. You must specify a comma-separated "\    "list of subpicture modules" )#define OSD_TEXT N_("OSD menu")#define OSD_LONGTEXT N_(\    "Stream the On Screen Display menu (using the osdmenu subpicture module)." )#define THREADS_TEXT N_("Number of threads")#define THREADS_LONGTEXT N_( \    "Number of threads used for the transcoding." )#define HP_TEXT N_("High priority")#define HP_LONGTEXT N_( \    "Runs the optional encoder thread at the OUTPUT priority instead of " \    "VIDEO." )#define ASYNC_TEXT N_("Synchronise on audio track")#define ASYNC_LONGTEXT N_( \    "This option will drop/duplicate video frames to synchronise the video " \    "track on the audio track." )#define HURRYUP_TEXT N_( "Hurry up" )#define HURRYUP_LONGTEXT N_( "The transcoder will drop frames if your CPU " \                "can't keep up with the encoding rate." )static const char *const ppsz_deinterlace_type[] ={    "deinterlace", "ffmpeg-deinterlace"};static int  Open ( vlc_object_t * );static void Close( vlc_object_t * );#define SOUT_CFG_PREFIX "sout-transcode-"vlc_module_begin();    set_shortname( N_("Transcode"));    set_description( N_("Transcode stream output") );    set_capability( "sout stream", 50 );    add_shortcut( "transcode" );    set_callbacks( Open, Close );    set_category( CAT_SOUT );    set_subcategory( SUBCAT_SOUT_STREAM );    set_section( N_("Video"), NULL );    add_string( SOUT_CFG_PREFIX "venc", NULL, NULL, VENC_TEXT,                VENC_LONGTEXT, false );    add_string( SOUT_CFG_PREFIX "vcodec", NULL, NULL, VCODEC_TEXT,                VCODEC_LONGTEXT, false );    add_integer( SOUT_CFG_PREFIX "vb", 800 * 1000, NULL, VB_TEXT,                 VB_LONGTEXT, false );    add_float( SOUT_CFG_PREFIX "scale", 1, NULL, SCALE_TEXT,               SCALE_LONGTEXT, false );    add_float( SOUT_CFG_PREFIX "fps", 0, NULL, FPS_TEXT,               FPS_LONGTEXT, false );    add_bool( SOUT_CFG_PREFIX "hurry-up", true, NULL, HURRYUP_TEXT,               HURRYUP_LONGTEXT, false );    add_bool( SOUT_CFG_PREFIX "deinterlace", 0, NULL, DEINTERLACE_TEXT,              DEINTERLACE_LONGTEXT, false );    add_string( SOUT_CFG_PREFIX "deinterlace-module", "deinterlace", NULL,                DEINTERLACE_MODULE_TEXT, DEINTERLACE_MODULE_LONGTEXT,                false );        change_string_list( ppsz_deinterlace_type, 0, 0 );    add_integer( SOUT_CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,                 WIDTH_LONGTEXT, true );    add_integer( SOUT_CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,                 HEIGHT_LONGTEXT, true );    add_integer( SOUT_CFG_PREFIX "maxwidth", 0, NULL, MAXWIDTH_TEXT,                 MAXWIDTH_LONGTEXT, true );    add_integer( SOUT_CFG_PREFIX "maxheight", 0, NULL, MAXHEIGHT_TEXT,                 MAXHEIGHT_LONGTEXT, true );    add_module_list( SOUT_CFG_PREFIX "vfilter", "video filter2",                     NULL, NULL,                     VFILTER_TEXT, VFILTER_LONGTEXT, false );    set_section( N_("Audio"), NULL );    add_string( SOUT_CFG_PREFIX "aenc", NULL, NULL, AENC_TEXT,                AENC_LONGTEXT, false );    add_string( SOUT_CFG_PREFIX "acodec", NULL, NULL, ACODEC_TEXT,                ACODEC_LONGTEXT, false );    add_integer( SOUT_CFG_PREFIX "ab", 0, NULL, AB_TEXT,                 AB_LONGTEXT, false );    add_integer( SOUT_CFG_PREFIX "channels", 0, NULL, ACHANS_TEXT,                 ACHANS_LONGTEXT, false );    add_integer( SOUT_CFG_PREFIX "samplerate", 0, NULL, ARATE_TEXT,                 ARATE_LONGTEXT, true );    add_bool( SOUT_CFG_PREFIX "audio-sync", 0, NULL, ASYNC_TEXT,              ASYNC_LONGTEXT, false );    add_module_list( SOUT_CFG_PREFIX "afilter",  "audio filter2",                     NULL, NULL,                     AFILTER_TEXT, AFILTER_LONGTEXT, false );    set_section( N_("Overlays/Subtitles"), NULL );    add_string( SOUT_CFG_PREFIX "senc", NULL, NULL, SENC_TEXT,                SENC_LONGTEXT, false );    add_string( SOUT_CFG_PREFIX "scodec", NULL, NULL, SCODEC_TEXT,                SCODEC_LONGTEXT, false );    add_bool( SOUT_CFG_PREFIX "soverlay", 0, NULL, SCODEC_TEXT,               SCODEC_LONGTEXT, false );    add_module_list( SOUT_CFG_PREFIX "sfilter", "video filter",                     NULL, NULL,                     SFILTER_TEXT, SFILTER_LONGTEXT, false );    set_section( N_("On Screen Display"), NULL );    add_bool( SOUT_CFG_PREFIX "osd", 0, NULL, OSD_TEXT,              OSD_LONGTEXT, false );    set_section( N_("Miscellaneous"), NULL );    add_integer( SOUT_CFG_PREFIX "threads", 0, NULL, THREADS_TEXT,                 THREADS_LONGTEXT, true );    add_bool( SOUT_CFG_PREFIX "high-priority", 0, NULL, HP_TEXT, HP_LONGTEXT,              true );vlc_module_end();static const char *const ppsz_sout_options[] = {    "venc", "vcodec", "vb",    "scale", "fps", "width", "height", "vfilter", "deinterlace",    "deinterlace-module", "threads", "hurry-up", "aenc", "acodec", "ab",    "afilter", "samplerate", "channels", "senc", "scodec", "soverlay",    "sfilter", "osd", "audio-sync", "high-priority", "maxwidth", "maxheight",    NULL};/***************************************************************************** * Exported prototypes *****************************************************************************/static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );static int               Del ( sout_stream_t *, sout_stream_id_t * );static int               Send( sout_stream_t *, sout_stream_id_t *, block_t* );static int  transcode_audio_new    ( sout_stream_t *, sout_stream_id_t * );static void transcode_audio_close  ( sout_stream_id_t * );static int  transcode_audio_process( sout_stream_t *, sout_stream_id_t *,                                     block_t *, block_t ** );static aout_buffer_t *audio_new_buffer( decoder_t *, int );static void audio_del_buffer( decoder_t *, aout_buffer_t * );static int  transcode_video_new    ( sout_stream_t *, sout_stream_id_t * );static void transcode_video_close  ( sout_stream_t *, sout_stream_id_t * );static void transcode_video_encoder_init( sout_stream_t *, sout_stream_id_t *);static int  transcode_video_encoder_open( sout_stream_t *, sout_stream_id_t *);static int  transcode_video_process( sout_stream_t *, sout_stream_id_t *,                                     block_t *, block_t ** );static void video_del_buffer( vlc_object_t *, picture_t * );static picture_t *video_new_buffer_decoder( decoder_t * );static void video_del_buffer_decoder( decoder_t *, picture_t * );static void video_link_picture_decoder( decoder_t *, picture_t * );static void video_unlink_picture_decoder( decoder_t *, picture_t * );static picture_t *video_new_buffer_filter( filter_t * );static void video_del_buffer_filter( filter_t *, picture_t * );static int  transcode_spu_new    ( sout_stream_t *, sout_stream_id_t * );static void transcode_spu_close  ( sout_stream_id_t * );static int  transcode_spu_process( sout_stream_t *, sout_stream_id_t *,                                   block_t *, block_t ** );static int  transcode_osd_new    ( sout_stream_t *, sout_stream_id_t * );static void transcode_osd_close  ( sout_stream_t *, sout_stream_id_t * );static int  transcode_osd_process( sout_stream_t *, sout_stream_id_t *,                                   block_t *, block_t ** );static void* EncoderThread( vlc_object_t * p_this );static const int pi_channels_maps[6] ={    0,    AOUT_CHAN_CENTER,   AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,    AOUT_CHAN_CENTER | AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,    AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT     | AOUT_CHAN_REARRIGHT,    AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER     | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT};#define PICTURE_RING_SIZE 64#define SUBPICTURE_RING_SIZE 20#define ENC_FRAMERATE (25 * 1000 + .5)#define ENC_FRAMERATE_BASE 1000struct sout_stream_sys_t{    VLC_COMMON_MEMBERS    sout_stream_t   *p_out;    sout_stream_id_t *id_video;    block_t         *p_buffers;    vlc_mutex_t     lock_out;    vlc_cond_t      cond;    picture_t *     pp_pics[PICTURE_RING_SIZE];    int             i_first_pic, i_last_pic;    /* Audio */    vlc_fourcc_t    i_acodec;   /* codec audio (0 if not transcode) */    char            *psz_aenc;    config_chain_t  *p_audio_cfg;    uint32_t        i_sample_rate;    uint32_t        i_channels;    int             i_abitrate;    char            *psz_af2;    /* Video */    vlc_fourcc_t    i_vcodec;   /* codec video (0 if not transcode) */    char            *psz_venc;    config_chain_t  *p_video_cfg;    int             i_vbitrate;    double          f_scale;    double          f_fps;    unsigned int    i_width, i_maxwidth;    unsigned int    i_height, i_maxheight;    bool            b_deinterlace;    char            *psz_deinterlace;    config_chain_t  *p_deinterlace_cfg;    int             i_threads;    bool            b_high_priority;    bool            b_hurry_up;    char            *psz_vf2;    /* SPU */    vlc_fourcc_t    i_scodec;   /* codec spu (0 if not transcode) */    char            *psz_senc;    bool            b_soverlay;    config_chain_t  *p_spu_cfg;    spu_t           *p_spu;    /* OSD Menu */    vlc_fourcc_t    i_osdcodec; /* codec osd menu (0 if not transcode) */    char            *psz_osdenc;    config_chain_t  *p_osd_cfg;    bool            b_osd;   /* true when osd es is registered */    /* Sync */    bool            b_master_sync;    mtime_t         i_master_drift;};struct decoder_owner_sys_t{    picture_t *pp_pics[PICTURE_RING_SIZE];    sout_stream_sys_t *p_sys;};struct filter_owner_sys_t{    picture_t *pp_pics[PICTURE_RING_SIZE];    sout_stream_sys_t *p_sys;};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -