mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-08 13:22:53 +02:00
activated 'raw stream copy' feature (use -acodec copy or -vcodec copy)
Originally committed as revision 1026 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
a5e880583c
commit
1629626f5d
109
ffmpeg.c
109
ffmpeg.c
@ -143,6 +143,8 @@ static int do_vstats = 0;
|
||||
static int mpeg_vcd = 0;
|
||||
static int do_pass = 0;
|
||||
static char *pass_logfilename = NULL;
|
||||
static int audio_stream_copy = 0;
|
||||
static int video_stream_copy = 0;
|
||||
|
||||
#define DEFAULT_PASS_LOGFILENAME "ffmpeg2pass"
|
||||
|
||||
@ -744,17 +746,6 @@ static int av_encode(AVFormatContext **output_files,
|
||||
}
|
||||
}
|
||||
|
||||
/* dump the stream mapping */
|
||||
fprintf(stderr, "Stream mapping:\n");
|
||||
for(i=0;i<nb_ostreams;i++) {
|
||||
ost = ost_table[i];
|
||||
fprintf(stderr, " Stream #%d.%d -> #%d.%d\n",
|
||||
ist_table[ost->source_index]->file_index,
|
||||
ist_table[ost->source_index]->index,
|
||||
ost->file_index,
|
||||
ost->index);
|
||||
}
|
||||
|
||||
/* for each output stream, we compute the right encoding parameters */
|
||||
for(i=0;i<nb_ostreams;i++) {
|
||||
ost = ost_table[i];
|
||||
@ -763,21 +754,28 @@ static int av_encode(AVFormatContext **output_files,
|
||||
codec = &ost->st->codec;
|
||||
icodec = &ist->st->codec;
|
||||
|
||||
if (ost->st->stream_copy) {
|
||||
/* if stream_copy is selected, no need to decode or encode */
|
||||
codec->codec_id = icodec->codec_id;
|
||||
codec->codec_type = icodec->codec_type;
|
||||
codec->codec_tag = icodec->codec_tag;
|
||||
codec->bit_rate = icodec->bit_rate;
|
||||
switch(codec->codec_type) {
|
||||
case CODEC_TYPE_AUDIO:
|
||||
/* check if same codec with same parameters. If so, no
|
||||
reencoding is needed */
|
||||
if (codec->codec_id == icodec->codec_id &&
|
||||
codec->bit_rate == icodec->bit_rate &&
|
||||
codec->sample_rate == icodec->sample_rate &&
|
||||
codec->channels == icodec->channels) {
|
||||
/* no reencoding */
|
||||
/* use the same frame size */
|
||||
codec->frame_size = icodec->frame_size;
|
||||
//codec->frame_size = 8*icodec->sample_rate*icodec->frame_size/
|
||||
// icodec->bit_rate;
|
||||
//fprintf(stderr,"\nFrame size: %d", codec->frame_size);
|
||||
codec->sample_rate = icodec->sample_rate;
|
||||
codec->channels = icodec->channels;
|
||||
break;
|
||||
case CODEC_TYPE_VIDEO:
|
||||
codec->frame_rate = icodec->frame_rate;
|
||||
codec->width = icodec->width;
|
||||
codec->height = icodec->height;
|
||||
break;
|
||||
default:
|
||||
av_abort();
|
||||
}
|
||||
} else {
|
||||
switch(codec->codec_type) {
|
||||
case CODEC_TYPE_AUDIO:
|
||||
if (fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE))
|
||||
goto fail;
|
||||
|
||||
@ -810,18 +808,8 @@ static int av_encode(AVFormatContext **output_files,
|
||||
}
|
||||
ist->decoding_needed = 1;
|
||||
ost->encoding_needed = 1;
|
||||
}
|
||||
break;
|
||||
case CODEC_TYPE_VIDEO:
|
||||
/* check if same codec with same parameters. If so, no
|
||||
reencoding is needed */
|
||||
if (codec->codec_id == icodec->codec_id &&
|
||||
codec->bit_rate == icodec->bit_rate &&
|
||||
codec->frame_rate == icodec->frame_rate &&
|
||||
codec->width == icodec->width &&
|
||||
codec->height == icodec->height) {
|
||||
/* no reencoding */
|
||||
} else {
|
||||
if (codec->width == icodec->width &&
|
||||
codec->height == icodec->height) {
|
||||
ost->video_resample = 0;
|
||||
@ -846,7 +834,6 @@ static int av_encode(AVFormatContext **output_files,
|
||||
}
|
||||
ost->encoding_needed = 1;
|
||||
ist->decoding_needed = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
av_abort();
|
||||
@ -891,6 +878,24 @@ static int av_encode(AVFormatContext **output_files,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* dump the file output parameters - cannot be done before in case
|
||||
of stream copy */
|
||||
for(i=0;i<nb_output_files;i++) {
|
||||
dump_format(output_files[i], i, output_files[i]->filename, 1);
|
||||
}
|
||||
|
||||
/* dump the stream mapping */
|
||||
fprintf(stderr, "Stream mapping:\n");
|
||||
for(i=0;i<nb_ostreams;i++) {
|
||||
ost = ost_table[i];
|
||||
fprintf(stderr, " Stream #%d.%d -> #%d.%d\n",
|
||||
ist_table[ost->source_index]->file_index,
|
||||
ist_table[ost->source_index]->index,
|
||||
ost->file_index,
|
||||
ost->index);
|
||||
}
|
||||
|
||||
/* open each encoder */
|
||||
for(i=0;i<nb_ostreams;i++) {
|
||||
@ -1666,6 +1671,9 @@ void opt_audio_codec(const char *arg)
|
||||
{
|
||||
AVCodec *p;
|
||||
|
||||
if (!strcmp(arg, "copy")) {
|
||||
audio_stream_copy = 1;
|
||||
} else {
|
||||
p = first_avcodec;
|
||||
while (p) {
|
||||
if (!strcmp(p->name, arg) && p->type == CODEC_TYPE_AUDIO)
|
||||
@ -1679,6 +1687,7 @@ void opt_audio_codec(const char *arg)
|
||||
audio_codec_id = p->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char *motion_str[] = {
|
||||
"zero",
|
||||
@ -1710,6 +1719,9 @@ void opt_video_codec(const char *arg)
|
||||
{
|
||||
AVCodec *p;
|
||||
|
||||
if (!strcmp(arg, "copy")) {
|
||||
video_stream_copy = 1;
|
||||
} else {
|
||||
p = first_avcodec;
|
||||
while (p) {
|
||||
if (!strcmp(p->name, arg) && p->type == CODEC_TYPE_VIDEO)
|
||||
@ -1723,6 +1735,7 @@ void opt_video_codec(const char *arg)
|
||||
video_codec_id = p->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void opt_map(const char *arg)
|
||||
{
|
||||
@ -1921,14 +1934,17 @@ void opt_output_file(const char *filename)
|
||||
fprintf(stderr, "Could not alloc stream\n");
|
||||
exit(1);
|
||||
}
|
||||
video_enc = &st->codec;
|
||||
|
||||
video_enc = &st->codec;
|
||||
if (video_stream_copy) {
|
||||
st->stream_copy = 1;
|
||||
video_enc->codec_type = CODEC_TYPE_VIDEO;
|
||||
} else {
|
||||
codec_id = file_oformat->video_codec;
|
||||
if (video_codec_id != CODEC_ID_NONE)
|
||||
codec_id = video_codec_id;
|
||||
|
||||
video_enc->codec_id = codec_id;
|
||||
video_enc->codec_type = CODEC_TYPE_VIDEO;
|
||||
|
||||
video_enc->bit_rate = video_bit_rate;
|
||||
video_enc->bit_rate_tolerance = video_bit_rate_tolerance;
|
||||
@ -1936,6 +1952,7 @@ void opt_output_file(const char *filename)
|
||||
|
||||
video_enc->width = frame_width;
|
||||
video_enc->height = frame_height;
|
||||
|
||||
if (!intra_only)
|
||||
video_enc->gop_size = gop_size;
|
||||
else
|
||||
@ -2009,7 +2026,7 @@ void opt_output_file(const char *filename)
|
||||
if (oc->oformat->flags & AVFMT_RGB24) {
|
||||
video_enc->pix_fmt = PIX_FMT_RGB24;
|
||||
}
|
||||
|
||||
}
|
||||
oc->streams[nb_streams] = st;
|
||||
nb_streams++;
|
||||
}
|
||||
@ -2022,12 +2039,16 @@ void opt_output_file(const char *filename)
|
||||
fprintf(stderr, "Could not alloc stream\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
audio_enc = &st->codec;
|
||||
audio_enc->codec_type = CODEC_TYPE_AUDIO;
|
||||
if (audio_stream_copy) {
|
||||
st->stream_copy = 1;
|
||||
} else {
|
||||
codec_id = file_oformat->audio_codec;
|
||||
if (audio_codec_id != CODEC_ID_NONE)
|
||||
codec_id = audio_codec_id;
|
||||
audio_enc->codec_id = codec_id;
|
||||
audio_enc->codec_type = CODEC_TYPE_AUDIO;
|
||||
|
||||
audio_enc->bit_rate = audio_bit_rate;
|
||||
audio_enc->sample_rate = audio_sample_rate;
|
||||
@ -2037,6 +2058,7 @@ void opt_output_file(const char *filename)
|
||||
audio_enc->channels = 2;
|
||||
} else
|
||||
audio_enc->channels = audio_channels;
|
||||
}
|
||||
oc->streams[nb_streams] = st;
|
||||
nb_streams++;
|
||||
}
|
||||
@ -2058,10 +2080,7 @@ void opt_output_file(const char *filename)
|
||||
pstrcpy(oc->comment, sizeof(oc->comment), str_comment);
|
||||
}
|
||||
|
||||
output_files[nb_output_files] = oc;
|
||||
/* dump the file content */
|
||||
dump_format(oc, nb_output_files, filename, 1);
|
||||
nb_output_files++;
|
||||
output_files[nb_output_files++] = oc;
|
||||
|
||||
strcpy(oc->filename, filename);
|
||||
|
||||
@ -2105,6 +2124,8 @@ void opt_output_file(const char *filename)
|
||||
video_disable = 0;
|
||||
audio_codec_id = CODEC_ID_NONE;
|
||||
video_codec_id = CODEC_ID_NONE;
|
||||
audio_stream_copy = 0;
|
||||
video_stream_copy = 0;
|
||||
}
|
||||
|
||||
/* prepare dummy protocols for grab */
|
||||
@ -2367,7 +2388,7 @@ const OptionDef options[] = {
|
||||
{ "minrate", HAS_ARG, {(void*)opt_video_bitrate_min}, "set min video bitrate tolerance (in kbit/s)", "bitrate" },
|
||||
{ "bufsize", HAS_ARG, {(void*)opt_video_buffer_size}, "set ratecontrol buffere size (in kbit)", "size" },
|
||||
{ "vd", HAS_ARG | OPT_EXPERT, {(void*)opt_video_device}, "set video grab device", "device" },
|
||||
{ "vcodec", HAS_ARG | OPT_EXPERT, {(void*)opt_video_codec}, "force video codec", "codec" },
|
||||
{ "vcodec", HAS_ARG | OPT_EXPERT, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" },
|
||||
{ "me", HAS_ARG | OPT_EXPERT, {(void*)opt_motion_estimation}, "set motion estimation method",
|
||||
"method" },
|
||||
{ "dct_algo", HAS_ARG | OPT_EXPERT, {(void*)opt_dct_algo}, "set dct algo", "algo" },
|
||||
@ -2387,7 +2408,7 @@ const OptionDef options[] = {
|
||||
{ "ac", HAS_ARG, {(void*)opt_audio_channels}, "set number of audio channels", "channels" },
|
||||
{ "an", OPT_BOOL, {(void*)&audio_disable}, "disable audio" },
|
||||
{ "ad", HAS_ARG | OPT_EXPERT, {(void*)opt_audio_device}, "set audio device", "device" },
|
||||
{ "acodec", HAS_ARG | OPT_EXPERT, {(void*)opt_audio_codec}, "force audio codec", "codec" },
|
||||
{ "acodec", HAS_ARG | OPT_EXPERT, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" },
|
||||
{ "deinterlace", OPT_BOOL | OPT_EXPERT, {(void*)&do_deinterlace},
|
||||
"deinterlace pictures" },
|
||||
{ "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark},
|
||||
|
Loading…
Reference in New Issue
Block a user