How to convert an mkv (with subtitles) to something Nexus One friendly? - ffmpeg

I have this ffmpeg one-liner that's been good for generating video files for my Nexus One:
ffmpeg -i infile.mkv -acodec aac -s 572x238 -vcodec libx264 -vpre ipod640 -ab 128k -b 512k -f mp4 -strict experimental outfile.mp4
But it does this ignorant of the subtitles in infile.mkv -- usually not a problem, unless I'm dealing with a non-english movie. In cases like this, I'd like to use the Japanese audio track, and the English subtitles.
The funny bit is that I can use mplayer to play it using -alang and -slang, but don't know how to use mencoder to make Nexus One friendly videos. I can use ffmpeg to generate Nexus One friendly videos, but can't figure out how to get it to use a specific subtitle track.
If someone can solve one of these for me, I'll be a happy camper.

Well after a lot of googling and trial & error, here is what worked for me:
mencoder infile.mkv -o outfile.mp4 -vf dsize=512:352:2,scale=-8:-8,harddup -oac faac -faacopts mpeg=4:object=2:raw:br=128 -of lavf -lavfopts format=mp4 -ovc x264 -sws 9 -x264encopts nocabac:level_idc=30:bframes=0:bitrate=264:threads=auto:global_header:threads=auto:subq=5:frameref=6:partitions=all:trellis=1:chroma_me:me=umh
It's not using ffmpeg, but it appears to be working.

Related

FFmpeg how generate a sequence of videos with bash

i try to write an .sh that read a folder create a playlist of mp4 files and then generate an only big video with a sequence of all videos find in the folder, and encode it for dash:
printf "file '%s'\n" ./*.mp4 > playlist.sh
ffmpeg -f concat -safe 0 -i playlist.sh -c copy concat.mp4
Till now i follow the demux concat official guido to ffmpeg website.
Without result, also the following give me "more than 1000 frames duplicated between videos of the sequence"
ffmpeg -f concat -i playlist.sh -c:a aac -b:a 384k -ar 48000 -ac 2 -c:v libx264 -x264opts 'keyint=50:min-keyint=50:no-scenecut' -r 25 -b:v 2400k -maxrate 2400k -bufsize 1200k -vf "scale=-1:432 " out.mp4
Thanks a lot
Sry, cannot comment (yet)...
Your commands are correct, I could just concat some sample videos.
Do you always get the mentioned error, or also something else? And is the video working, or no video is created?
In most cases, the input video is incorrect. Wrong input format (not fitting to file extension) or worse like ending at wrong frame.
Perhaps you can make the video available?
PS: Needed to add -safe 0 to the second command to avoid error [concat # 0x7fbfd1000000] Unsafe file name './small.mp4'
Hint: Do not use file extension .sh for your list of video files. This extension is used for shell scripts, so it can be confusing. Just use .txt.
UPDATE #Massimo Vantaggio
We should not create new answers, but I cannot comment yours and I also don't know how to continue our discussion, so I edit my answer.
Your videos don't look very different. Can't see, what's wrong with the first one.
Perhaps you could use ffprobe -report input.mp4 to get more informations. Look for errors or warnings.
My assumption is still that the video was cut in a hard way (by conversion software), so keyframes are messed up or something else.
You can also try to first reencode your video with ffmpeg. After that, it should be complete compatible with ffmpeg ;)
Something like this:
ffmpeg -i small.mp4 -acodec aac -ab 192k -vcodec libx264 -vb 1024k -f mp4 output.mp4
Use -ab and -vb from your input video, or at least the bitrate from input. Quality will decrease a little bit and file size increase, but it should be okay.

How add scale in my ffmpeg command

i want convert video from any format to mp4. so i am using command:
ffmpeg -i ttt.mp4 -vcodec copy -acodec copy test.mp4
this is working perftectly but now i also add scale in this -s 320:240.
There also many other command for convert LIKE :
ffmpeg -i inputfile.avi -s 320x240 outputfile.avi
but after convert by this command video not play in html5 player
BUT this is not working so tell me in my command how i add scale;
So please provide me solution for this .
Thanks in advance.
You have several problems:
In your command, you have -vcodec copy you cannot scale video without reencoding.
In the command you randomly found on the Internet, they are using AVI, which is not HTML5-compatible.
What you should do is:
ffmpeg -i INPUT -s 320x240 -acodec copy OUT.mp4
Adding to Timothy_G:
Video copy will ignore the video filter chain of ffmpeg, so no scaling is available (man ffmpeg is a great source of information that you will not find on Google). Notice that once you start decoding-filtering-encoding (i.e., no copy) the process will be much slower (x100 time slower or even more). The libx264 is recommended if you want compatibility with all browsers.
$ ffmpeg -i INPUT -s 320x240 -threads 4 -c:a copy -c:v libx264 OUT.mp4
vp9 will provide nearly 50% extra bandwidth saving, but only for supported browsers (Firefox/Chrome), and the encoding will much slower compared to libx264 (that itself is much slower that v:c copy):
$ ffmpeg -i INPUT -s 320x240 -c:a copy -c:v vp9 OUT.webm
Notice that there is a set of formats (containers) accepted by browsers (most admit mp4, some also webm, ...) and for each format there is a set of audio/video codecs accepted. For example you can use mp3 or aac with an mp4 file (container), but not with webm files.
http://en.wikipedia.org/wiki/HTML5_video#Supported_video_formats

Converted mp4 h264 baseline format loads long time

I have converted my video to mp4 x264 baseline format and it works fine with all pc/mobile phones , the problem is it takes long time to load the video while googling came to know that ffmpeg converts and sets the index file at the eof the video so it loads to the end to read and then plays the video, So any advices would be appreciatable to cut short the loading time.
Note:tryied out QT index swapper2 but dint give much difference , please advice .
this is the cmd i used to convert -
ffmpeg -i … -c:v libx264 -profile:v baseline -level 1 …
Thanks for your time .
You have several options to relocate the moov atom so the video can begin playback before it is completely downloaded by the client.
-movflags faststart
The easiest is the option -movflags faststart when re-encoding:
ffmpeg -i input -c:v libx264 -profile:v baseline -movflags faststart output.mp4
If you already encoded your .mp4 file, but simply want to move the atom:
ffmpeg -i input.mp4 -codec copy -movflags faststart output.mp4
You may need to get a more recent ffmpeg version to use this option. See the FFmpeg download page for links to ffmpeg builds for Linux, OS X, and Windows, or you can follow a step-by-step guide to compile ffmpeg.
qt-faststart
Alternatively you can use the qt-faststart tool that comes with the ffmpeg source:
cd ~/ffmpeg/tools
make qt-faststart
./qt-faststart input.mp4 output.mp4
MP4Box
Or you could use MP4Box (usually provided by the gpac package depending on your distro):
MP4Box -add input.mp4 output.mp4
Also See
FFmpeg and x264 Encoding Guide
FFmpeg and AAC Audio Encoding Guide

Hardsub/Converting via Windows commandline

I have been trying to hardsub a video via cmd for a long time now. Still i could not find a proper way of doing it. I tried HandbrakeCLI, ffmpeg and mencoder but still could not find a way to do it. I got so closer to hardsubbing with HandbrakeCLI but there were some codeset problems and it wasn't really a hardsub at the end. I really need to find a way to hardsub .avi/.mp4 files via CMD. If you know any ways to do it please help me out! Thanks.
Try this:
mencoder -sub sub.srt -utf8 -font 'Arial Unicode MS' in.mp4 -o out.mp4 -of lavf -oac copy -fafmttag 0x706D -ovc x264 -x264encopts profile=baseline:bitrate=300k
After this I have to pass it through ffmpeg:
ffmpeg -i out.mp4 -acodec copy -vcodec copy final.mp4
as there is some issue with mp4 generated by mencoder, it does not play on some android phones.

Merge/Join images & video files together using mencoder or ffmpeg

Hi i have command to merge video files
but i want to join an image to a video file.
What i am doing:
1) convert image to mp4 using ffmpeg
2) joining this converted video to my selected video using mencoder
but it prommpts an error:
cannot mix video only files with audio-video files try -nosound.
i also added -nosound but with this the resultant file does not contains any audio.
what to do?
ffmpeg command:
-y -i Garden.jpg -s 640x480 converted.mp4
this converted .mp4 file is created properly but with no audio
mencoder command:
-oac mp3lame -ovc lavc -noodml -o output.mp4 converted.mp4 selected.mp4
Please help..
If you target is Windows, converting the result to msmpeg4v2 (avi) or mpeg1video (mpg) or asf (wmv) would probably work best.
Note, ASF files often have .wmv or .wma extensions in Windows. It should also be mentioned that Microsoft claims a patent on the ASF format, and may sue or threaten users who create ASF files with non-Microsoft software. It is strongly advised to avoid ASF where possible.
Read this for full list.
Here is a free command line tool which can join MPEG 1 files:
http://mpgtx.sourceforge.net/#Download
(Windows exe available). Did not try it on my own, however.
EDIT: another alternative may be to utilize VirtualDub. You have to write your merge command to a script and pass the script name per command line:
http://www.virtualdub.org/blog/pivot/entry.php?id=20
However, you have to get yourself through the syntax of the scripting language
http://www.virtualdub.org/docs/vdscript.txt
(I did not try this by myself programmatically, have only used virtual dub via GUI interface to concat video files, which worked really well.)
FFmpeg can accomplish this easily with the following command:
ffmpeg -i vid-1.mp4 -i vid-2.mp4 -ar 44100 -ab 64k -ac 1 -c:a libmp3lame -filter_complex '[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]' -map '[v]' -map '[a]' output.mp4

Resources