[FFmpeg-user] Splitting video not on keyframes
Tim Hiles
thiles at confex.com
Tue Aug 15 22:41:45 EEST 2017
Hi users,
Have a problem that I've long needed a solution for.
I record my screen using this command using a bat script to automate the
process:
ex. c:\ffmpeg\ffmpeg\bin\ffmpeg.exe -rtbufsize 1000M -f gdigrab -framerate
15 -i desktop -f dshow -i audio=%Device% -flags +global_header -vcodec
libx264 -pix_fmt yuv420p -preset ultrafast -acodec pcm_s16le -ac 1 -ar
22050 -vf "fps=15" "C:\TestVideo\Session%SessionRecording%.mkv"
It then converts the video using this immediately after:
ex. c:\ffmpeg\ffmpeg\bin\ffmpeg.exe -i
"C:\TestVideo\Session%SessionRecording%.mkv" -loglevel error -stats -c:v
copy -acodec aac -ac 1 -ar 22050 -strict -2 -movflags +faststart
"C:\TestVideo\Session%SessionRecording%.mp4"
If I try to split this video after by hand using ffmpeg (rather than using
a video editor like Premiere) I use this command:
ex. c:\ffmpeg\ffmpeg\bin\ffmpeg.exe -ss 0:06:14 -i
"C:\TestVideo\Session42402_0.mp4" -vcodec copy -acodec copy -t 0:14:50
-async 2 -vsync 2 "C:\TestVideo\TestResult.MP4"
The resulting video's audio\video is in sync, however the start of the
video is always off by a few seconds either ahead or behind the -ss
timestamp. Is there a way to fix this issue? Can I change the gdigrab
command? Can I change the convert command? Can I change the split video
command?
Note to make about the split command:
I have tried many different variations including -to, putting the -ss after
the -i filename, -async 1, vsync 1, a combo of the two or none at all.
I've gotten two different results out of all the variations, either the
video starts off a few seconds before or after the -ss timestamp OR the
video starts off correctly but the audio is behind by a few seconds, async
nor vsync help.
Now I've looked into google I don't know how many times. Stackoverflow,
Superuser, ffmpeg mailing list. The general concensus I get is it might
have something to do with keyframes. Is it possible (can't find the
option) to add keyframes while recording with the gdigrab command, and
would this help? I did today notice in the docs that there is a Segment
muxer with the option ‘split_by_time’
*Allow segments to start on frames other than keyframes. This improves
behavior on some players when the time between keyframes is inconsistent,
but may make things worse on others, and can cause some oddities during
seeking. This flag should be used with the hls_time option. *
Is this something that could help? If so, where and how would I implement
it in any of the commands above?
output and command of split video:
C:\Users\c0nF3x41l3s>c:\ffmpeg\ffmpeg\bin\ffmpeg.exe -ss 0:06:14 -i
"C:\TestVideo\Session42402_0.mp4" -vcodec co
py -acodec copy -t 0:14:50 -async 2 -vsync 2 "C:\TestVideo\TestResult.MP4"
ffmpeg version N-86986-g62dfa2b Copyright (c) 2000-2017 the FFmpeg
developers
built with gcc 7.1.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-cuda
--enable-cuvid --enable-d3d11va --enable-dxva2 --enable-li
bmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig
--enable-frei0r --enable-gnutls --enable-iconv
--enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca
--enable-libfreetype --enable-libgme --enable-libgs
m --enable-libilbc --enable-libmodplug --enable-libmp3lame
--enable-libopencore-amrnb --enable-libopencore-amrwb --enabl
e-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp
--enable-libsnappy --enable-libsoxr --enable-libspe
ex --enable-libtheora --enable-libtwolame --enable-libvidstab
--enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx
--enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265
--enable-libxavs --enable-libxvid --enable-libzi
mg --enable-lzma --enable-zlib
libavutil 55. 74.100 / 55. 74.100
libavcodec 57.102.100 / 57.102.100
libavformat 57. 76.100 / 57. 76.100
libavdevice 57. 7.100 / 57. 7.100
libavfilter 6. 99.100 / 6. 99.100
libswscale 4. 7.102 / 4. 7.102
libswresample 2. 8.100 / 2. 8.100
libpostproc 54. 6.100 / 54. 6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\TestVideo\Session42402_0.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.8.102
Duration: 02:20:00.05, start: 0.000000, bitrate: 442 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 /
0x31637661), yuv420p, 1024x768, 343 kb/s, 15 fps, 15 tb
r, 16k tbn, 30 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 22050 Hz, mono,
fltp, 94 kb/s (default)
Metadata:
handler_name : SoundHandler
Output #0, mp4, to 'C:\TestVideo\TestResult.MP4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.76.100
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 /
0x31637661), yuv420p, 1024x768, q=2-31, 343 kb/s, 15 fp
s, 15 tbr, 16k tbn, 16k tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 22050 Hz, mono,
fltp, 94 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=13458 fps=0.0 q=-1.0 Lsize= 39643kB time=00:14:49.95 bitrate=
364.9kbits/s speed=3.89e+003x
video:28217kB audio:10985kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 1.128093%
Thanks in advance for any help!
More information about the ffmpeg-user
mailing list