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

📄 transcode.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** * transcode.c: transcoding stream output module ***************************************************************************** * Copyright (C) 2003-2004 the VideoLAN team * $Id: transcode.c 16774 2006-09-21 19:29:10Z hartman $ * * Authors: Laurent Aimar <fenrir@via.ecp.fr> *          Gildas Bazin <gbazin@videolan.org> *          Jean-Paul Saman <jpsaman #_at_# m2x dot nl> * * 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 *****************************************************************************/#include <stdlib.h>#include <string.h>#include <math.h>#include <vlc/vlc.h>#include <vlc/input.h>#include <vlc/sout.h>#include <vlc/vout.h>#include <vlc/decoder.h>#include "vlc_filter.h"#include "vlc_osd.h"#define MASTER_SYNC_MAX_DRIFT 100000/***************************************************************************** * 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 CROPTOP_TEXT N_("Video crop (top)")#define CROPTOP_LONGTEXT N_( \    "Number of pixels to crop at the top of the video." )#define CROPLEFT_TEXT N_("Video crop (left)")#define CROPLEFT_LONGTEXT N_( \    "Number of pixels to crop at the left of the video." )#define CROPBOTTOM_TEXT N_("Video crop (bottom)")#define CROPBOTTOM_LONGTEXT N_( \    "Number of pixels to crop at the bottom of the video." )#define CROPRIGHT_TEXT N_("Video crop (right)")#define CROPRIGHT_LONGTEXT N_( \    "Number of pixels to crop at the right of the video." )#define PADDTOP_TEXT N_("Video padding (top)")#define PADDTOP_LONGTEXT N_( \    "Size of the black border to add at the top of the video." )#define PADDLEFT_TEXT N_("Video padding (left)")#define PADDLEFT_LONGTEXT N_( \    "Size of the black border to add at the left of the video." )#define PADDBOTTOM_TEXT N_("Video padding (bottom)")#define PADDBOTTOM_LONGTEXT N_( \    "Size of the black border to add at the bottom of the video." )#define PADDRIGHT_TEXT N_("Video padding (right)")#define PADDRIGHT_LONGTEXT N_( \    "Size of the black border to add at the right of the video." )#define CANVAS_WIDTH_TEXT N_("Video canvas width")//\bug [strings] crod -> crop (twice)#define CANVAS_WIDTH_LONGTEXT N_( \    "This will automatically crod and pad the video to a specified width." )#define CANVAS_HEIGHT_TEXT N_("Video canvas height")#define CANVAS_HEIGHT_LONGTEXT N_( \    "This will automatically crod and pad the video to a specified height." )#define CANVAS_ASPECT_TEXT N_("Video canvas aspect ratio")#define CANVAS_ASPECT_LONGTEXT N_( \    "This sets aspect (like 4:3) of the video canvas and letterbox the video "\    "accordingly." )#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 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 char *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( _("Transcode"));    set_description( _("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, VLC_FALSE );    add_string( SOUT_CFG_PREFIX "vcodec", NULL, NULL, VCODEC_TEXT,                VCODEC_LONGTEXT, VLC_FALSE );    add_integer( SOUT_CFG_PREFIX "vb", 800 * 1000, NULL, VB_TEXT,                 VB_LONGTEXT, VLC_FALSE );    add_float( SOUT_CFG_PREFIX "scale", 1, NULL, SCALE_TEXT,               SCALE_LONGTEXT, VLC_FALSE );    add_float( SOUT_CFG_PREFIX "fps", 0, NULL, FPS_TEXT,               FPS_LONGTEXT, VLC_FALSE );    add_bool( SOUT_CFG_PREFIX "hurry-up", VLC_TRUE, NULL, HURRYUP_TEXT,               HURRYUP_LONGTEXT, VLC_FALSE );    add_bool( SOUT_CFG_PREFIX "deinterlace", 0, NULL, DEINTERLACE_TEXT,              DEINTERLACE_LONGTEXT, VLC_FALSE );    add_string( SOUT_CFG_PREFIX "deinterlace-module", "deinterlace", NULL,                DEINTERLACE_MODULE_TEXT, DEINTERLACE_MODULE_LONGTEXT,                VLC_FALSE );        change_string_list( ppsz_deinterlace_type, 0, 0 );    add_integer( SOUT_CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,                 WIDTH_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,                 HEIGHT_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "maxwidth", 0, NULL, MAXWIDTH_TEXT,                 MAXWIDTH_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "maxheight", 0, NULL, MAXHEIGHT_TEXT,                 MAXHEIGHT_LONGTEXT, VLC_TRUE );    add_module_list_cat( SOUT_CFG_PREFIX "vfilter", SUBCAT_VIDEO_VFILTER,                     NULL, NULL,                     VFILTER_TEXT, VFILTER_LONGTEXT, VLC_FALSE );    add_integer( SOUT_CFG_PREFIX "croptop", 0, NULL, CROPTOP_TEXT,                 CROPTOP_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "cropleft", 0, NULL, CROPLEFT_TEXT,                 CROPLEFT_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "cropbottom", 0, NULL, CROPBOTTOM_TEXT,                 CROPBOTTOM_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "cropright", 0, NULL, CROPRIGHT_TEXT,                 CROPRIGHT_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "paddtop", 0, NULL, PADDTOP_TEXT,                 PADDTOP_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "paddleft", 0, NULL, PADDLEFT_TEXT,                 PADDLEFT_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "paddbottom", 0, NULL, PADDBOTTOM_TEXT,                 PADDBOTTOM_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "paddright", 0, NULL, PADDRIGHT_TEXT,                 PADDRIGHT_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "canvas-width", 0, NULL, CANVAS_WIDTH_TEXT,                 CANVAS_WIDTH_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "canvas-height", 0, NULL, CANVAS_HEIGHT_TEXT,                 CANVAS_HEIGHT_LONGTEXT, VLC_TRUE );    add_string( SOUT_CFG_PREFIX "canvas-aspect", NULL, NULL, CANVAS_ASPECT_TEXT,                CANVAS_ASPECT_LONGTEXT, VLC_FALSE );    set_section( N_("Audio"), NULL );    add_string( SOUT_CFG_PREFIX "aenc", NULL, NULL, AENC_TEXT,                AENC_LONGTEXT, VLC_FALSE );    add_string( SOUT_CFG_PREFIX "acodec", NULL, NULL, ACODEC_TEXT,                ACODEC_LONGTEXT, VLC_FALSE );    add_integer( SOUT_CFG_PREFIX "ab", 64000, NULL, AB_TEXT,                 AB_LONGTEXT, VLC_FALSE );    add_integer( SOUT_CFG_PREFIX "channels", 0, NULL, ACHANS_TEXT,                 ACHANS_LONGTEXT, VLC_FALSE );    add_integer( SOUT_CFG_PREFIX "samplerate", 0, NULL, ARATE_TEXT,                 ARATE_LONGTEXT, VLC_TRUE );    add_bool( SOUT_CFG_PREFIX "audio-sync", 0, NULL, ASYNC_TEXT,              ASYNC_LONGTEXT, VLC_FALSE );    set_section( N_("Overlays/Subtitles"), NULL );    add_string( SOUT_CFG_PREFIX "senc", NULL, NULL, SENC_TEXT,                SENC_LONGTEXT, VLC_FALSE );    add_string( SOUT_CFG_PREFIX "scodec", NULL, NULL, SCODEC_TEXT,                SCODEC_LONGTEXT, VLC_FALSE );    add_bool( SOUT_CFG_PREFIX "soverlay", 0, NULL, SCODEC_TEXT,               SCODEC_LONGTEXT, VLC_FALSE );    add_module_list_cat( SOUT_CFG_PREFIX "sfilter", SUBCAT_VIDEO_SUBPIC,                     NULL, NULL,                     SFILTER_TEXT, SFILTER_LONGTEXT, VLC_FALSE );    set_section( N_("On Screen Display"), NULL );    add_bool( SOUT_CFG_PREFIX "osd", 0, NULL, OSD_TEXT,              OSD_LONGTEXT, VLC_FALSE );        set_section( N_("Miscellaneous"), NULL );    add_integer( SOUT_CFG_PREFIX "threads", 0, NULL, THREADS_TEXT,                 THREADS_LONGTEXT, VLC_TRUE );    add_bool( SOUT_CFG_PREFIX "high-priority", 0, NULL, HP_TEXT, HP_LONGTEXT,              VLC_TRUE );vlc_module_end();static const char *ppsz_sout_options[] = {    "venc", "vcodec", "vb", "croptop", "cropbottom", "cropleft", "cropright",    "paddtop", "paddbottom", "paddleft", "paddright",     "canvas-width", "canvas-height", "canvas-aspect",     "scale", "fps", "width", "height", "vfilter", "deinterlace",    "deinterlace-module", "threads", "hurry-up", "aenc", "acodec", "ab",    "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_t *, 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 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_t *, 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 int  EncoderThread( struct sout_stream_sys_t * p_sys );static 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 20struct 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) */

⌨️ 快捷键说明

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