I am tring to cut a video in linux OS
$ ffmpeg -i dhol.mkv
ffmpeg version n4.1.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20181127
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Input #0, matroska,webm, from 'dhol.mkv':
Metadata:
ENCODER : Lavf58.20.100
Duration: 00:03:56.18, start: -0.007000, bitrate: 2688 kb/s
Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, bt709/unknown/unknown), 1920x1080, SAR 1:1 DAR 16:9, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Metadata:
DURATION : 00:03:56.167000000
Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Metadata:
DURATION : 00:03:56.181000000
I was trying to precisely cut the video file:
But using ffmpeg I was not successfull. It cuts from the nearest key frames to the given start time
ffmpeg -y -i dhol.mkv -ss $shift -t $duration -c:v copy -an output.mkv
ONE OF THE REASONS HERE IS H.264 Video format (YUV420p vs YUV420sp). I am using -c:v copy
so it has to use the same format YUV420p, so it has to start from nearest keyframe
Now the only reliable software that i can fully depend if avidemux.
Even in that i have to select
video-codec: MJPEG
audio-codec: vorbis
But the cut video size will be large.
I tried in avidemux
video-codec: copy
audio-codec: copy
It will cut from nearest keyframe than precisely.
One conclusion:
So irrespective of ffmpeg
or avidemux
, the output video format yuv420p
will not allow precise formatting
Only option currently possible:
Using avidemux and with
video-codec: MJPEG
audio-codec: vorbis
Cons:
1) bigger video size.
2) no proper command line examples available for avidemux to do the same as gui does
I tried command line in avidemux:
avidemux3_cli --video-codec MJPEG --audio-codec AAC --output-format AVI --load dhol.mkv --begin 137.633 --end 141.334 --save dhol2.mkv
It tries to convert the whole file rather than from the start to end time
My requirement: I want to do it command line.
I didnt try with ffmpeg (with video codec: MJPEG and audio: vorbis). I never saw any example
How to precisely cut a video (even the output format can be different (like MJPEG instead of yuv420p, and also bigger sizes, its ok) using command line