kopia lustrzana https://github.com/F5OEO/tstools
(Version of) patch from Richard Watts: allow forcing of MPEG2 or MPEG4 ADTS in
esmerge. --HG-- extra : convert_revision : svn%3Aeff31bef-be4a-0410-a8fe-e47997df2690/trunk%4019issue20
rodzic
3c0dac2bb5
commit
633ef0ed27
19
adts.c
19
adts.c
|
@ -45,12 +45,15 @@
|
|||
*
|
||||
* - `file` is the file descriptor of the ADTS file to read from
|
||||
* - `frame` is the ADTS frame that is read
|
||||
* - `flags` indicates if we are forcing the recognition of "emphasis"
|
||||
* fields, etc.
|
||||
*
|
||||
* Returns 0 if all goes well, EOF if end-of-file is read, and 1 if something
|
||||
* goes wrong.
|
||||
*/
|
||||
extern int read_next_adts_frame(int file,
|
||||
audio_frame_p *frame)
|
||||
audio_frame_p *frame,
|
||||
unsigned int flags)
|
||||
{
|
||||
#define JUST_ENOUGH 6 // just enough to hold the bits of the headers we want
|
||||
|
||||
|
@ -59,6 +62,7 @@ extern int read_next_adts_frame(int file,
|
|||
byte header[JUST_ENOUGH];
|
||||
byte *data = NULL;
|
||||
int frame_length;
|
||||
int has_emphasis = 0;
|
||||
|
||||
offset_t posn = tell_file(file);
|
||||
#if DEBUG
|
||||
|
@ -102,16 +106,21 @@ extern int read_next_adts_frame(int file,
|
|||
printf(" layer is %d, not 0 (in frame at " OFFSET_T_FORMAT ")\n",
|
||||
layer,posn);
|
||||
|
||||
if (id == 1)
|
||||
// Experience appears to show that emphasis doesn't exist in MPEG-2 AVC.
|
||||
// But it does exist in (ID=1) MPEG-4 streams.
|
||||
//
|
||||
// .. or if forced.
|
||||
|
||||
has_emphasis = (flags & ADTS_FLAG_NO_EMPHASIS) ? 0 :
|
||||
((flags & ADTS_FLAG_FORCE_EMPHASIS) || !id);
|
||||
|
||||
if (!has_emphasis)
|
||||
{
|
||||
// We assume the Emphasis field is not present
|
||||
// (experience appears to show that it is not used for MPEG-2 AVC)
|
||||
frame_length = ((header[3] & 0x03) << 11) | (header[4] << 3) |
|
||||
((unsigned)(header[5] & 0xE0) >> 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We assume the Emphasis field *is* present
|
||||
frame_length = (header[4] << 5) | ((unsigned)(header[5] & 0xF8) >> 3);
|
||||
}
|
||||
#if DEBUG
|
||||
|
|
11
adts_defns.h
11
adts_defns.h
|
@ -32,6 +32,17 @@
|
|||
#include "audio_defns.h"
|
||||
// AAC ADTS provides audio in frames of constant time
|
||||
|
||||
// Flags for ``read_next_adts_frame``
|
||||
//
|
||||
// Specify this flag to indicate that there is no emphasis field in the ADTS
|
||||
// header. Generally, MPEG-2 ADTS audio (ID=0) has no emphasis field and
|
||||
// MPEG-4 (ID=1) has emphasis, but some H.264/AAC streams have MPEG-4 ADTS
|
||||
// with no emphasis and in those cases, you'll need this flag.
|
||||
#define ADTS_FLAG_NO_EMPHASIS (1<<0)
|
||||
// Specify this flag to indicate that there is always an emphasis field, even
|
||||
// if the ID says there isn't one - included for symmetry with NO_EMPHASIS.
|
||||
#define ADTS_FLAG_FORCE_EMPHASIS (1<<1)
|
||||
|
||||
#endif // _adts_defns
|
||||
|
||||
// Local Variables:
|
||||
|
|
|
@ -39,12 +39,15 @@
|
|||
*
|
||||
* - `file` is the file descriptor of the ADTS file to read from
|
||||
* - `frame` is the ADTS frame that is read
|
||||
* - `flags` indicates if we are forcing the recognition of "emphasis"
|
||||
* fields, etc.
|
||||
*
|
||||
* Returns 0 if all goes well, EOF if end-of-file is read, and 1 if something
|
||||
* goes wrong.
|
||||
*/
|
||||
extern int read_next_adts_frame(int file,
|
||||
audio_frame_p *frame);
|
||||
audio_frame_p *frame,
|
||||
unsigned int flags);
|
||||
|
||||
|
||||
#endif // _adts_fns
|
||||
|
|
6
audio.c
6
audio.c
|
@ -98,8 +98,12 @@ extern int read_next_audio_frame(int file,
|
|||
{
|
||||
switch (audio_type)
|
||||
{
|
||||
case AUDIO_ADTS_MPEG2:
|
||||
return read_next_adts_frame(file,frame,ADTS_FLAG_NO_EMPHASIS);
|
||||
case AUDIO_ADTS_MPEG4:
|
||||
return read_next_adts_frame(file,frame,ADTS_FLAG_FORCE_EMPHASIS);
|
||||
case AUDIO_ADTS:
|
||||
return read_next_adts_frame(file,frame);
|
||||
return read_next_adts_frame(file,frame,0);
|
||||
case AUDIO_L2:
|
||||
return read_next_l2audio_frame(file,frame);
|
||||
default:
|
||||
|
|
|
@ -46,6 +46,9 @@ typedef struct audio_frame *audio_frame_p;
|
|||
#define AUDIO_ADTS ADTS_AUDIO_STREAM_TYPE
|
||||
#define AUDIO_L2 MPEG2_AUDIO_STREAM_TYPE
|
||||
|
||||
#define AUDIO_ADTS_MPEG2 0x100
|
||||
#define AUDIO_ADTS_MPEG4 0x101
|
||||
|
||||
#define AUDIO_STR(x) ((x)==AUDIO_UNKNOWN?"unknown": \
|
||||
(x)==AUDIO_ADTS ?"ADTS": \
|
||||
(x)==AUDIO_L2 ?"MPEG2": \
|
||||
|
|
14
esmerge.c
14
esmerge.c
|
@ -178,6 +178,8 @@ static int merge_with_avs(avs_context_p video_context,
|
|||
switch (audio_type)
|
||||
{
|
||||
case AUDIO_ADTS:
|
||||
case AUDIO_ADTS_MPEG2:
|
||||
case AUDIO_ADTS_MPEG4:
|
||||
prog_type[1] = ADTS_AUDIO_STREAM_TYPE;
|
||||
break;
|
||||
case AUDIO_L2:
|
||||
|
@ -392,6 +394,8 @@ static int merge_with_h264(access_unit_context_p video_context,
|
|||
switch (audio_type)
|
||||
{
|
||||
case AUDIO_ADTS:
|
||||
case AUDIO_ADTS_MPEG2:
|
||||
case AUDIO_ADTS_MPEG4:
|
||||
prog_type[1] = ADTS_AUDIO_STREAM_TYPE;
|
||||
break;
|
||||
case AUDIO_L2:
|
||||
|
@ -570,6 +574,8 @@ static void print_usage()
|
|||
"\n"
|
||||
" -adts The audio stream is ADTS (the default)\n"
|
||||
" -l2 The audio stream is MPEG layer 2 audio\n"
|
||||
" -mp2adts The audio stream is MPEG-2 style ADTS regardless of ID bit\n"
|
||||
" -mp4adts The audio stream is MPEG-4 style ADTS regardless of ID bit\n"
|
||||
"\n"
|
||||
"Limitations\n"
|
||||
"===========\n"
|
||||
|
@ -671,6 +677,14 @@ int main(int argc, char **argv)
|
|||
{
|
||||
video_type = VIDEO_H264;
|
||||
}
|
||||
else if (!strcmp("-mp2adts", argv[ii]))
|
||||
{
|
||||
audio_type = AUDIO_ADTS_MPEG2;
|
||||
}
|
||||
else if (!strcmp("-mp4adts", argv[ii]))
|
||||
{
|
||||
audio_type = AUDIO_ADTS_MPEG4;
|
||||
}
|
||||
else if (!strcmp("-avs",argv[ii]))
|
||||
{
|
||||
video_type = VIDEO_AVS;
|
||||
|
|
Ładowanie…
Reference in New Issue