1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001-2009 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 /* TODO: add OpenDML write support */
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
37 #include <vlc_block.h>
38 #include <vlc_codecs.h>
40 /*****************************************************************************
42 *****************************************************************************/
43 static int Open ( vlc_object_t
* );
44 static void Close ( vlc_object_t
* );
47 set_description( N_("AVI muxer") )
48 set_category( CAT_SOUT
)
49 set_subcategory( SUBCAT_SOUT_MUX
)
50 set_capability( "sout mux", 5 )
52 set_callbacks( Open
, Close
)
56 /*****************************************************************************
58 *****************************************************************************/
59 static int Control( sout_mux_t
*, int, va_list );
60 static int AddStream( sout_mux_t
*, sout_input_t
* );
61 static int DelStream( sout_mux_t
*, sout_input_t
* );
62 static int Mux ( sout_mux_t
* );
64 typedef struct avi_stream_s
70 mtime_t i_duration
; // in µs
72 int i_frames
; // total frame count
73 int64_t i_totalsize
; // total stream size
78 BITMAPINFOHEADER
*p_bih
;
83 typedef struct avi_idx1_entry_s
92 typedef struct avi_idx1_s
94 unsigned int i_entry_count
;
95 unsigned int i_entry_max
;
97 avi_idx1_entry_t
*entry
;
100 struct sout_mux_sys_t
108 avi_stream_t stream
[100];
116 #define HDR_SIZE 10240
119 #define AVIF_HASINDEX 0x00000010 // Index at end of file?
120 #define AVIF_ISINTERLEAVED 0x00000100
121 #define AVIF_TRUSTCKTYPE 0x00000800 // Use CKType to find key frames?
123 /* Flags for index */
124 #define AVIIF_KEYFRAME 0x00000010L /* this frame is a key frame.*/
127 static block_t
*avi_HeaderCreateRIFF( sout_mux_t
* );
128 static block_t
*avi_HeaderCreateidx1( sout_mux_t
* );
130 static void SetFCC( uint8_t *p
, char *fcc
)
135 /*****************************************************************************
137 *****************************************************************************/
138 static int Open( vlc_object_t
*p_this
)
140 sout_mux_t
*p_mux
= (sout_mux_t
*)p_this
;
141 sout_mux_sys_t
*p_sys
;
143 msg_Dbg( p_mux
, "AVI muxer opened" );
145 p_sys
= malloc( sizeof( sout_mux_sys_t
) );
148 p_sys
->i_streams
= 0;
149 p_sys
->i_stream_video
= -1;
150 p_sys
->i_movi_size
= 0;
152 p_sys
->idx1
.i_entry_count
= 0;
153 p_sys
->idx1
.i_entry_max
= 10000;
154 p_sys
->idx1
.entry
= calloc( p_sys
->idx1
.i_entry_max
,
155 sizeof( avi_idx1_entry_t
) );
156 if( !p_sys
->idx1
.entry
)
161 p_sys
->b_write_header
= true;
164 p_mux
->pf_control
= Control
;
165 p_mux
->pf_addstream
= AddStream
;
166 p_mux
->pf_delstream
= DelStream
;
168 p_mux
->p_sys
= p_sys
;
173 /*****************************************************************************
175 *****************************************************************************/
176 static void Close( vlc_object_t
* p_this
)
178 sout_mux_t
*p_mux
= (sout_mux_t
*)p_this
;
179 sout_mux_sys_t
*p_sys
= p_mux
->p_sys
;
181 block_t
*p_hdr
, *p_idx1
;
184 msg_Dbg( p_mux
, "AVI muxer closed" );
186 /* first create idx1 chunk (write at the end of the stream */
187 p_idx1
= avi_HeaderCreateidx1( p_mux
);
188 p_sys
->i_idx1_size
= p_idx1
->i_buffer
;
189 sout_AccessOutWrite( p_mux
->p_access
, p_idx1
);
191 /* calculate some value for headers creations */
192 for( i_stream
= 0; i_stream
< p_sys
->i_streams
; i_stream
++ )
194 avi_stream_t
*p_stream
;
196 p_stream
= &p_sys
->stream
[i_stream
];
198 p_stream
->f_fps
= 25;
199 if( p_stream
->i_duration
> 0 )
201 p_stream
->f_fps
= (float)p_stream
->i_frames
/
202 ( (float)p_stream
->i_duration
/
205 p_stream
->i_bitrate
= 128 * 1024;
206 if( p_stream
->i_duration
> 0 )
208 p_stream
->i_bitrate
=
209 8 * (uint64_t)1000000 *
210 (uint64_t)p_stream
->i_totalsize
/
211 (uint64_t)p_stream
->i_duration
;
213 msg_Info( p_mux
, "stream[%d] duration:%"PRId64
" totalsize:%"PRId64
214 " frames:%d fps:%f KiB/s:%d",
216 (int64_t)p_stream
->i_duration
/ (int64_t)1000000,
217 p_stream
->i_totalsize
,
219 p_stream
->f_fps
, p_stream
->i_bitrate
/1024 );
222 p_hdr
= avi_HeaderCreateRIFF( p_mux
);
223 sout_AccessOutSeek( p_mux
->p_access
, 0 );
224 sout_AccessOutWrite( p_mux
->p_access
, p_hdr
);
227 static int Control( sout_mux_t
*p_mux
, int i_query
, va_list args
)
235 case MUX_CAN_ADD_STREAM_WHILE_MUXING
:
236 pb_bool
= (bool*)va_arg( args
, bool * );
240 case MUX_GET_ADD_STREAM_WAIT
:
241 pb_bool
= (bool*)va_arg( args
, bool * );
246 ppsz
= (char**)va_arg( args
, char ** );
247 *ppsz
= strdup( "video/avi" );
255 static int AddStream( sout_mux_t
*p_mux
, sout_input_t
*p_input
)
257 sout_mux_sys_t
*p_sys
= p_mux
->p_sys
;
258 avi_stream_t
*p_stream
;
260 if( p_sys
->i_streams
>= 100 )
262 msg_Err( p_mux
, "too many streams" );
266 msg_Dbg( p_mux
, "adding input" );
267 p_input
->p_sys
= malloc( sizeof( int ) );
268 if( !p_input
->p_sys
)
271 *((int*)p_input
->p_sys
) = p_sys
->i_streams
;
272 p_stream
= &p_sys
->stream
[p_sys
->i_streams
];
274 switch( p_input
->p_fmt
->i_cat
)
277 p_stream
->i_cat
= AUDIO_ES
;
278 p_stream
->fcc
[0] = '0' + p_sys
->i_streams
/ 10;
279 p_stream
->fcc
[1] = '0' + p_sys
->i_streams
% 10;
280 p_stream
->fcc
[2] = 'w';
281 p_stream
->fcc
[3] = 'b';
283 p_stream
->p_bih
= NULL
;
285 p_stream
->p_wf
= malloc( sizeof( WAVEFORMATEX
) +
286 p_input
->p_fmt
->i_extra
);
287 if( !p_stream
->p_wf
)
289 free( p_input
->p_sys
);
292 #define p_wf p_stream->p_wf
293 p_wf
->cbSize
= p_input
->p_fmt
->i_extra
;
294 if( p_wf
->cbSize
> 0 )
297 p_input
->p_fmt
->p_extra
,
298 p_input
->p_fmt
->i_extra
);
300 p_wf
->nChannels
= p_input
->p_fmt
->audio
.i_channels
;
301 p_wf
->nSamplesPerSec
= p_input
->p_fmt
->audio
.i_rate
;
302 p_wf
->nBlockAlign
= p_input
->p_fmt
->audio
.i_blockalign
;
303 p_wf
->nAvgBytesPerSec
= p_input
->p_fmt
->i_bitrate
/ 8;
304 p_wf
->wBitsPerSample
= 0;
306 switch( p_input
->p_fmt
->i_codec
)
309 p_wf
->wFormatTag
= WAVE_FORMAT_A52
;
312 p_wf
->wFormatTag
= WAVE_FORMAT_MPEGLAYER3
;
315 p_wf
->wFormatTag
= WAVE_FORMAT_WMA1
;
318 p_wf
->wFormatTag
= WAVE_FORMAT_WMA2
;
321 p_wf
->wFormatTag
= WAVE_FORMAT_WMAP
;
324 p_wf
->wFormatTag
= WAVE_FORMAT_WMAL
;
328 p_wf
->wFormatTag
= WAVE_FORMAT_PCM
;
329 p_wf
->nBlockAlign
= p_wf
->nChannels
;
330 p_wf
->wBitsPerSample
= 8;
333 p_wf
->wFormatTag
= WAVE_FORMAT_PCM
;
334 p_wf
->nBlockAlign
= 2 * p_wf
->nChannels
;
335 p_wf
->wBitsPerSample
= 16;
338 p_wf
->wFormatTag
= WAVE_FORMAT_PCM
;
339 p_wf
->nBlockAlign
= 3 * p_wf
->nChannels
;
340 p_wf
->wBitsPerSample
= 24;
343 p_wf
->wFormatTag
= WAVE_FORMAT_PCM
;
344 p_wf
->nBlockAlign
= 4 * p_wf
->nChannels
;
345 p_wf
->wBitsPerSample
= 32;
353 p_stream
->i_cat
= VIDEO_ES
;
354 p_stream
->fcc
[0] = '0' + p_sys
->i_streams
/ 10;
355 p_stream
->fcc
[1] = '0' + p_sys
->i_streams
% 10;
356 p_stream
->fcc
[2] = 'd';
357 p_stream
->fcc
[3] = 'c';
358 if( p_sys
->i_stream_video
< 0 )
360 p_sys
->i_stream_video
= p_sys
->i_streams
;
362 p_stream
->p_wf
= NULL
;
363 p_stream
->p_bih
= malloc( sizeof( BITMAPINFOHEADER
) +
364 p_input
->p_fmt
->i_extra
);
365 if( !p_stream
->p_bih
)
367 free( p_input
->p_sys
);
370 #define p_bih p_stream->p_bih
371 p_bih
->biSize
= sizeof( BITMAPINFOHEADER
) +
372 p_input
->p_fmt
->i_extra
;
373 if( p_input
->p_fmt
->i_extra
> 0 )
376 p_input
->p_fmt
->p_extra
,
377 p_input
->p_fmt
->i_extra
);
379 p_bih
->biWidth
= p_input
->p_fmt
->video
.i_width
;
380 p_bih
->biHeight
= p_input
->p_fmt
->video
.i_height
;
382 p_bih
->biBitCount
= 24;
383 p_bih
->biSizeImage
= 0;
384 p_bih
->biXPelsPerMeter
= 0;
385 p_bih
->biYPelsPerMeter
= 0;
386 p_bih
->biClrUsed
= 0;
387 p_bih
->biClrImportant
= 0;
388 switch( p_input
->p_fmt
->i_codec
)
391 p_bih
->biCompression
= VLC_FOURCC( 'X', 'V', 'I', 'D' );
394 p_bih
->biCompression
= p_input
->p_fmt
->i_original_fourcc
?: p_input
->p_fmt
->i_codec
;
400 return( VLC_EGENERIC
);
402 p_stream
->i_totalsize
= 0;
403 p_stream
->i_frames
= 0;
404 p_stream
->i_duration
= 0;
407 p_stream
->f_fps
= 25;
408 p_stream
->i_bitrate
= 128 * 1024;
411 return( VLC_SUCCESS
);
414 static int DelStream( sout_mux_t
*p_mux
, sout_input_t
*p_input
)
416 msg_Dbg( p_mux
, "removing input" );
418 free( p_input
->p_sys
);
422 static int Mux ( sout_mux_t
*p_mux
)
424 sout_mux_sys_t
*p_sys
= p_mux
->p_sys
;
425 avi_stream_t
*p_stream
;
428 if( p_sys
->b_write_header
)
432 msg_Dbg( p_mux
, "writing header" );
434 p_hdr
= avi_HeaderCreateRIFF( p_mux
);
435 sout_AccessOutWrite( p_mux
->p_access
, p_hdr
);
437 p_sys
->b_write_header
= false;
440 for( i
= 0; i
< p_mux
->i_nb_inputs
; i
++ )
443 block_fifo_t
*p_fifo
;
445 i_stream
= *((int*)p_mux
->pp_inputs
[i
]->p_sys
);
446 p_stream
= &p_sys
->stream
[i_stream
];
448 p_fifo
= p_mux
->pp_inputs
[i
]->p_fifo
;
449 i_count
= block_FifoCount( p_fifo
);
452 avi_idx1_entry_t
*p_idx
;
455 p_data
= block_FifoGet( p_fifo
);
456 if( block_FifoCount( p_fifo
) > 0 )
458 block_t
*p_next
= block_FifoShow( p_fifo
);
459 p_data
->i_length
= p_next
->i_dts
- p_data
->i_dts
;
462 p_stream
->i_frames
++;
463 if( p_data
->i_length
< 0 )
465 msg_Warn( p_mux
, "argg length < 0 l" );
466 block_Release( p_data
);
470 p_stream
->i_duration
+= p_data
->i_length
;
471 p_stream
->i_totalsize
+= p_data
->i_buffer
;
473 /* add idx1 entry for this frame */
474 p_idx
= &p_sys
->idx1
.entry
[p_sys
->idx1
.i_entry_count
];
475 memcpy( p_idx
->fcc
, p_stream
->fcc
, 4 );
477 if( ( p_data
->i_flags
& BLOCK_FLAG_TYPE_MASK
) == 0 || ( p_data
->i_flags
& BLOCK_FLAG_TYPE_I
) )
478 p_idx
->i_flags
= AVIIF_KEYFRAME
;
479 p_idx
->i_pos
= p_sys
->i_movi_size
+ 4;
480 p_idx
->i_length
= p_data
->i_buffer
;
481 p_sys
->idx1
.i_entry_count
++;
482 if( p_sys
->idx1
.i_entry_count
>= p_sys
->idx1
.i_entry_max
)
484 p_sys
->idx1
.i_entry_max
+= 10000;
485 p_sys
->idx1
.entry
= xrealloc( p_sys
->idx1
.entry
,
486 p_sys
->idx1
.i_entry_max
* sizeof( avi_idx1_entry_t
) );
489 p_data
= block_Realloc( p_data
, 8, p_data
->i_buffer
);
492 SetFCC( p_data
->p_buffer
, p_stream
->fcc
);
493 SetDWLE( p_data
->p_buffer
+ 4, p_data
->i_buffer
- 8 );
495 if( p_data
->i_buffer
& 0x01 )
497 p_data
= block_Realloc( p_data
, 0, p_data
->i_buffer
+ 1 );
498 p_data
->p_buffer
[ p_data
->i_buffer
- 1 ] = '\0';
501 p_sys
->i_movi_size
+= p_data
->i_buffer
;
502 sout_AccessOutWrite( p_mux
->p_access
, p_data
);
512 /****************************************************************************/
513 /****************************************************************************/
514 /****************************************************************************/
515 /****************************************************************************/
517 typedef struct buffer_out_s
525 static void bo_Init( buffer_out_t
*p_bo
, int i_size
, uint8_t *p_buffer
)
527 p_bo
->i_buffer_size
= i_size
;
529 p_bo
->p_buffer
= p_buffer
;
531 static void bo_AddByte( buffer_out_t
*p_bo
, uint8_t i
)
533 if( p_bo
->i_buffer
< p_bo
->i_buffer_size
)
535 p_bo
->p_buffer
[p_bo
->i_buffer
] = i
;
539 static void bo_AddWordLE( buffer_out_t
*p_bo
, uint16_t i
)
541 bo_AddByte( p_bo
, i
&0xff );
542 bo_AddByte( p_bo
, ( ( i
>> 8) &0xff ) );
544 static void bo_AddWordBE( buffer_out_t
*p_bo
, uint16_t i
)
546 bo_AddByte( p_bo
, ( ( i
>> 8) &0xff ) );
547 bo_AddByte( p_bo
, i
&0xff );
549 static void bo_AddDWordLE( buffer_out_t
*p_bo
, uint32_t i
)
551 bo_AddWordLE( p_bo
, i
&0xffff );
552 bo_AddWordLE( p_bo
, ( ( i
>> 16) &0xffff ) );
554 static void bo_AddDWordBE( buffer_out_t
*p_bo
, uint32_t i
)
556 bo_AddWordBE( p_bo
, ( ( i
>> 16) &0xffff ) );
557 bo_AddWordBE( p_bo
, i
&0xffff );
560 static void bo_AddLWordLE( buffer_out_t
*p_bo
, uint64_t i
)
562 bo_AddDWordLE( p_bo
, i
&0xffffffff );
563 bo_AddDWordLE( p_bo
, ( ( i
>> 32) &0xffffffff ) );
565 static void bo_AddLWordBE( buffer_out_t
*p_bo
, uint64_t i
)
567 bo_AddDWordBE( p_bo
, ( ( i
>> 32) &0xffffffff ) );
568 bo_AddDWordBE( p_bo
, i
&0xffffffff );
572 static void bo_AddFCC( buffer_out_t
*p_bo
, const char *fcc
)
574 bo_AddByte( p_bo
, fcc
[0] );
575 bo_AddByte( p_bo
, fcc
[1] );
576 bo_AddByte( p_bo
, fcc
[2] );
577 bo_AddByte( p_bo
, fcc
[3] );
580 static void bo_AddMem( buffer_out_t
*p_bo
, int i_size
, uint8_t *p_mem
)
584 for( i
= 0; i
< i_size
; i
++ )
586 bo_AddByte( p_bo
, p_mem
[i
] );
590 /****************************************************************************
591 ****************************************************************************
593 ** avi header generation
595 ****************************************************************************
596 ****************************************************************************/
597 #define AVI_BOX_ENTER( fcc ) \
598 buffer_out_t _bo_sav_; \
599 bo_AddFCC( p_bo, fcc ); \
601 bo_AddDWordLE( p_bo, 0 )
603 #define AVI_BOX_ENTER_LIST( fcc ) \
604 AVI_BOX_ENTER( "LIST" ); \
605 bo_AddFCC( p_bo, fcc )
607 #define AVI_BOX_EXIT( i_err ) \
608 if( p_bo->i_buffer&0x01 ) bo_AddByte( p_bo, 0 ); \
609 bo_AddDWordLE( &_bo_sav_, p_bo->i_buffer - _bo_sav_.i_buffer - 4 ); \
612 static int avi_HeaderAdd_avih( sout_mux_t
*p_mux
,
615 sout_mux_sys_t
*p_sys
= p_mux
->p_sys
;
616 avi_stream_t
*p_video
= NULL
;
618 uint32_t i_microsecperframe
;
619 int i_maxbytespersec
;
621 AVI_BOX_ENTER( "avih" );
623 if( p_sys
->i_stream_video
>= 0 )
625 p_video
= &p_sys
->stream
[p_sys
->i_stream_video
];
626 if( p_video
->i_frames
<= 0 )
635 (uint32_t)( (float)1000000 /
636 (float)p_sys
->stream
[p_sys
->i_stream_video
].f_fps
);
637 i_totalframes
= p_sys
->stream
[p_sys
->i_stream_video
].i_frames
;
641 msg_Warn( p_mux
, "avi file without video track isn't a good idea..." );
642 i_microsecperframe
= 0;
646 for( i_stream
= 0,i_maxbytespersec
= 0; i_stream
< p_sys
->i_streams
; i_stream
++ )
648 if( p_sys
->stream
[i_stream
].i_duration
> 0 )
651 p_sys
->stream
[i_stream
].i_totalsize
/
652 p_sys
->stream
[i_stream
].i_duration
;
656 bo_AddDWordLE( p_bo
, i_microsecperframe
);
657 bo_AddDWordLE( p_bo
, i_maxbytespersec
);
658 bo_AddDWordLE( p_bo
, 0 ); /* padding */
659 bo_AddDWordLE( p_bo
, AVIF_TRUSTCKTYPE
|
661 AVIF_ISINTERLEAVED
); /* flags */
662 bo_AddDWordLE( p_bo
, i_totalframes
);
663 bo_AddDWordLE( p_bo
, 0 ); /* initial frame */
664 bo_AddDWordLE( p_bo
, p_sys
->i_streams
); /* streams count */
665 bo_AddDWordLE( p_bo
, 1024 * 1024 ); /* suggested buffer size */
668 bo_AddDWordLE( p_bo
, p_video
->p_bih
->biWidth
);
669 bo_AddDWordLE( p_bo
, p_video
->p_bih
->biHeight
);
673 bo_AddDWordLE( p_bo
, 0 );
674 bo_AddDWordLE( p_bo
, 0 );
676 bo_AddDWordLE( p_bo
, 0 ); /* ???? */
677 bo_AddDWordLE( p_bo
, 0 ); /* ???? */
678 bo_AddDWordLE( p_bo
, 0 ); /* ???? */
679 bo_AddDWordLE( p_bo
, 0 ); /* ???? */
683 static int avi_HeaderAdd_strh( buffer_out_t
*p_bo
, avi_stream_t
*p_stream
)
685 AVI_BOX_ENTER( "strh" );
687 switch( p_stream
->i_cat
)
691 bo_AddFCC( p_bo
, "vids" );
692 bo_AddDWordBE( p_bo
, p_stream
->p_bih
->biCompression
);
693 bo_AddDWordLE( p_bo
, 0 ); /* flags */
694 bo_AddWordLE( p_bo
, 0 ); /* priority */
695 bo_AddWordLE( p_bo
, 0 ); /* langage */
696 bo_AddDWordLE( p_bo
, 0 ); /* initial frame */
697 bo_AddDWordLE( p_bo
, 1000 );/* scale */
698 bo_AddDWordLE( p_bo
, (uint32_t)( 1000 * p_stream
->f_fps
));
699 bo_AddDWordLE( p_bo
, 0 ); /* start */
700 bo_AddDWordLE( p_bo
, p_stream
->i_frames
);
701 bo_AddDWordLE( p_bo
, 1024 * 1024 );
702 bo_AddDWordLE( p_bo
, -1 ); /* quality */
703 bo_AddDWordLE( p_bo
, 0 ); /* samplesize */
704 bo_AddWordLE( p_bo
, 0 ); /* ??? */
705 bo_AddWordLE( p_bo
, 0 ); /* ??? */
706 bo_AddWordLE( p_bo
, p_stream
->p_bih
->biWidth
);
707 bo_AddWordLE( p_bo
, p_stream
->p_bih
->biHeight
);
712 int i_rate
, i_scale
, i_samplesize
;
714 i_samplesize
= p_stream
->p_wf
->nBlockAlign
;
715 if( i_samplesize
> 1 )
717 i_scale
= i_samplesize
;
718 i_rate
= /*i_scale **/ p_stream
->i_bitrate
/ 8;
724 i_rate
= 1000 * p_stream
->i_bitrate
/ 8;
726 bo_AddFCC( p_bo
, "auds" );
727 bo_AddDWordLE( p_bo
, 0 ); /* tag */
728 bo_AddDWordLE( p_bo
, 0 ); /* flags */
729 bo_AddWordLE( p_bo
, 0 ); /* priority */
730 bo_AddWordLE( p_bo
, 0 ); /* langage */
731 bo_AddDWordLE( p_bo
, 0 ); /* initial frame */
732 bo_AddDWordLE( p_bo
, i_scale
);/* scale */
733 bo_AddDWordLE( p_bo
, i_rate
);
734 bo_AddDWordLE( p_bo
, 0 ); /* start */
735 bo_AddDWordLE( p_bo
, p_stream
->i_frames
);
736 bo_AddDWordLE( p_bo
, 10 * 1024 );
737 bo_AddDWordLE( p_bo
, -1 ); /* quality */
738 bo_AddDWordLE( p_bo
, i_samplesize
);
739 bo_AddWordLE( p_bo
, 0 ); /* ??? */
740 bo_AddWordLE( p_bo
, 0 ); /* ??? */
741 bo_AddWordLE( p_bo
, 0 );
742 bo_AddWordLE( p_bo
, 0 );
750 static int avi_HeaderAdd_strf( buffer_out_t
*p_bo
, avi_stream_t
*p_stream
)
752 AVI_BOX_ENTER( "strf" );
754 switch( p_stream
->i_cat
)
757 bo_AddWordLE( p_bo
, p_stream
->p_wf
->wFormatTag
);
758 bo_AddWordLE( p_bo
, p_stream
->p_wf
->nChannels
);
759 bo_AddDWordLE( p_bo
, p_stream
->p_wf
->nSamplesPerSec
);
760 bo_AddDWordLE( p_bo
, p_stream
->p_wf
->nAvgBytesPerSec
);
761 bo_AddWordLE( p_bo
, p_stream
->p_wf
->nBlockAlign
);
762 bo_AddWordLE( p_bo
, p_stream
->p_wf
->wBitsPerSample
);
763 bo_AddWordLE( p_bo
, p_stream
->p_wf
->cbSize
);
764 bo_AddMem( p_bo
, p_stream
->p_wf
->cbSize
, (uint8_t*)&p_stream
->p_wf
[1] );
767 bo_AddDWordLE( p_bo
, p_stream
->p_bih
->biSize
);
768 bo_AddDWordLE( p_bo
, p_stream
->p_bih
->biWidth
);
769 bo_AddDWordLE( p_bo
, p_stream
->p_bih
->biHeight
);
770 bo_AddWordLE( p_bo
, p_stream
->p_bih
->biPlanes
);
771 bo_AddWordLE( p_bo
, p_stream
->p_bih
->biBitCount
);
772 if( VLC_FOURCC( 0, 0, 0, 1 ) == 0x00000001 )
774 bo_AddDWordBE( p_bo
, p_stream
->p_bih
->biCompression
);
778 bo_AddDWordLE( p_bo
, p_stream
->p_bih
->biCompression
);
780 bo_AddDWordLE( p_bo
, p_stream
->p_bih
->biSizeImage
);
781 bo_AddDWordLE( p_bo
, p_stream
->p_bih
->biXPelsPerMeter
);
782 bo_AddDWordLE( p_bo
, p_stream
->p_bih
->biYPelsPerMeter
);
783 bo_AddDWordLE( p_bo
, p_stream
->p_bih
->biClrUsed
);
784 bo_AddDWordLE( p_bo
, p_stream
->p_bih
->biClrImportant
);
786 p_stream
->p_bih
->biSize
- sizeof( BITMAPINFOHEADER
),
787 (uint8_t*)&p_stream
->p_bih
[1] );
794 static int avi_HeaderAdd_strl( buffer_out_t
*p_bo
, avi_stream_t
*p_stream
)
796 AVI_BOX_ENTER_LIST( "strl" );
798 avi_HeaderAdd_strh( p_bo
, p_stream
);
799 avi_HeaderAdd_strf( p_bo
, p_stream
);
804 static block_t
*avi_HeaderCreateRIFF( sout_mux_t
*p_mux
)
806 sout_mux_sys_t
*p_sys
= p_mux
->p_sys
;
812 p_hdr
= block_New( p_mux
, HDR_SIZE
);
813 memset( p_hdr
->p_buffer
, 0, HDR_SIZE
);
815 bo_Init( &bo
, HDR_SIZE
, p_hdr
->p_buffer
);
817 bo_AddFCC( &bo
, "RIFF" );
818 bo_AddDWordLE( &bo
, p_sys
->i_movi_size
+ HDR_SIZE
- 8 + p_sys
->i_idx1_size
);
819 bo_AddFCC( &bo
, "AVI " );
821 bo_AddFCC( &bo
, "LIST" );
822 bo_AddDWordLE( &bo
, HDR_SIZE
- 8);
823 bo_AddFCC( &bo
, "hdrl" );
825 avi_HeaderAdd_avih( p_mux
, &bo
);
826 for( i_stream
= 0; i_stream
< p_sys
->i_streams
; i_stream
++ )
828 avi_HeaderAdd_strl( &bo
, &p_sys
->stream
[i_stream
] );
831 i_junk
= HDR_SIZE
- bo
.i_buffer
- 8 - 12;
832 bo_AddFCC( &bo
, "JUNK" );
833 bo_AddDWordLE( &bo
, i_junk
);
835 bo
.i_buffer
+= i_junk
;
836 bo_AddFCC( &bo
, "LIST" );
837 bo_AddDWordLE( &bo
, p_sys
->i_movi_size
+ 4 );
838 bo_AddFCC( &bo
, "movi" );
843 static block_t
* avi_HeaderCreateidx1( sout_mux_t
*p_mux
)
845 sout_mux_sys_t
*p_sys
= p_mux
->p_sys
;
847 uint32_t i_idx1_size
;
851 i_idx1_size
= 16 * p_sys
->idx1
.i_entry_count
;
853 p_idx1
= block_New( p_mux
, i_idx1_size
+ 8 );
854 memset( p_idx1
->p_buffer
, 0, i_idx1_size
);
856 bo_Init( &bo
, i_idx1_size
, p_idx1
->p_buffer
);
857 bo_AddFCC( &bo
, "idx1" );
858 bo_AddDWordLE( &bo
, i_idx1_size
);
860 for( i
= 0; i
< p_sys
->idx1
.i_entry_count
; i
++ )
862 bo_AddFCC( &bo
, p_sys
->idx1
.entry
[i
].fcc
);
863 bo_AddDWordLE( &bo
, p_sys
->idx1
.entry
[i
].i_flags
);
864 bo_AddDWordLE( &bo
, p_sys
->idx1
.entry
[i
].i_pos
);
865 bo_AddDWordLE( &bo
, p_sys
->idx1
.entry
[i
].i_length
);