Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
86bbdf86
Commit
86bbdf86
authored
Sep 30, 2012
by
Luca Barbato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avformat: refactor avformat_write_header
Mostly cosmetic changes adding some intermediate to shorten the lines.
parent
55f9037f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
27 deletions
+42
-27
mux.c
libavformat/mux.c
+42
-27
No files found.
libavformat/mux.c
View file @
86bbdf86
...
@@ -140,88 +140,103 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options)
...
@@ -140,88 +140,103 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options)
int
ret
=
0
,
i
;
int
ret
=
0
,
i
;
AVStream
*
st
;
AVStream
*
st
;
AVDictionary
*
tmp
=
NULL
;
AVDictionary
*
tmp
=
NULL
;
AVCodecContext
*
codec
=
NULL
;
AVOutputFormat
*
of
=
s
->
oformat
;
if
(
options
)
if
(
options
)
av_dict_copy
(
&
tmp
,
*
options
,
0
);
av_dict_copy
(
&
tmp
,
*
options
,
0
);
if
((
ret
=
av_opt_set_dict
(
s
,
&
tmp
))
<
0
)
if
((
ret
=
av_opt_set_dict
(
s
,
&
tmp
))
<
0
)
goto
fail
;
goto
fail
;
// some sanity checks
// some sanity checks
if
(
s
->
nb_streams
==
0
&&
!
(
s
->
oformat
->
flags
&
AVFMT_NOSTREAMS
))
{
if
(
s
->
nb_streams
==
0
&&
!
(
of
->
flags
&
AVFMT_NOSTREAMS
))
{
av_log
(
s
,
AV_LOG_ERROR
,
"no streams
\n
"
);
av_log
(
s
,
AV_LOG_ERROR
,
"no streams
\n
"
);
ret
=
AVERROR
(
EINVAL
);
ret
=
AVERROR
(
EINVAL
);
goto
fail
;
goto
fail
;
}
}
for
(
i
=
0
;
i
<
s
->
nb_streams
;
i
++
)
{
for
(
i
=
0
;
i
<
s
->
nb_streams
;
i
++
)
{
st
=
s
->
streams
[
i
];
st
=
s
->
streams
[
i
];
codec
=
st
->
codec
;
switch
(
st
->
codec
->
codec_type
)
{
switch
(
codec
->
codec_type
)
{
case
AVMEDIA_TYPE_AUDIO
:
case
AVMEDIA_TYPE_AUDIO
:
if
(
st
->
codec
->
sample_rate
<=
0
)
{
if
(
codec
->
sample_rate
<=
0
)
{
av_log
(
s
,
AV_LOG_ERROR
,
"sample rate not set
\n
"
);
av_log
(
s
,
AV_LOG_ERROR
,
"sample rate not set
\n
"
);
ret
=
AVERROR
(
EINVAL
);
ret
=
AVERROR
(
EINVAL
);
goto
fail
;
goto
fail
;
}
}
if
(
!
st
->
codec
->
block_align
)
if
(
!
codec
->
block_align
)
st
->
codec
->
block_align
=
st
->
codec
->
channels
*
codec
->
block_align
=
codec
->
channels
*
av_get_bits_per_sample
(
st
->
codec
->
codec_id
)
>>
3
;
av_get_bits_per_sample
(
codec
->
codec_id
)
>>
3
;
break
;
break
;
case
AVMEDIA_TYPE_VIDEO
:
case
AVMEDIA_TYPE_VIDEO
:
if
(
st
->
codec
->
time_base
.
num
<=
0
||
st
->
codec
->
time_base
.
den
<=
0
)
{
//FIXME audio too?
if
(
codec
->
time_base
.
num
<=
0
||
codec
->
time_base
.
den
<=
0
)
{
//FIXME audio too?
av_log
(
s
,
AV_LOG_ERROR
,
"time base not set
\n
"
);
av_log
(
s
,
AV_LOG_ERROR
,
"time base not set
\n
"
);
ret
=
AVERROR
(
EINVAL
);
ret
=
AVERROR
(
EINVAL
);
goto
fail
;
goto
fail
;
}
}
if
((
st
->
codec
->
width
<=
0
||
st
->
codec
->
height
<=
0
)
&&
!
(
s
->
oformat
->
flags
&
AVFMT_NODIMENSIONS
))
{
if
((
codec
->
width
<=
0
||
codec
->
height
<=
0
)
&&
!
(
of
->
flags
&
AVFMT_NODIMENSIONS
))
{
av_log
(
s
,
AV_LOG_ERROR
,
"dimensions not set
\n
"
);
av_log
(
s
,
AV_LOG_ERROR
,
"dimensions not set
\n
"
);
ret
=
AVERROR
(
EINVAL
);
ret
=
AVERROR
(
EINVAL
);
goto
fail
;
goto
fail
;
}
}
if
(
av_cmp_q
(
st
->
sample_aspect_ratio
,
st
->
codec
->
sample_aspect_ratio
))
{
if
(
av_cmp_q
(
st
->
sample_aspect_ratio
,
codec
->
sample_aspect_ratio
))
{
av_log
(
s
,
AV_LOG_ERROR
,
"Aspect ratio mismatch between muxer "
av_log
(
s
,
AV_LOG_ERROR
,
"Aspect ratio mismatch between muxer "
"(%d/%d) and encoder layer (%d/%d)
\n
"
,
"(%d/%d) and encoder layer (%d/%d)
\n
"
,
st
->
sample_aspect_ratio
.
num
,
st
->
sample_aspect_ratio
.
den
,
st
->
sample_aspect_ratio
.
num
,
st
->
sample_aspect_ratio
.
den
,
st
->
codec
->
sample_aspect_ratio
.
num
,
codec
->
sample_aspect_ratio
.
num
,
st
->
codec
->
sample_aspect_ratio
.
den
);
codec
->
sample_aspect_ratio
.
den
);
ret
=
AVERROR
(
EINVAL
);
ret
=
AVERROR
(
EINVAL
);
goto
fail
;
goto
fail
;
}
}
break
;
break
;
}
}
if
(
s
->
oformat
->
codec_tag
)
{
if
(
of
->
codec_tag
)
{
if
(
st
->
codec
->
codec_tag
&&
st
->
codec
->
codec_id
==
AV_CODEC_ID_RAWVIDEO
&&
av_codec_get_tag
(
s
->
oformat
->
codec_tag
,
st
->
codec
->
codec_id
)
==
0
&&
!
validate_codec_tag
(
s
,
st
))
{
if
(
codec
->
codec_tag
&&
//the current rawvideo encoding system ends up setting the wrong codec_tag for avi, we override it here
codec
->
codec_id
==
AV_CODEC_ID_RAWVIDEO
&&
st
->
codec
->
codec_tag
=
0
;
!
av_codec_get_tag
(
of
->
codec_tag
,
codec
->
codec_id
)
&&
!
validate_codec_tag
(
s
,
st
))
{
// the current rawvideo encoding system ends up setting
// the wrong codec_tag for avi, we override it here
codec
->
codec_tag
=
0
;
}
}
if
(
st
->
codec
->
codec_tag
)
{
if
(
codec
->
codec_tag
)
{
if
(
!
validate_codec_tag
(
s
,
st
))
{
if
(
!
validate_codec_tag
(
s
,
st
))
{
char
tagbuf
[
32
];
char
tagbuf
[
32
];
av_get_codec_tag_string
(
tagbuf
,
sizeof
(
tagbuf
),
st
->
codec
->
codec_tag
);
av_get_codec_tag_string
(
tagbuf
,
sizeof
(
tagbuf
),
codec
->
codec_tag
);
av_log
(
s
,
AV_LOG_ERROR
,
av_log
(
s
,
AV_LOG_ERROR
,
"Tag %s/0x%08x incompatible with output codec id '%d'
\n
"
,
"Tag %s/0x%08x incompatible with output codec id '%d'
\n
"
,
tagbuf
,
st
->
codec
->
codec_tag
,
st
->
codec
->
codec_id
);
tagbuf
,
codec
->
codec_tag
,
codec
->
codec_id
);
ret
=
AVERROR_INVALIDDATA
;
ret
=
AVERROR_INVALIDDATA
;
goto
fail
;
goto
fail
;
}
}
}
else
}
else
st
->
codec
->
codec_tag
=
av_codec_get_tag
(
s
->
oformat
->
codec_tag
,
st
->
codec
->
codec_id
);
codec
->
codec_tag
=
av_codec_get_tag
(
of
->
codec_tag
,
codec
->
codec_id
);
}
}
if
(
s
->
oformat
->
flags
&
AVFMT_GLOBALHEADER
&&
if
(
of
->
flags
&
AVFMT_GLOBALHEADER
&&
!
(
st
->
codec
->
flags
&
CODEC_FLAG_GLOBAL_HEADER
))
!
(
codec
->
flags
&
CODEC_FLAG_GLOBAL_HEADER
))
av_log
(
s
,
AV_LOG_WARNING
,
"Codec for stream %d does not use global headers but container format requires global headers
\n
"
,
i
);
av_log
(
s
,
AV_LOG_WARNING
,
"Codec for stream %d does not use global headers "
"but container format requires global headers
\n
"
,
i
);
}
}
if
(
!
s
->
priv_data
&&
s
->
oformat
->
priv_data_size
>
0
)
{
if
(
!
s
->
priv_data
&&
of
->
priv_data_size
>
0
)
{
s
->
priv_data
=
av_mallocz
(
s
->
oformat
->
priv_data_size
);
s
->
priv_data
=
av_mallocz
(
of
->
priv_data_size
);
if
(
!
s
->
priv_data
)
{
if
(
!
s
->
priv_data
)
{
ret
=
AVERROR
(
ENOMEM
);
ret
=
AVERROR
(
ENOMEM
);
goto
fail
;
goto
fail
;
}
}
if
(
s
->
oformat
->
priv_class
)
{
if
(
of
->
priv_class
)
{
*
(
const
AVClass
**
)
s
->
priv_data
=
s
->
oformat
->
priv_class
;
*
(
const
AVClass
**
)
s
->
priv_data
=
of
->
priv_class
;
av_opt_set_defaults
(
s
->
priv_data
);
av_opt_set_defaults
(
s
->
priv_data
);
if
((
ret
=
av_opt_set_dict
(
s
->
priv_data
,
&
tmp
))
<
0
)
if
((
ret
=
av_opt_set_dict
(
s
->
priv_data
,
&
tmp
))
<
0
)
goto
fail
;
goto
fail
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment