Video and audio are not synchronized in mp4 container

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Video and audio are not synchronized in mp4 container

I have small utility that reads annex-b h264 and adts aac streams from two pipes and writes them to one mp4 container. Both pipes have live streams from v4l2 and alsa devices. As you can see, I added is-live property to fdsrc. Without this property pts and dts of the video stream were corrupted.



usage() {
    echo "Usage: $(basename $0) [OPTIONS] <VIDEOPIPE> <AUDIOPIPE> <MASK>"
    echo "  -o arg (=$timeout) timeout"

    exit 0


while getopts "o:" opt

    case $opt in
        o)  timeout=$OPTARG
        *)  usage

shift $((OPTIND-1))

[ $# -ne 3 ] && usage


exec 3<> "$video_pipe"
exec 4<> "$audio_pipe"

gst-launch-1.0 -qe \
    fdsrc fd=3 do-timestamp=true is-live=true \
  ! queue \
  ! h264parse \
  !     video/x-h264,stream-format=avc,alignment=au \
  ! \
    fdsrc fd=4 do-timestamp=true is-live=true \
  ! queue \
  ! aacparse \
  !     audio/mpeg,stream-format=raw \
  ! mux.audio_0 \
    splitmuxsink name=mux location="$mask" max-size-time="${timeout}000000000"

The problem is that video and audio streams in mp4 file are not synchronized (or something else). Video looks good, but audio stream has periodically pauses about one second long. There are same pauses in audio stream after remuxing it from mp4 container with audio and video streams to another mp4 container without video stream. But result is good if I first mux only audio stream from audio pipe to mp4 container without video stream. So, I think that video stream affects to this problem.

I already tryed to set sync property of splitmuxsink to true or false. It did not help.

gstreamer-devel mailing list
[hidden email]