CN105554593B - 一种flv到mp4的文件容器转换方法 - Google Patents

一种flv到mp4的文件容器转换方法 Download PDF

Info

Publication number
CN105554593B
CN105554593B CN201510902768.2A CN201510902768A CN105554593B CN 105554593 B CN105554593 B CN 105554593B CN 201510902768 A CN201510902768 A CN 201510902768A CN 105554593 B CN105554593 B CN 105554593B
Authority
CN
China
Prior art keywords
frame
stts
entry
flv
sample
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201510902768.2A
Other languages
English (en)
Other versions
CN105554593A (zh
Inventor
王雪辉
谢亚光
叶�武
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Dang Hong Polytron Technologies Inc
Original Assignee
Hangzhou Arcvideo Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Arcvideo Technology Co ltd filed Critical Hangzhou Arcvideo Technology Co ltd
Priority to CN201510902768.2A priority Critical patent/CN105554593B/zh
Publication of CN105554593A publication Critical patent/CN105554593A/zh
Application granted granted Critical
Publication of CN105554593B publication Critical patent/CN105554593B/zh
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/80Generation or processing of content or additional data by content creator independently of the distribution process; Content per se
    • H04N21/85Assembly of content; Generation of multimedia applications
    • H04N21/854Content authoring
    • H04N21/8547Content authoring involving timestamps for synchronizing content
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/80Generation or processing of content or additional data by content creator independently of the distribution process; Content per se
    • H04N21/85Assembly of content; Generation of multimedia applications
    • H04N21/854Content authoring
    • H04N21/85406Content authoring involving a specific file format, e.g. MP4 format

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Television Signal Processing For Recording (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

本发明公开了一种FLV到MP4的文件容器转换方法,先从原文件读取时间戳信息并获得每一帧的stts,然后将连续的stts合并为一个entry,通过这种高效的转换方法,在有限的精度损失下,可以使得转换后的’moov’box长度有效降低,从而减少文件的加载时间。

Description

一种FLV到MP4的文件容器转换方法
技术领域
本发明涉及一种FLV到MP4的文件容器转换方法。
背景技术
很多移动终端、上载系统、CDN等都只支持MP4格式而不支持FLV的格式,但市面上有很多存量FLV文件,如果通过编码的方式转成MP4格式,不仅会降低视频质量,同时还会增加运营成本,降低工作效率。
同时,对于MP4文件,为了提高用户体验,减少点播缓冲时间,加载文件要快速,需要做成逐行下载的模式(Progressive Downloading Profile),即’moov’ box必须在文件起始处,并且越小越好。在MP4的spec(14496-12)中,描述时间戳的字段是由stts((decoding)time-to-sample)及ctts((composition)time to sample)组成,其中sample_delta,sample_offset都是以’mdhd’的’timescale’为单位的。通常情况下,为了增加精度,audio的’timescale’都是以采样率为主,如48000,而video的’timescale’为90000。
但是对于FLV文件来说,描述时间戳的字段是由TimeStamp(即DTS)与CompositionTime(即ctts)组成,而且是以毫秒为单位,这样对于非整数毫秒的时间戳,如当video的帧率为23.976fps、30fps等,特别是audio流,其时间戳是有精度损失的。举个例子,对于采样率为48000hz的AAC LC来说,其每帧的时间间隔为1024.0/48=21.333333ms,写到FLV文件里面,就会是21,22,21,22,21,22...,这样转换成对应的MP4的stts就会是1023,1024,1023,1024,1023,1024...,最终生成的stts大小就会增加很多。
发明内容
基于此,有必要提供一种不需要编码器,可直接做从FLV到MP4的容器转换,且在有限的精度损失下,可以使得转换后的’moov’box长度有效降低,从而减少文件加载时间的FLV到MP4的文件容器转换方法。
根据本发明的一方面,提供了一种FLV到MP4的文件容器转换方法,包括如下步骤:
从原文件读取时间戳信息并获得每一帧的stts;
将连续的stts合并为一个entry。
在其中一个实施例中,从原文件读取时间戳信息并获得每一帧的stts步骤中,具体方法如下:
读取原文件每帧的时间戳信息,第n帧的时间戳信息记为dts(n);
根据stts(n)=dts(n+1)-dts(n)公式,换算得每一帧的stts。
在其中一个实施例中,将连续的stts合并为一个entry的步骤中,具体方法如下:
计算每帧的DT值,并预设一个常量THR,当连续两帧的DT值的差值小于预设的常量THR,则连续的两帧合并为一个entry。
这种FLV到MP4的文件容器转换方法,提供了一种高效的转换方法,在有限的精度损失下,可以使得转换后的’moov’box长度有效降低,从而减少文件的加载时间。
具体实施方式
为了便于理解本发明,下面将用具体实施例对本发明进行更全面的描述。但是,本发明可以以许多不同的形式来实现,并不限于本文所描述的实施例。相反地,提供这实施例的目的是使对本发明的公开内容的理解更加透彻全面。
本发明一实施例的FLV到MP4的文件容器转换方法,包括如下步骤:
步骤S1、从原文件读取时间戳信息并获得每一帧的stts。
具体地,通过FLV Splitter读取源文件内容,将源文件的每帧Audio/Video数据,包括解码时间戳信息(DTS)送给后端的MP4 Muxer。
步骤S2、将连续的stts合并为一个entry。
具体地,计算每帧的DT值,并预设一个常量THR,当连续两帧的DT值的差值小于预设的常量THR,则连续的两帧合并为一个entry。
DT值计算方法如下:
假设MP4文件共有N个entry,每个entry的sample count分别记为stts samplecount(n),每个entry的sample offset记为stts sample offset(n),n=1~N。
设F(n)为第n个entry的第一帧的帧序号n:1~N,
则F(0)=0,F(1)=1,
当n>1,n≤N+1时,
设文件的总帧数为M,则M=F(N)+stts sample count(N)=F(N+1)-1
对于第m(m≥1,m≤N)帧,一定有一个唯一的m’,使得m≥F(m’)且m<F(m’+1),那么第m帧的DT值如下:
在写入文件之前,分别对所有连续的audio帧和video帧进行分组,每一组一个entry,且对应一个使得总entry数尽量少并且保证由MP4文件得到的每帧的DT和原始FLV的DT的误差在一个很小的范围。
具体地,分组的步骤如下:
步骤A1、假设原始文件共有的帧数为M。先计算每帧的原始stts,
stts org(n)=DT org(n+1)-DT org(n)
步骤A2、先令n=1,m=1,其中n为帧序号,m为从当前第n帧之前共有的entry个数。
然后令n=2,继续步骤A3。
步骤A3、判断第n帧是否可以与第n-1帧合为一组,令
由此,根据上述DT值的计算方法,可以计算帧序号为n’的帧(n’:F(N)~n)的DT(n’)。
如果所有的DT(n’)与DT org(n’)的差值都小于一个预设的常量THR(典型的THR为1ms),那么表示第n帧可以和之前的帧合为一个entry。
此时令n=n+1,如果n<N,分组完毕;否则继续A3。
反之,则表示第n帧不能和之前的帧合为一个entry,这样就可以确定第m个entry,
stts sample count(m)=n-1-F(m-1)
stts sample offset=(DT org(n)-DT org(F(m)))/stts sample count(m)
然后令m=m+1,n=n+1,如果n<N,分组完毕;否则继续步骤A3。
这种FLV到MP4的文件容器转换方法,提供了一种高效的转换方法,在有限的精度损失下,可以使得转换后的’moov’box长度有效降低,从而减少文件的加载时间。根据本实施例方法转换后的’moov’box长度可降低约30%。
如对于一个内容2小时的FLV文件,Video是30fps,audio是48000hz的AAC文件,
那么audio的帧数=2*3600/(1024/48000)=337500
Video的帧数=2*3600*30=216000
如果没有进行精度补偿,那么生成出来的audio和video的stts大小大约为
Audio=337500*8=2700000
Video=216000*8=1728000
其中8代表的是每个stts占有的字节数。
经过精度补偿后,audio和video的stts在理想状态下(即输入源没有丢包的情况下)只会占用12个字节。
减少的字节数(BYTES)=(2700000+1728000)=4428000。
对于平均10M的带宽,可以减少加载的时间(4428000*8/10000000)=3.5424s
以上所述实施例仅表达了本发明的个别实施方式,其描述较为具体和详细,但并不能因此而理解为对本发明专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本发明构思的前提下,还可以做出若干变形和改进,这些都属于本发明的保护范围。因此,本发明专利的保护范围应以所附权利要求为准。

Claims (1)

1.一种FLV到MP4的文件容器转换方法,其特征在于,包括如下步骤:
读取原文件每帧的时间戳信息,第n帧的所述时间戳信息记为dts(n),根据stts(n)=dts(n+1)-dts(n)公式,换算得每一帧的stts;
计算每帧的DT值,并预设一个常量THR,当连续两帧的所述DT值的差值小于预设的所述常量THR,则所述连续的两帧合并为一个entry;
所述DT值的计算方式为通过公式
以及公式
算得,其中所述F(n)为第n个entry的第一帧的帧序号n:1~N,所述N为MP4文件中共有N个entry,每个entry的sample count分为别为所述stts_sample_count(n),每个entry的sample offset分别为所述stts_sample_offset(n),所述n=1~N,所述M为文件总帧数。
CN201510902768.2A 2015-12-10 2015-12-10 一种flv到mp4的文件容器转换方法 Active CN105554593B (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510902768.2A CN105554593B (zh) 2015-12-10 2015-12-10 一种flv到mp4的文件容器转换方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510902768.2A CN105554593B (zh) 2015-12-10 2015-12-10 一种flv到mp4的文件容器转换方法

Publications (2)

Publication Number Publication Date
CN105554593A CN105554593A (zh) 2016-05-04
CN105554593B true CN105554593B (zh) 2019-04-02

Family

ID=55833493

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510902768.2A Active CN105554593B (zh) 2015-12-10 2015-12-10 一种flv到mp4的文件容器转换方法

Country Status (1)

Country Link
CN (1) CN105554593B (zh)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102256162A (zh) * 2011-07-22 2011-11-23 网宿科技股份有限公司 基于实时文件格式转换的优化流媒体点播的方法和系统
CN102883189A (zh) * 2012-10-16 2013-01-16 北京千橡网景科技发展有限公司 视频提供方法和系统
CN103020297A (zh) * 2012-12-31 2013-04-03 传聚互动(北京)科技有限公司 兼容多种平台的视频文件编解码方法和系统

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2009114111A2 (en) * 2008-03-12 2009-09-17 Packetvideo Corp. System and method for reformatting digital broadcast multimedia for a mobile device
US8619150B2 (en) * 2010-05-25 2013-12-31 Intellectual Ventures Fund 83 Llc Ranking key video frames using camera fixation
CN103905841B (zh) * 2014-03-18 2018-01-12 深圳市云宙多媒体技术有限公司 自适应网络带宽的多协议多播放器视频播放方法和系统

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102256162A (zh) * 2011-07-22 2011-11-23 网宿科技股份有限公司 基于实时文件格式转换的优化流媒体点播的方法和系统
CN102883189A (zh) * 2012-10-16 2013-01-16 北京千橡网景科技发展有限公司 视频提供方法和系统
CN103020297A (zh) * 2012-12-31 2013-04-03 传聚互动(北京)科技有限公司 兼容多种平台的视频文件编解码方法和系统

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
MP4文件流化方法与流媒体系统开发;王华青;《中国优秀硕士学位论文全文数据库》;20110915(第09期);正文第6-8、12-24、32-33页

Also Published As

Publication number Publication date
CN105554593A (zh) 2016-05-04

Similar Documents

Publication Publication Date Title
CN105379293B (zh) 基于超文本协议的动态自适应流媒体中的媒体质量信息指示
JP5475855B2 (ja) マルチビュー・ビデオ符号化のための仮想参照デコーダ
KR101849749B1 (ko) 트랜스코딩 시스템에서의 오디오 및 비디오 동기화 방법
EP3445053A1 (en) Transmission method and reception method
CN103200425B (zh) 一种多媒体处理装置及方法
US20170092280A1 (en) Information processing apparatus and information processing method
US20080310762A1 (en) System and method for generating and regenerating 3d image files based on 2d image media standards
EP3962085A2 (en) Image encoding and decoding method, encoding and decoding device, encoder and decoder
JP2016522622A (ja) 動的適応型ハイパーテキスト転送プロトコルストリーミングにおけるメタデータ情報のシグナリングおよび搬送
EP3241354A1 (en) Fragmented video transcoding systems and methods
JP2003114845A (ja) メディア変換方法およびメディア変換装置
US20150074129A1 (en) Augmenting media presentation description and index for metadata in a network environment
US20180007375A1 (en) Image encoding and decoding methods and devices thereof
JP2019502949A5 (zh)
CN105191325A (zh) 数据发送方法、数据再现方法、数据发送装置及数据再现装置
US10375439B2 (en) Information processing apparatus and information processing method
JP2007060286A (ja) コンテンツ編集装置及びその再生装置
CN104661058A (zh) Mp4视频点播的数据流传输方法、客户端及点播系统
CN109640162B (zh) 码流转换方法及系统
CN103763556B (zh) 视频图像编解码装置及其方法、传输系统及其方法
CN103379379A (zh) 流媒体缓冲播放方法和装置
RU2017111578A (ru) Принцип сращивания аудиоданных
US20080304766A1 (en) System and method for generating and regenerating 3d image files based on 2d image media standards
EP2276192A2 (en) Method and apparatus for transmitting/receiving multi - channel audio signals using super frame
CN105554593B (zh) 一种flv到mp4的文件容器转换方法

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP03 Change of name, title or address

Address after: 310000 A Block, 16th Floor, E Building, Paradise Software Park, No. 3 Xidoumen Road, Hangzhou City, Zhejiang Province

Patentee after: Hangzhou Dang Hong Polytron Technologies Inc

Address before: 310000 B2010, two floor, North (two), six and 368 Road, Binjiang District, Hangzhou, Zhejiang.

Patentee before: HANGZHOU DANGHONG TECHNOLOGY CO., LTD.

CP03 Change of name, title or address