1 /*****************************************************************************
2 * muxers.c: h264 file i/o plugins
3 *****************************************************************************
4 * Copyright (C) 2003-2008 x264 project
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
7 * Loren Merritt <lorenm@u.washington.edu>
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 02111, USA.
22 *****************************************************************************/
24 #include "common/common.h"
33 #include <sys/types.h>
41 #include <gpac/isomedia.h>
44 static int64_t gcd( int64_t a, int64_t b )
62 /* raw 420 yuv file operation */
63 int open_file_yuv( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
65 yuv_input_t *h = malloc(sizeof(yuv_input_t));
66 h->width = p_param->i_width;
67 h->height = p_param->i_height;
70 if( !strcmp(psz_filename, "-") )
73 h->fh = fopen(psz_filename, "rb");
81 int get_frame_total_yuv( hnd_t handle )
83 yuv_input_t *h = handle;
84 int i_frame_total = 0;
86 if( !fseek( h->fh, 0, SEEK_END ) )
88 uint64_t i_size = ftell( h->fh );
89 fseek( h->fh, 0, SEEK_SET );
90 i_frame_total = (int)(i_size / ( h->width * h->height * 3 / 2 ));
96 int read_frame_yuv( x264_picture_t *p_pic, hnd_t handle, int i_frame )
98 yuv_input_t *h = handle;
100 if( i_frame != h->next_frame )
101 if( fseek( h->fh, (uint64_t)i_frame * h->width * h->height * 3 / 2, SEEK_SET ) )
104 if( fread( p_pic->img.plane[0], 1, h->width * h->height, h->fh ) <= 0
105 || fread( p_pic->img.plane[1], 1, h->width * h->height / 4, h->fh ) <= 0
106 || fread( p_pic->img.plane[2], 1, h->width * h->height / 4, h->fh ) <= 0 )
109 h->next_frame = i_frame+1;
114 int close_file_yuv(hnd_t handle)
116 yuv_input_t *h = handle;
124 /* YUV4MPEG2 raw 420 yuv file operation */
129 int seq_header_len, frame_header_len;
133 #define Y4M_MAGIC "YUV4MPEG2"
134 #define MAX_YUV4_HEADER 80
135 #define Y4M_FRAME_MAGIC "FRAME"
136 #define MAX_FRAME_HEADER 80
138 int open_file_y4m( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
142 char header[MAX_YUV4_HEADER+10];
143 char *tokstart, *tokend, *header_end;
144 y4m_input_t *h = malloc(sizeof(y4m_input_t));
148 if( !strcmp(psz_filename, "-") )
151 h->fh = fopen(psz_filename, "rb");
155 h->frame_header_len = strlen(Y4M_FRAME_MAGIC)+1;
158 for( i=0; i<MAX_YUV4_HEADER; i++ )
160 header[i] = fgetc(h->fh);
161 if( header[i] == '\n' )
163 /* Add a space after last option. Makes parsing "444" vs
164 "444alpha" easier. */
170 if( i == MAX_YUV4_HEADER || strncmp(header, Y4M_MAGIC, strlen(Y4M_MAGIC)) )
173 /* Scan properties */
174 header_end = &header[i+1]; /* Include space */
175 h->seq_header_len = i+1;
176 for( tokstart = &header[strlen(Y4M_MAGIC)+1]; tokstart < header_end; tokstart++ )
178 if(*tokstart==0x20) continue;
181 case 'W': /* Width. Required. */
182 h->width = p_param->i_width = strtol(tokstart, &tokend, 10);
185 case 'H': /* Height. Required. */
186 h->height = p_param->i_height = strtol(tokstart, &tokend, 10);
189 case 'C': /* Color space */
190 if( strncmp("420", tokstart, 3) )
192 fprintf(stderr, "Colorspace unhandled\n");
195 tokstart = strchr(tokstart, 0x20);
197 case 'I': /* Interlace type */
200 case 'p': interlaced = 0; break;
205 default: interlaced = 1;
206 fprintf(stderr, "Warning, this sequence might be interlaced\n");
209 case 'F': /* Frame rate - 0:0 if unknown */
210 if( sscanf(tokstart, "%d:%d", &n, &d) == 2 && n && d )
212 x264_reduce_fraction( &n, &d );
213 p_param->i_fps_num = n;
214 p_param->i_fps_den = d;
216 tokstart = strchr(tokstart, 0x20);
218 case 'A': /* Pixel aspect - 0:0 if unknown */
219 if( sscanf(tokstart, "%d:%d", &n, &d) == 2 && n && d )
221 x264_reduce_fraction( &n, &d );
222 p_param->vui.i_sar_width = n;
223 p_param->vui.i_sar_height = d;
225 tokstart = strchr(tokstart, 0x20);
227 case 'X': /* Vendor extensions */
228 if( !strncmp("YSCSS=",tokstart,6) )
230 /* Older nonstandard pixel format representation */
232 if( strncmp("420JPEG",tokstart,7) &&
233 strncmp("420MPEG2",tokstart,8) &&
234 strncmp("420PALDV",tokstart,8) )
236 fprintf(stderr, "Unsupported extended colorspace\n");
240 tokstart = strchr(tokstart, 0x20);
245 fprintf(stderr, "yuv4mpeg: %ix%i@%i/%ifps, %i:%i\n",
246 h->width, h->height, p_param->i_fps_num, p_param->i_fps_den,
247 p_param->vui.i_sar_width, p_param->vui.i_sar_height);
249 *p_handle = (hnd_t)h;
253 /* Most common case: frame_header = "FRAME" */
254 int get_frame_total_y4m( hnd_t handle )
256 y4m_input_t *h = handle;
257 int i_frame_total = 0;
258 uint64_t init_pos = ftell(h->fh);
260 if( !fseek( h->fh, 0, SEEK_END ) )
262 uint64_t i_size = ftell( h->fh );
263 fseek( h->fh, init_pos, SEEK_SET );
264 i_frame_total = (int)((i_size - h->seq_header_len) /
265 (3*(h->width*h->height)/2+h->frame_header_len));
268 return i_frame_total;
271 int read_frame_y4m( x264_picture_t *p_pic, hnd_t handle, int i_frame )
273 int slen = strlen(Y4M_FRAME_MAGIC);
276 y4m_input_t *h = handle;
278 if( i_frame != h->next_frame )
280 if (fseek(h->fh, (uint64_t)i_frame*(3*(h->width*h->height)/2+h->frame_header_len)
281 + h->seq_header_len, SEEK_SET))
285 /* Read frame header - without terminating '\n' */
286 if (fread(header, 1, slen, h->fh) != slen)
290 if (strncmp(header, Y4M_FRAME_MAGIC, slen))
292 fprintf(stderr, "Bad header magic (%08X <=> %s)\n",
293 *((uint32_t*)header), header);
297 /* Skip most of it */
298 while (i<MAX_FRAME_HEADER && fgetc(h->fh) != '\n')
300 if (i == MAX_FRAME_HEADER)
302 fprintf(stderr, "Bad frame header!\n");
305 h->frame_header_len = i+slen+1;
307 if( fread(p_pic->img.plane[0], 1, h->width*h->height, h->fh) <= 0
308 || fread(p_pic->img.plane[1], 1, h->width * h->height / 4, h->fh) <= 0
309 || fread(p_pic->img.plane[2], 1, h->width * h->height / 4, h->fh) <= 0)
312 h->next_frame = i_frame+1;
317 int close_file_y4m(hnd_t handle)
319 y4m_input_t *h = handle;
327 /* avs/avi input file support under cygwin */
335 int open_file_avis( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
337 avis_input_t *h = malloc(sizeof(avis_input_t));
341 *p_handle = (hnd_t)h;
344 if( AVIStreamOpenFromFile( &h->p_avi, psz_filename, streamtypeVIDEO, 0, OF_READ, NULL ) )
350 if( AVIStreamInfo(h->p_avi, &info, sizeof(AVISTREAMINFO)) )
352 AVIStreamRelease(h->p_avi);
357 // check input format
358 if (info.fccHandler != MAKEFOURCC('Y', 'V', '1', '2'))
360 fprintf( stderr, "avis [error]: unsupported input format (%c%c%c%c)\n",
361 (char)(info.fccHandler & 0xff), (char)((info.fccHandler >> 8) & 0xff),
362 (char)((info.fccHandler >> 16) & 0xff), (char)((info.fccHandler >> 24)) );
364 AVIStreamRelease(h->p_avi);
371 p_param->i_width = info.rcFrame.right - info.rcFrame.left;
373 p_param->i_height = info.rcFrame.bottom - info.rcFrame.top;
374 i = gcd(info.dwRate, info.dwScale);
375 p_param->i_fps_den = info.dwScale / i;
376 p_param->i_fps_num = info.dwRate / i;
378 fprintf( stderr, "avis [info]: %dx%d @ %.2f fps (%d frames)\n",
379 p_param->i_width, p_param->i_height,
380 (double)p_param->i_fps_num / (double)p_param->i_fps_den,
381 (int)info.dwLength );
386 int get_frame_total_avis( hnd_t handle )
388 avis_input_t *h = handle;
391 if( AVIStreamInfo(h->p_avi, &info, sizeof(AVISTREAMINFO)) )
394 return info.dwLength;
397 int read_frame_avis( x264_picture_t *p_pic, hnd_t handle, int i_frame )
399 avis_input_t *h = handle;
401 p_pic->img.i_csp = X264_CSP_YV12;
403 if( AVIStreamRead(h->p_avi, i_frame, 1, p_pic->img.plane[0], h->width * h->height * 3 / 2, NULL, NULL ) )
409 int close_file_avis( hnd_t handle )
411 avis_input_t *h = handle;
412 AVIStreamRelease(h->p_avi);
422 int (*p_read_frame)( x264_picture_t *p_pic, hnd_t handle, int i_frame );
423 int (*p_close_infile)( hnd_t handle );
429 struct thread_input_arg_t *next_args;
432 typedef struct thread_input_arg_t {
437 } thread_input_arg_t;
439 int open_file_thread( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
441 thread_input_t *h = malloc(sizeof(thread_input_t));
442 x264_picture_alloc( &h->pic, X264_CSP_I420, p_param->i_width, p_param->i_height );
443 h->p_read_frame = p_read_frame;
444 h->p_close_infile = p_close_infile;
445 h->p_handle = *p_handle;
447 h->next_args = malloc(sizeof(thread_input_arg_t));
449 h->next_args->status = 0;
450 h->frame_total = p_get_frame_total( h->p_handle );
452 *p_handle = (hnd_t)h;
456 int get_frame_total_thread( hnd_t handle )
458 thread_input_t *h = handle;
459 return h->frame_total;
462 void read_frame_thread_int( thread_input_arg_t *i )
464 i->status = i->h->p_read_frame( i->pic, i->h->p_handle, i->i_frame );
467 int read_frame_thread( x264_picture_t *p_pic, hnd_t handle, int i_frame )
469 thread_input_t *h = handle;
473 if( h->next_frame >= 0 )
475 x264_pthread_join( h->tid, &stuff );
476 ret |= h->next_args->status;
479 if( h->next_frame == i_frame )
481 XCHG( x264_picture_t, *p_pic, h->pic );
485 ret |= h->p_read_frame( p_pic, h->p_handle, i_frame );
488 if( !h->frame_total || i_frame+1 < h->frame_total )
491 h->next_args->i_frame = i_frame+1;
492 h->next_args->pic = &h->pic;
493 x264_pthread_create( &h->tid, NULL, (void*)read_frame_thread_int, h->next_args );
501 int close_file_thread( hnd_t handle )
503 thread_input_t *h = handle;
504 h->p_close_infile( h->p_handle );
505 x264_picture_clean( &h->pic );
512 int open_file_bsf( char *psz_filename, hnd_t *p_handle )
514 if ((*p_handle = fopen(psz_filename, "w+b")) == NULL)
520 int set_param_bsf( hnd_t handle, x264_param_t *p_param )
525 int write_nalu_bsf( hnd_t handle, uint8_t *p_nalu, int i_size )
527 if (fwrite(p_nalu, i_size, 1, (FILE *)handle) > 0)
532 int set_eop_bsf( hnd_t handle, x264_picture_t *p_picture )
537 int close_file_bsf( hnd_t handle )
539 if ((handle == NULL) || (handle == stdout))
542 return fclose((FILE *)handle);
545 /* -- mp4 muxing support ------------------------------------------------- */
551 GF_AVCConfig *p_config;
552 GF_ISOSample *p_sample;
564 void recompute_bitrate_mp4(GF_ISOFile *p_file, int i_track)
566 u32 i, count, di, timescale, time_wnd, rate;
571 esd = gf_isom_get_esd(p_file, i_track, 1);
574 esd->decoderConfig->avgBitrate = 0;
575 esd->decoderConfig->maxBitrate = 0;
578 timescale = gf_isom_get_media_timescale(p_file, i_track);
579 count = gf_isom_get_sample_count(p_file, i_track);
580 for (i=0; i<count; i++) {
581 GF_ISOSample *samp = gf_isom_get_sample_info(p_file, i_track, i+1, &di, &offset);
583 if (samp->dataLength>esd->decoderConfig->bufferSizeDB) esd->decoderConfig->bufferSizeDB = samp->dataLength;
585 if (esd->decoderConfig->bufferSizeDB < samp->dataLength) esd->decoderConfig->bufferSizeDB = samp->dataLength;
586 esd->decoderConfig->avgBitrate += samp->dataLength;
587 rate += samp->dataLength;
588 if (samp->DTS > time_wnd + timescale) {
589 if (rate > esd->decoderConfig->maxBitrate) esd->decoderConfig->maxBitrate = rate;
590 time_wnd = samp->DTS;
594 gf_isom_sample_del(&samp);
597 br = (Double) (s64) gf_isom_get_media_duration(p_file, i_track);
599 esd->decoderConfig->avgBitrate = (u32) (esd->decoderConfig->avgBitrate / br);
601 esd->decoderConfig->avgBitrate *= 8;
602 esd->decoderConfig->maxBitrate *= 8;
604 gf_isom_change_mpeg4_description(p_file, i_track, 1, esd);
605 gf_odf_desc_del((GF_Descriptor *) esd);
609 int close_file_mp4( hnd_t handle )
611 mp4_t *p_mp4 = (mp4_t *)handle;
617 gf_odf_avc_cfg_del(p_mp4->p_config);
621 if (p_mp4->p_sample->data)
622 free(p_mp4->p_sample->data);
624 gf_isom_sample_del(&p_mp4->p_sample);
629 recompute_bitrate_mp4(p_mp4->p_file, p_mp4->i_track);
630 gf_isom_set_pl_indication(p_mp4->p_file, GF_ISOM_PL_VISUAL, 0x15);
631 gf_isom_set_storage_mode(p_mp4->p_file, GF_ISOM_STORE_FLAT);
632 gf_isom_close(p_mp4->p_file);
640 int open_file_mp4( char *psz_filename, hnd_t *p_handle )
646 if ((p_mp4 = (mp4_t *)malloc(sizeof(mp4_t))) == NULL)
649 memset(p_mp4, 0, sizeof(mp4_t));
650 p_mp4->p_file = gf_isom_open(psz_filename, GF_ISOM_OPEN_WRITE, NULL);
652 if ((p_mp4->p_sample = gf_isom_sample_new()) == NULL)
654 close_file_mp4( p_mp4 );
658 gf_isom_set_brand_info(p_mp4->p_file, GF_ISOM_BRAND_AVC1, 0);
666 int set_param_mp4( hnd_t handle, x264_param_t *p_param )
668 mp4_t *p_mp4 = (mp4_t *)handle;
670 p_mp4->i_track = gf_isom_new_track(p_mp4->p_file, 0, GF_ISOM_MEDIA_VISUAL,
673 p_mp4->p_config = gf_odf_avc_cfg_new();
674 gf_isom_avc_config_new(p_mp4->p_file, p_mp4->i_track, p_mp4->p_config,
675 NULL, NULL, &p_mp4->i_descidx);
677 gf_isom_set_track_enabled(p_mp4->p_file, p_mp4->i_track, 1);
679 gf_isom_set_visual_info(p_mp4->p_file, p_mp4->i_track, p_mp4->i_descidx,
680 p_param->i_width, p_param->i_height);
682 if( p_param->vui.i_sar_width && p_param->vui.i_sar_height )
684 uint64_t dw = p_param->i_width << 16;
685 uint64_t dh = p_param->i_height << 16;
686 double sar = (double)p_param->vui.i_sar_width / p_param->vui.i_sar_height;
691 gf_isom_set_track_layout_info( p_mp4->p_file, p_mp4->i_track, dw, dh, 0, 0, 0 );
694 p_mp4->p_sample->data = (char *)malloc(p_param->i_width * p_param->i_height * 3 / 2);
695 if (p_mp4->p_sample->data == NULL)
698 p_mp4->i_time_res = p_param->i_fps_num;
699 p_mp4->i_time_inc = p_param->i_fps_den;
700 p_mp4->i_init_delay = p_param->i_bframe ? (p_param->b_bframe_pyramid ? 2 : 1) : 0;
701 p_mp4->i_init_delay *= p_mp4->i_time_inc;
702 fprintf(stderr, "mp4 [info]: initial delay %d (scale %d)\n",
703 p_mp4->i_init_delay, p_mp4->i_time_res);
709 int write_nalu_mp4( hnd_t handle, uint8_t *p_nalu, int i_size )
711 mp4_t *p_mp4 = (mp4_t *)handle;
712 GF_AVCConfigSlot *p_slot;
713 uint8_t type = p_nalu[4] & 0x1f;
722 p_mp4->p_config->configurationVersion = 1;
723 p_mp4->p_config->AVCProfileIndication = p_nalu[5];
724 p_mp4->p_config->profile_compatibility = p_nalu[6];
725 p_mp4->p_config->AVCLevelIndication = p_nalu[7];
726 p_slot = (GF_AVCConfigSlot *)malloc(sizeof(GF_AVCConfigSlot));
727 p_slot->size = i_size - 4;
728 p_slot->data = (char *)malloc(p_slot->size);
729 memcpy(p_slot->data, p_nalu + 4, i_size - 4);
730 gf_list_add(p_mp4->p_config->sequenceParameterSets, p_slot);
740 p_slot = (GF_AVCConfigSlot *)malloc(sizeof(GF_AVCConfigSlot));
741 p_slot->size = i_size - 4;
742 p_slot->data = (char *)malloc(p_slot->size);
743 memcpy(p_slot->data, p_nalu + 4, i_size - 4);
744 gf_list_add(p_mp4->p_config->pictureParameterSets, p_slot);
748 gf_isom_avc_config_update(p_mp4->p_file, p_mp4->i_track, 1, p_mp4->p_config);
757 memcpy(p_mp4->p_sample->data + p_mp4->p_sample->dataLength, p_nalu, i_size);
758 p_mp4->p_sample->data[p_mp4->p_sample->dataLength + 0] = (psize >> 24) & 0xff;
759 p_mp4->p_sample->data[p_mp4->p_sample->dataLength + 1] = (psize >> 16) & 0xff;
760 p_mp4->p_sample->data[p_mp4->p_sample->dataLength + 2] = (psize >> 8) & 0xff;
761 p_mp4->p_sample->data[p_mp4->p_sample->dataLength + 3] = (psize >> 0) & 0xff;
762 p_mp4->p_sample->dataLength += i_size;
769 int set_eop_mp4( hnd_t handle, x264_picture_t *p_picture )
771 mp4_t *p_mp4 = (mp4_t *)handle;
772 uint64_t dts = (uint64_t)p_mp4->i_numframe * p_mp4->i_time_inc;
773 uint64_t pts = (uint64_t)p_picture->i_pts;
774 int32_t offset = p_mp4->i_init_delay + pts - dts;
776 p_mp4->p_sample->IsRAP = p_picture->i_type == X264_TYPE_IDR ? 1 : 0;
777 p_mp4->p_sample->DTS = dts;
778 p_mp4->p_sample->CTS_Offset = offset;
779 gf_isom_add_sample(p_mp4->p_file, p_mp4->i_track, p_mp4->i_descidx, p_mp4->p_sample);
781 p_mp4->p_sample->dataLength = 0;
790 /* -- mkv muxing support ------------------------------------------------- */
796 int sps_len, pps_len;
798 int width, height, d_width, d_height;
800 int64_t frame_duration;
803 int b_header_written;
804 char b_writing_frame;
807 int write_header_mkv( mkv_t *p_mkv )
813 if( p_mkv->sps == NULL || p_mkv->pps == NULL ||
814 p_mkv->width == 0 || p_mkv->height == 0 ||
815 p_mkv->d_width == 0 || p_mkv->d_height == 0)
818 avcC_len = 5 + 1 + 2 + p_mkv->sps_len + 1 + 2 + p_mkv->pps_len;
819 avcC = malloc(avcC_len);
824 avcC[1] = p_mkv->sps[1];
825 avcC[2] = p_mkv->sps[2];
826 avcC[3] = p_mkv->sps[3];
827 avcC[4] = 0xff; // nalu size length is four bytes
828 avcC[5] = 0xe1; // one sps
830 avcC[6] = p_mkv->sps_len >> 8;
831 avcC[7] = p_mkv->sps_len;
833 memcpy(avcC+8, p_mkv->sps, p_mkv->sps_len);
835 avcC[8+p_mkv->sps_len] = 1; // one pps
836 avcC[9+p_mkv->sps_len] = p_mkv->pps_len >> 8;
837 avcC[10+p_mkv->sps_len] = p_mkv->pps_len;
839 memcpy( avcC+11+p_mkv->sps_len, p_mkv->pps, p_mkv->pps_len );
841 ret = mk_writeHeader( p_mkv->w, "x264", "V_MPEG4/ISO/AVC",
842 avcC, avcC_len, p_mkv->frame_duration, 50000,
843 p_mkv->width, p_mkv->height,
844 p_mkv->d_width, p_mkv->d_height );
848 p_mkv->b_header_written = 1;
853 int open_file_mkv( char *psz_filename, hnd_t *p_handle )
859 p_mkv = malloc(sizeof(*p_mkv));
863 memset(p_mkv, 0, sizeof(*p_mkv));
865 p_mkv->w = mk_createWriter(psz_filename);
866 if (p_mkv->w == NULL)
877 int set_param_mkv( hnd_t handle, x264_param_t *p_param )
879 mkv_t *p_mkv = handle;
882 if( p_param->i_fps_num > 0 )
884 p_mkv->frame_duration = (int64_t)p_param->i_fps_den *
885 (int64_t)1000000000 / p_param->i_fps_num;
886 p_mkv->fps_num = p_param->i_fps_num;
890 p_mkv->frame_duration = 0;
894 p_mkv->width = p_param->i_width;
895 p_mkv->height = p_param->i_height;
897 if( p_param->vui.i_sar_width && p_param->vui.i_sar_height )
899 dw = (int64_t)p_param->i_width * p_param->vui.i_sar_width;
900 dh = (int64_t)p_param->i_height * p_param->vui.i_sar_height;
904 dw = p_param->i_width;
905 dh = p_param->i_height;
908 if( dw > 0 && dh > 0 )
910 int64_t x = gcd( dw, dh );
915 p_mkv->d_width = (int)dw;
916 p_mkv->d_height = (int)dh;
921 int write_nalu_mkv( hnd_t handle, uint8_t *p_nalu, int i_size )
923 mkv_t *p_mkv = handle;
924 uint8_t type = p_nalu[4] & 0x1f;
934 p_mkv->sps = malloc(i_size - 4);
935 if (p_mkv->sps == NULL)
937 p_mkv->sps_len = i_size - 4;
938 memcpy(p_mkv->sps, p_nalu + 4, i_size - 4);
946 p_mkv->pps = malloc(i_size - 4);
947 if (p_mkv->pps == NULL)
949 p_mkv->pps_len = i_size - 4;
950 memcpy(p_mkv->pps, p_nalu + 4, i_size - 4);
958 if( !p_mkv->b_writing_frame )
960 if( mk_startFrame(p_mkv->w) < 0 )
962 p_mkv->b_writing_frame = 1;
965 dsize[0] = psize >> 24;
966 dsize[1] = psize >> 16;
967 dsize[2] = psize >> 8;
969 if( mk_addFrameData(p_mkv->w, dsize, 4) < 0 ||
970 mk_addFrameData(p_mkv->w, p_nalu + 4, i_size - 4) < 0 )
978 if( !p_mkv->b_header_written && p_mkv->pps && p_mkv->sps &&
979 write_header_mkv(p_mkv) < 0 )
985 int set_eop_mkv( hnd_t handle, x264_picture_t *p_picture )
987 mkv_t *p_mkv = handle;
988 int64_t i_stamp = (int64_t)(p_picture->i_pts * 1e9 / p_mkv->fps_num);
990 p_mkv->b_writing_frame = 0;
992 return mk_setFrameFlags( p_mkv->w, i_stamp,
993 p_picture->i_type == X264_TYPE_IDR );
996 int close_file_mkv( hnd_t handle )
998 mkv_t *p_mkv = handle;
1006 ret = mk_close(p_mkv->w);