Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This question can be seen as an extension of this question. I am using the ffmpeg 2.0.1 .

The following commands is useful when you want to extract parts of one big video file given time makers.

ffmpeg -i 00402.MTS -s 1280x720 -ss 0:00:05.38608 -vcodec libxvid -qscale:v 2 -acodec ac3 -ar 48000 -ab 256k -t 0:00:06.61391 m001.avi

My problem is that in the ouput file, the start value is 0 and the there is ~50ms of shift between audio and video. What argument should I use to take into account this 'start value' when extracting severals parts of the big video file ('.mts') ? What does this 'start value' mean ?

ffprobe output from big MTS video file

ffprobe m001.MTS 
ffprobe version 2.0.1 Copyright (c) 2007-2013 the FFmpeg developers built on Sep 24 2013 05:31:18 with gcc 4.8 (Debian 4.8.1-10)
configuration: --extra-cflags=-I../static/include --extra-ldflags='-L../static/lib -static' --enable-gpl --enable-version3 --enable-static --disable-shared --disable-debug --enable-runtime-cpudetect --enable-libmp3lame --enable-libx264 --enable-libspeex --enable-libvorbis --enable-libvpx --enable-libfreetype --enable-libxvid --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --disable-ffserver
libavutil      52. 38.100 / 52. 38.100
libavcodec     55. 18.102 / 55. 18.102
libavformat    55. 12.100 / 55. 12.100
libavdevice    55.  3.100 / 55.  3.100
libavfilter     3. 79.101 /  3. 79.101
libswscale      2.  3.100 /  2.  3.100
libswresample   0. 17.102 /  0. 17.102
libpostproc    52.  3.100 / 52.  3.100
Input #0, mpegts, from 'm001.MTS':
Duration: 00:01:18.25, start: 0.455556, bitrate: 12217 kb/s
Program 1 
Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p, 1440x1080 [SAR 4:3       DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc
Stream #0:1[0x1100]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 256 kb/s

ffprobe ouput from extract sample

Input #0, avi, from 'm001.avi':
Metadata:
encoder         : Lavf55.12.100
Duration: 00:00:06.64, start: 0.000000, bitrate: 4950 kb/s
Stream #0:0: Video: mpeg4 (Simple Profile) (xvid / 0x64697678), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, mono, fltp, 256 kb/s
share|improve this question
    
Could you add the console output? Not sure what you mean by "Start Value". If you are using ffmpeg -i or ffprobe, please add the output of the console. –  Rajib Jan 16 at 17:11
    
You can find the start value in the above ffprobe output: start: 0.455556 –  Eric Jan 16 at 17:26
    
Major problem is that in the extracted video output, audio and video are not sync. Shift of about 50ms (that correponds to start value: 0.455556 in the MTS original file. –  Eric Jan 19 at 14:07
    
Try adding the parameter -async 1. Does the audio start late or early? –  harrymc Jan 19 at 14:37
    
Audio start late. Option -async 1 didn't change anything. –  Eric Jan 20 at 8:48

1 Answer 1

I've come across this problem before, and the only solution is to use itsoffset and map.

ffmpeg -i 00402.MTS -itsoffset 0.455556 -i 00402.MTS -map 1:0 -map 0:1 -s 1280x720 -ss 0:00:05.38608 -vcodec libxvid -qscale:v 2 -acodec ac3 -ar 48000 -ab 256k -t 0:00:06.61391 m001.avi

This page has a nice explanation why and how it works.

http://www.kkoncepts.net/blog/fixing-out-sync-audio-and-video-ffmpeg

EDIT There are two main tools here to be aware of: 1) itsoffset 2) map

itsoffset exists to offset a stream that is out of sync, whereas map informs ffmpeg to use certain streams from specific inputs and apply them to the output.

In this example, we are using the same input twice, mapping the streams thusly: We use the video stream of first input (which seems to be starting at 00:00:00.00) We use the second input as the audio stream, but offset the input time 0.455556 seconds.

From the above mentioned site:

Here "-map 1:0" tells ffmpeg to use the second input file (1) and take its first stream (0) as the video source. Since that's the input that follows the "-itsoffset" switch, that's the stream that will be delayed. Then "-map 0.1" tells it to use the second stream from the first input as the audio. Since there's no offset applied to the first input file, it will be processed normally.

share|improve this answer
    
The given link is down. Could you update it ? –  Eric Jan 23 at 9:07
    
Here is another link with similar information. Just search the page for itsoffset: howto-pages.org/ffmpeg –  denjello Jan 23 at 9:54
    
thanks for all information, however the results is still async. I don't really know where extracting parts of a sync video can lead to async parts. What is the meaning of 'start value' exactly ? –  Eric Jan 23 at 14:46
    
try putting -ss 0:00:05.38608 in front of the first -i --- as in ffmpeg -ss 0:00:05.38608 -i 00402.MTS ... –  denjello Jan 23 at 15:19
    
After recompiling ffmpeg version git-2014-01-20-4014b40 and putting ss option after input, the shift decreased to 256 samples (...!!). When comparing audio (.wav) extracted from outputed .avi, and audio directly extracted from original .MTS, I found a 256 samples shi(f)t.. Again, why ? –  Eric Jan 23 at 17:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.