[FFmpeg-user] Create A/V sync audio and video segment files for MPEG-DASH

Wesley Wen delbin.wen at gmail.com
Tue May 26 11:08:35 CEST 2015


Hi,

We're creating MPEG-DASH stream, and the very first step is to transcode
source file to various audio and video profiles, e.g. 32k, 64k, ... for
audio while 80k, 200k, ... for video.

I use FFmpeg to do transcoding like below. (The real case could involve two
pass and much more options, but I think they might not play important role
for this question. Feel free to let me know if you need more information.)

ffmpeg -i movie.ts -c:v libx264 -b:v 80k -an -sn -dn video.mp4
ffmpeg -i movie.ts -c:a libfdk_aac -b:a 32k -vn -sn -dn audio.mp4

One of the questions I have is I could negative start PTS of audio.mp4.
Looks like,

tmp $ffprobe -show_streams audio.mp4
ffprobe version git-2015-05-20-b8e7f2b Copyright (c) 2007-2015 the FFmpeg
developers
  built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM
3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD --enable-shared
--enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables
--enable-avresample --cc=clang --host-cflags= --host-ldflags=
--enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid
--enable-libfaac --enable-libfdk-aac --enable-nonfree --enable-vda
  libavutil      54. 23.101 / 54. 23.101
  libavcodec     56. 39.101 / 56. 39.101
  libavformat    56. 33.101 / 56. 33.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'audio.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf56.33.101
  Duration: 00:00:49.72, start: 0.042667, bitrate: 33 kb/s
    Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp, 32 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[STREAM]
index=0
codec_name=aac
codec_long_name=AAC (Advanced Audio Coding)
profile=LC
codec_type=audio
codec_time_base=1/48000
codec_tag_string=mp4a
codec_tag=0x6134706d
sample_fmt=fltp
sample_rate=48000
channels=2
channel_layout=stereo
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/48000
start_pts=-2048
start_time=-0.042667
duration_ts=2386688
duration=49.722667
bit_rate=32003
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=2331
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
TAG:language=und
TAG:handler_name=SoundHandler
[/STREAM]

And interestingly, start PTS of video.mp4 is always 0.

tmp $ffprobe -show_streams video.mp4
ffprobe version git-2015-05-20-b8e7f2b Copyright (c) 2007-2015 the FFmpeg
developers
  built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM
3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD --enable-shared
--enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables
--enable-avresample --cc=clang --host-cflags= --host-ldflags=
--enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid
--enable-libfaac --enable-libfdk-aac --enable-nonfree --enable-vda
  libavutil      54. 23.101 / 54. 23.101
  libavcodec     56. 39.101 / 56. 39.101
  libavformat    56. 33.101 / 56. 33.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.33.101
  Duration: 00:00:49.68, start: 0.000000, bitrate: 114 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
1440x1080 [SAR 4:3 DAR 16:9], 111 kb/s, 29.97 fps, 29.97 tbr, 30k tbn,
59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_time_base=1001/60000
codec_tag_string=avc1
codec_tag=0x31637661
width=1440
height=1080
coded_width=1440
coded_height=1088
has_b_frames=2
sample_aspect_ratio=4:3
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=40
color_range=N/A
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=left
timecode=N/A
refs=4
is_avc=1
nal_length_size=4
id=N/A
r_frame_rate=30000/1001
avg_frame_rate=30000/1001
time_base=1/30000
start_pts=0
start_time=0.000000
duration_ts=1490489
duration=49.682967
bit_rate=111719
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=1489
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
TAG:language=und
TAG:handler_name=VideoHandler
[/STREAM]

Can I make sure both audio.mp4 and video.mp4 are sync at the same stream
timeline?

I know there is an option, avoid_negative_ts, could force output timestamp
to start from 0 or avoid negative timestamp. Do I need to specify the
option for both audio and video transcoding?

Thanks,
Wesley


More information about the ffmpeg-user mailing list