On date Thursday 2011-04-14 13:32:36 +0200, Luca Barbato wrote:
> The patch is the first step to support -dcodec copy
> ---
> cmdutils.h | 1 +
> ffmpeg.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++----
> libavformat/riff.c | 1 +
> 3 files changed, 80 insertions(+), 7 deletions(-)
>
> diff --git a/cmdutils.h b/cmdutils.h
> index 0067295..0a61efb 100644
> --- a/cmdutils.h
> +++ b/cmdutils.h
> @@ -122,6 +122,7 @@ typedef struct {
> #define OPT_FUNC2 0x0400
> #define OPT_INT64 0x0800
> #define OPT_EXIT 0x1000
> +#define OPT_DATA 0x2000
> union {
> void (*func_arg)(const char *); //FIXME passing error code as int
> return would be nicer then exit() in the func
> int *int_arg;
> diff --git a/ffmpeg.c b/ffmpeg.c
> index 80d2cca..2cf9bdd 100644
> --- a/ffmpeg.c
> +++ b/ffmpeg.c
> @@ -188,6 +188,10 @@ static char *subtitle_codec_name = NULL;
> static char *subtitle_language = NULL;
> static unsigned int subtitle_codec_tag = 0;
>
> +static int data_disable = 0;
> +static char *data_codec_name = NULL;
> +static unsigned int data_codec_tag = 0;
> +
> static float mux_preload= 0.5;
> static float mux_max_delay= 0.7;
>
> @@ -206,6 +210,7 @@ static char *pass_logfilename_prefix = NULL;
> static int audio_stream_copy = 0;
> static int video_stream_copy = 0;
> static int subtitle_stream_copy = 0;
> +static int data_stream_copy = 0;
> static int video_sync_method= -1;
> static int audio_sync_method= 0;
> static float audio_drift_threshold= 0.1;
> @@ -482,6 +487,7 @@ static int ffmpeg_exit(int ret)
> av_free(video_codec_name);
> av_free(audio_codec_name);
> av_free(subtitle_codec_name);
> + av_free(data_codec_name);
>
> av_free(video_standard);
>
> @@ -2127,6 +2133,8 @@ static int transcode(AVFormatContext **output_files,
> codec->width = icodec->width;
> codec->height = icodec->height;
> break;
> + case AVMEDIA_TYPE_DATA:
> + break;
> default:
> abort();
> }
> @@ -2890,6 +2898,11 @@ static void opt_subtitle_codec(const char *arg)
> opt_codec(&subtitle_stream_copy, &subtitle_codec_name,
> AVMEDIA_TYPE_SUBTITLE, arg);
> }
>
> +static void opt_data_codec(const char *arg)
> +{
> + opt_codec(&data_stream_copy, &data_codec_name, AVMEDIA_TYPE_DATA, arg);
> +}
> +
> static int opt_codec_tag(const char *opt, const char *arg)
> {
> char *tail;
> @@ -3283,15 +3296,19 @@ static void opt_input_file(const char *filename)
> av_freep(&subtitle_codec_name);
> }
>
> -static void check_audio_video_sub_inputs(int *has_video_ptr, int
> *has_audio_ptr,
> - int *has_subtitle_ptr)
> +static void check_inputs(int *has_video_ptr,
> + int *has_audio_ptr,
> + int *has_subtitle_ptr,
> + int *has_data_ptr)
> {
> - int has_video, has_audio, has_subtitle, i, j;
> + int has_video, has_audio, has_subtitle, has_data, i, j;
> AVFormatContext *ic;
>
> has_video = 0;
> has_audio = 0;
> has_subtitle = 0;
> + has_data = 0;
> +
> for(j=0;j<nb_input_files;j++) {
> ic = input_files[j];
> for(i=0;i<ic->nb_streams;i++) {
> @@ -3309,6 +3326,7 @@ static void check_audio_video_sub_inputs(int
> *has_video_ptr, int *has_audio_ptr,
> case AVMEDIA_TYPE_DATA:
> case AVMEDIA_TYPE_ATTACHMENT:
> case AVMEDIA_TYPE_UNKNOWN:
> + has_data = 1;
Potentially wrong, as ATTACHMENT and UNKNOWN are tagged as data.
> break;
> default:
> abort();
> @@ -3318,6 +3336,7 @@ static void check_audio_video_sub_inputs(int
> *has_video_ptr, int *has_audio_ptr,
> *has_video_ptr = has_video;
> *has_audio_ptr = has_audio;
> *has_subtitle_ptr = has_subtitle;
> + *has_data_ptr = has_data;
> }
>
> static void new_video_stream(AVFormatContext *oc, int file_idx)
> @@ -3544,6 +3563,44 @@ static void new_audio_stream(AVFormatContext *oc, int
> file_idx)
> audio_stream_copy = 0;
> }
>
> +static void new_data_stream(AVFormatContext *oc, int file_idx)
> +{
> + AVStream *st;
> + AVOutputStream *ost;
> + AVCodec *codec=NULL;
> + AVCodecContext *data_enc;
> +
> + st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ?
> streamid_map[oc->nb_streams] : 0);
> + if (!st) {
> + fprintf(stderr, "Could not alloc stream\n");
> + ffmpeg_exit(1);
> + }
> + ost = new_output_stream(oc, file_idx);
> + data_enc = st->codec;
> + output_codecs = grow_array(output_codecs, sizeof(*output_codecs),
> &nb_output_codecs, nb_output_codecs + 1);
> + if(!data_stream_copy){
Nit: K&R
> + ffmpeg_exit(1);
An error message may be useful
> + }
> + avcodec_get_context_defaults3(st->codec, codec);
> +
> + data_enc->codec_type = AVMEDIA_TYPE_DATA;
> +
> + if(data_codec_tag)
Nit++: K&R
> + data_enc->codec_tag= data_codec_tag;
> +
> + if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
> + data_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
> + avcodec_opts[AVMEDIA_TYPE_DATA]->flags |= CODEC_FLAG_GLOBAL_HEADER;
> + }
> + if (data_stream_copy) {
> + st->stream_copy = 1;
> + }
> +
> + data_disable = 0;
> + av_freep(&data_codec_name);
> + data_stream_copy = 0;
> +}
> +
> static void new_subtitle_stream(AVFormatContext *oc, int file_idx)
> {
> AVStream *st;
> @@ -3614,6 +3671,7 @@ static int opt_new_stream(const char *opt, const char
> *arg)
> if (!strcmp(opt, "newvideo" )) new_video_stream (oc, file_idx);
> else if (!strcmp(opt, "newaudio" )) new_audio_stream (oc, file_idx);
> else if (!strcmp(opt, "newsubtitle")) new_subtitle_stream(oc, file_idx);
> + else if (!strcmp(opt, "newdata")) new_data_stream(oc, file_idx);
please keep vertical align
> else av_assert0(0);
> return 0;
> }
> @@ -3644,8 +3702,8 @@ static int opt_streamid(const char *opt, const char
> *arg)
> static void opt_output_file(const char *filename)
> {
> AVFormatContext *oc;
> - int err, use_video, use_audio, use_subtitle;
> - int input_has_video, input_has_audio, input_has_subtitle;
> + int err, use_video, use_audio, use_subtitle, use_data;
> + int input_has_video, input_has_audio, input_has_subtitle, input_has_data;
> AVFormatParameters params, *ap = ¶ms;
> AVOutputFormat *file_oformat;
>
> @@ -3690,28 +3748,37 @@ static void opt_output_file(const char *filename)
> use_video = file_oformat->video_codec != CODEC_ID_NONE ||
> video_stream_copy || video_codec_name;
> use_audio = file_oformat->audio_codec != CODEC_ID_NONE ||
> audio_stream_copy || audio_codec_name;
> use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE ||
> subtitle_stream_copy || subtitle_codec_name;
> + use_data = data_stream_copy || data_codec_name; /* XXX once generic
> data codec will be available add a ->data_codec reference and use it here */
>
> /* disable if no corresponding type found and at least one
> input file */
> if (nb_input_files > 0) {
> - check_audio_video_sub_inputs(&input_has_video, &input_has_audio,
> - &input_has_subtitle);
> + check_inputs(&input_has_video,
> + &input_has_audio,
> + &input_has_subtitle,
> + &input_has_data);
> +
> if (!input_has_video)
> use_video = 0;
> if (!input_has_audio)
> use_audio = 0;
> if (!input_has_subtitle)
> use_subtitle = 0;
> + if (!input_has_data)
> + use_data = 0;
> }
>
> /* manual disable */
> if (audio_disable) use_audio = 0;
> if (video_disable) use_video = 0;
> if (subtitle_disable) use_subtitle = 0;
> + if (data_disable) use_data = 0;
> +
Nit+++: double empty line
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel