Skip to content

Instantly share code, notes, and snippets.

@LeeiFrankJaw
Last active October 3, 2019 12:11
Show Gist options
  • Save LeeiFrankJaw/018145b065b5ca96664bc46c862d3955 to your computer and use it in GitHub Desktop.
Save LeeiFrankJaw/018145b065b5ca96664bc46c862d3955 to your computer and use it in GitHub Desktop.
Make iPhone compatible video with mencoder
mencoder input -o output.mp4 \
-of lavf -lavfopts format=mp4 \
-ovc x264 -x264encopts bframes=0:global_header \
# -ss 5:00 -endpos 5:00 \
-oac lavc -lavcopts acodec=ac3
# NOTE: THE OPTION -ovc copy SIMPLY DOES NOT WORK AND MENCODER CANNOT
# USE LIBAVCODEC PROPERLY. DO NOT WASTE TIME ON MENCODER LEARN ffmpeg
# INSTEAD.
# Given that the input file is already in the desired format, to cut
# the video only without any transcoding.
mencoder input.mp4 -o output.mp4 \
-of lavf -lavfopts format=mp4 \
-ovc copy \
-oac copy -fafmttag 0x706D \
-ss 10:00 -endpos 5:00
# Note that 0xff, 0x706D are both audio format tags for AAC.
# See https://github.com/larsmagne/mplayer/blob/master/etc/codecs.conf
# The mencoder coming from Ubuntu repository wasn't compiled with FAAC
# support. A mencoder with FAAC support can do the following.
mencoder input.mp4 -o output.mp4 \
-of lavf -lavfopts format=mp4 \
-ovc copy \
-oac faac -faacopts object=2 \
-ss 10:00 -endpos 5:00
# References:
# https://www.videolan.org/streaming-features.html
# https://wiki.videolan.org/Transcode/#Command-line
# https://wiki.videolan.org/Streaming/#Using_the_commandline
# https://wiki.videolan.org/Documentation:Command_line/
# https://wiki.videolan.org/VLC_Features_Formats/
# https://wiki.videolan.org/Codec/
# https://wiki.videolan.org/Interface/
# Active transcoding
#
# Note that the :start-time option doesn't work with active
# transcoding for mp4 format.
cvlc -v input \
--sout='#transcode{vcodec=h264,acodec=mp4a}:file{dst=output.mp4}' \
:stop-time=300 \
'vlc://quit'
# Keep both tracks
cvlc -v input \
--sout='#file{dst=output.mp4}' \
:stop-time=300 \
'vlc://quit'
# It is advisable not to use both :start-time and :stop-time at the
# same time even if it works in the absence of active transcoding,
# since the duration of the output file will be off at about 3
# seconds. Cut the original file into two parts and cut the second
# part recursively to get accurate duration for cutting.
# Cut the file into the second part
cvlc -v input \
--sout='#file{dst=output.mp4}' \
:start-time=300 \
'vlc://quit'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment