Rectangle 27 4

MP4 and MOV are the only formats that use 'atoms'. Hence, qtfaststart should not be used on any other file type.

Hmm, interesting. Then paperclip-ffmpeg should not run the qtfaststart process on flv, ogg, webm, and etc. Looks like I'll have to find a way to avoid qtfaststart from being run on these formats. this is what I had:

has_attached_file :name, :styles => {  :mp4iphone => { :geometry => "560x994>", :format => "mp4", :streaming => true, :processors => [:ffmpeg, :qtfaststart] }, :flviphone => { :geometry => "560x994>", :format => "flv", :streaming => true, :processors => [:ffmpeg] } }

ruby on rails - ffmpeg drops the moov atom when coverting mp4 to ogg, ...

ruby-on-rails video ffmpeg paperclip
Rectangle 27 5

You have to convert them into an MPEG format that can be easily concatenated. Below is a script I use and call "ffcat" for my GoPro videos. It essentially runs several "ffmpeg -i" commands which produce concatenate-able MPEG, which is piped to an ffmpeg command that then converts them to an H.264 mp4 file.

It also sizes the videos to 720p but you may not want that.

The "h264options" are flags I recently found on the internet at h264.code-shop.com

cmd="( "

h264options="-vcodec libx264 -b 512k -flags +loop+mv4 -cmp 256 \
 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 \
 -me_method hex -subq 7 -trellis 1 -refs 5 -bf 3 \
 -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -coder 1 -me_range 16 \
   -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10\
 -qmax 51 -qdiff 4"

outfile="out-`date +%F-%H%M.%S`.mp4"

for i; do
    cmd="${cmd}ffmpeg -i $i -ab 256000 -vb 10000000 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -g 100 -f mpeg -; "
done
cmd="${cmd} ) | ffmpeg -y -i - -threads 8 ${h264options} -vb 10000000 -acodec libfaac -ar 44100 -ab 128k -s 1280x720 ${outfile}"
echo "${cmd}"
eval ${cmd}

This has the negative effect of transcoding the video twice. I can imagine you might have to transcode once but twice shouldn't be necessary.

MP4 files do not need to be converted into an MPEG format before being concatenated. In order to do the most simple concatenation, where all the input files are mp4 and the output file is also mp4, no transcoding is needed at all. The ffmpeg command line in Windows 7 (using bcmpinc's inputs.txt file, see below) is: ffmpeg -f concat -i inputs.txt -c copy output.mp4

ffmpeg: Combine/merge multiple mp4 videos not working, output only con...

ffmpeg
Rectangle 27 7

ffmpeg -i file -c:v libx264 -x264opts keyint:25 [preset/rate control options] out.mp4
ffmpeg -i file -c:v libvpx-vp9 -g 25 [speed/rate control options] out.webm

Both commands will place a new keyframe every 25 frames. If you want more than that (e.g. one keyframe every frame), then perhaps you don't care about compression as much as you care about speed, and it may be worth looking into intra-only codecs such as FFv1.

FFMPEG: How to encode for seekable video at high key frame interval - ...

video ffmpeg mp4 requestanimationframe webm
Rectangle 27 3

Simple concat works for mp4 and mkv files if all the input videos have the same codec and you want output video also in same codec. https://trac.ffmpeg.org/wiki/Concatenate you need to creat a text file like

# this is a comment
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
ffmpeg -f concat -i mylist.txt -c copy output

I have used the example from the same reference page, it works pretty well. The only issue comes when video is not properly captured. It might introduce audio video sync issues because it just copies the PTS and DTS information from the source videos to the destination video. To get a full proof solution you need to read video packet-by-packet and then put together all the packets in one video with customized optimizations like dropping repeating PTS packets and maintaining monotonic PTS values.

ffmpeg: Combine/merge multiple mp4 videos not working, output only con...

ffmpeg
Rectangle 27 13

Step 1: (strip audio from video, and create single audio file)

ffmpeg -i IMG_0113.mp4 -c:v libvpx -s 160x90 -threads 4 -b:v 25k -tile-columns 4 -frame-parallel 1 -an -keyint_min 30 -g 30 -f webm video_160x90_25k.webm

ffmpeg -i IMG_0113.mp4 -c:v libvpx -s 160x90 -threads 4 -b:v 50k -tile-columns 4 -frame-parallel 1 -an -keyint_min 30 -g 30 -f webm video_160x90_50k.webm

ffmpeg -i IMG_0113.mp4 -vn -acodec libvorbis -ab 128k audio_128k.webm

Step 2: (using sample_muxer from the libwebm project available here, to create the video cue points)

sample_muxer -i video_160x90_25k.webm -o video_160x90_25k_cued.webm

sample_muxer -i video_160x90_50k.webm -o video_160x90_50k_cued.webm

Step 3: (Use ffmpeg to create the audio cue points)

ffmpeg -i audio_128k.webm -vn -acodec libvorbis -ab 128k -dash 1 audio_128k_cued.webm

Step 4: (Use ffmpeg to create the webm dash manifest file .mpd)

ffmpeg -f webm_dash_manifest -i video_160x90_25k_cued.webm -f webm_dash_manifest -i video_160x90_50k_cued.webm -f webm_dash_manifest -i audio_128k_cued.webm -c copy -map 0 -map 1 -map 2 -f webm_dash_manifest -adaptation_sets "id=0,streams=0,1 id=1,streams=2" manifest.mpd

ffmpeg (my version atleast), was not creating the cue points in the video files correctly (when adding the -dash 1) param. I determined this by probing the video files, and by understanding the webm file format (read this, if you'd like to know more).

I then stumbled upon sample_muxer from reading this page, and decided to see if it would better handle the video cue points that ffmpeg wasn't getting right. Whoop Whoop, it did!

I noticed that the cue points in the extracted audio file from ffmpeg (using the -dash 1 param), were being created correctly!

The ffmpeg generation of the webm dash manifest is also working nicely!

For playing back the video, I found shaka-player worked best but I could not use it as I required video playback from a cefpython container and the shaka-player did not work on the latest cef (chromium embedded framework) included in the cefpython release.

This issue of FFMPEG still not got resolved in the latest version at this point .

@StormyKnight, you'll notice that the '-b:v' args have different values. higher bitrate for video (and many more options) will produce larger better looking video. As a VOD service, one would prepare various sized / quality videos (from the same source video) for a 'dynamic' player to load. Players look for a manifest file of videos and their bitrates (poor to best quality), and will decide which to play according to the clients connectivity speed.

webm dash encoding... What are the correct ffmpeg parameters? - Stack ...

ffmpeg webm dash.js
Rectangle 27 1

Rotate with encoding using the correct ffmpeg

Rotating without re-encoding is not possible unless:

To correctly understand the steps needed to this, one should start by reading or at least skimming this question:

Summary: avconv is a fork of ffmpeg, debian maintainer chose avconv, you have to compile the correct ffmpeg from source.

The next step would be compiling the correct ffmpeg from source as is detailed here:

The final step is using the commands found in other posts:

Please do not provide links with no summaries of what's written there to avoid link rot problems. If it's possible summarise the content of the pages you've added to your answer in your own words.

ffmpeg - Rotate mp4 videos without re-encoding - Stack Overflow

ffmpeg rotation debian video-encoding avconv
Rectangle 27 25

I ended up using mpg as the intermediate format and it worked (NOTE this is a dangerous example, -qscale 0 will re-encode the video...)

ffmpeg -i 1.mp4 -qscale 0 1.mpg
ffmpeg -i 2.mp4 -qscale 0 2.mpg
cat 1.mpg 2.mpg | ffmpeg -f mpeg -i - -qscale 0 -vcodec mpeg4 output.mp4

As of this comment, -sameq was removed. Use -qscale 0 instead.

-sameq does not mean "same quality" and has been removed from ffmpeg as mentioned by @XavierHo.

It seems a shame to have to transcode the video through an intermediate format just to concatenate two files. You'll get generation loss. Better to not go deeper than the container format and use the concat command in ffmpeg, as @rogerdpack does above.

How come this is an accepted answer? This is very bad method.

@SargeBorsch Because it works. I've tried everything else on the page-- None of them work.

h.264 - Concatenate two mp4 files using ffmpeg - Stack Overflow

ffmpeg h.264 mp4
Rectangle 27 25

I ended up using mpg as the intermediate format and it worked (NOTE this is a dangerous example, -qscale 0 will re-encode the video...)

ffmpeg -i 1.mp4 -qscale 0 1.mpg
ffmpeg -i 2.mp4 -qscale 0 2.mpg
cat 1.mpg 2.mpg | ffmpeg -f mpeg -i - -qscale 0 -vcodec mpeg4 output.mp4

As of this comment, -sameq was removed. Use -qscale 0 instead.

-sameq does not mean "same quality" and has been removed from ffmpeg as mentioned by @XavierHo.

It seems a shame to have to transcode the video through an intermediate format just to concatenate two files. You'll get generation loss. Better to not go deeper than the container format and use the concat command in ffmpeg, as @rogerdpack does above.

How come this is an accepted answer? This is very bad method.

@SargeBorsch Because it works. I've tried everything else on the page-- None of them work.

h.264 - Concatenate two mp4 files using ffmpeg - Stack Overflow

ffmpeg h.264 mp4
Rectangle 27 25

I ended up using mpg as the intermediate format and it worked (NOTE this is a dangerous example, -qscale 0 will re-encode the video...)

ffmpeg -i 1.mp4 -qscale 0 1.mpg
ffmpeg -i 2.mp4 -qscale 0 2.mpg
cat 1.mpg 2.mpg | ffmpeg -f mpeg -i - -qscale 0 -vcodec mpeg4 output.mp4

As of this comment, -sameq was removed. Use -qscale 0 instead.

-sameq does not mean "same quality" and has been removed from ffmpeg as mentioned by @XavierHo.

It seems a shame to have to transcode the video through an intermediate format just to concatenate two files. You'll get generation loss. Better to not go deeper than the container format and use the concat command in ffmpeg, as @rogerdpack does above.

How come this is an accepted answer? This is very bad method.

@SargeBorsch Because it works. I've tried everything else on the page-- None of them work.

h.264 - Concatenate two mp4 files using ffmpeg - Stack Overflow

ffmpeg h.264 mp4
Rectangle 27 66

Of course you could code up some C/C++ and link to -lav*, basically creating a simplified version of ffmpeg just for extracting frames, and maybe even do it as a php extension (also I wouldn't run it as the same user, let alone in the same process). But the result is very unlikely to be faster, because you would only avoid some forking and setup overhead, but your likely problem is actually the decoding, which would still be the same.

Instead, you should first look into using ffmpeg in fast seeking mode (or fast/accurate hybrid mode). Their wiki states about fast seeking:

This example will produce one image frame (out1.jpg) somewhere around the third minute from the beginning of the movie. The input will be parsed using keyframes, which is very fast. The drawback is that it will also finish the seeking at some keyframe, not necessarily located at specified time (00:03:00), so the seeking will not be as accurate as expected.

Fast seeking is less accurate, but a damn lot faster, as ffmpeg will not actually need to decode (most of) the movie during the seek, while fast/accurate hybrid mode is good compromise. Read the wiki page for all available options.

As of FFmpeg 2.1, when transcoding with ffmpeg (i.e. not stream copying), -ss is now accurate even when used as an input option. Previous behavior can be restored with the -noaccurate_seek option. (source)

So with 2.1+, "hybrid" seeking shouldn't be required anymore for accurate results when it comes to re-encodes (and saving to .jpeg is a re-encode). It is enough to do the usual fast seeking (-ss ... -i ...) instead of slow seeking (-i ... -ss ...).

The difference in execution time was about 20 minutes (3GB video). Saved the day.

Fastest way to extract a specific frame from a video (PHP/ffmpeg/anyth...

php video ffmpeg mp4 video-processing
Rectangle 27 57

I decided to go for the ipod640 preset because it means the video can be viewed nicely on an iPhone or iPod touch. Of course, you can change the settings around a bit, get rid of the '-vpre ipod640', change the resolution or quality. Anyway the command is:

ffmpeg -i video_source_file.ext -vcodec libx264 -vpre ipod640 -b 250k -bt 50k -acodec libfaac -ab 56k -ac 2 -s 480x320 video_out_file.mp4

move some information to the front of the file so the video can play before it loads

qt-faststart video_out_file.mp4 video_out_file_quickstart.mp4

This depends on you having ffmpeg2theora installed. Also, I have only tested it with the input file being the output file from the previous ffmpeg conversion. The command is:

ffmpeg2theora -o video_out_file.ogv video_out_file.mp4

I did not test it for Windows. It's more likely to work on OS X and Linux than Windows.

well ffmpeg works on windows cause I can convert to other codecs, but when trying to convert to mp4 it complains and I was wondering if their were additional settings required

I think that qt-faststart was moved into the main build of ffmpeg in the 1.0 release. You can now apply it with the flags: -movflags +faststart

ffmpeg settings for converting to mp4 and ogg for HTML5 video - Stack ...

video html5 ffmpeg mp4 ogg
Rectangle 27 10

Forget about FFmpeg, use MP4Box instead, it is easy and faster:

mp4box -add video1.mp4 -cat video2.mp4 -cat video3.mp4 output.mp4

If you are on Windows you can use YAMB which is a GUI for MP4Box that works great: http://www.videohelp.com/tools/YAMB

mp4box

Some time ago FFmpeg has added a filter that can concatenate identical media files, here is the info: stackoverflow.com/a/11175851/218418

ffmpeg: Combine/merge multiple mp4 videos not working, output only con...

ffmpeg
Rectangle 27 9

Assuming you want to concatenate the movie, you can use the following command:

ffmpeg -f concat -i inputs.txt -vcodec copy -acodec copy Mux1.mp4

With the following text in inputs.txt:

file 75_540_38HQ2.mp4 
file 76_70_20.mp4 
file 76_173_80.mp4
file 81_186_35.mp4

Note: some distributions (like Ubuntu) do not have ffmpeg in their repository and instead define ffmpeg to be an alias of avconv. This won't work with avconv, so in such a case you have to compile ffmpeg yourself. You can check whether you have the real ffmpeg by running ffmpeg and checking if the first output line ends with "the FFmpeg developers".

ffmpeg: Combine/merge multiple mp4 videos not working, output only con...

ffmpeg
Rectangle 27 36

There are numerous ways to encode mp4 videos, and encoding them for mobile devices is even more complex. I'm not sure what you mean by "low cost mobile" do you mean low cost as in the device, or the bandwidth needed to play said video?

Here are some ffmpeg examples from the post ...

ffmpeg -i input_file.avi -vcodec libx264 -vprofile high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=-1:480 -threads
  0 -acodec libvo_aacenc -b:a 128k output_file.mp4
ffmpeg -i inputfile.avi -vcodec libx264 -vprofile high -preset slower -b:v 1000k -vf scale=-1:576 -threads 0 -acodec libvo_aacenc -ab
  196k output.mp4

From the examples there, some of the key things you might need to pay attention to are ...

-b:v 500k
-b:a 128k

Those are bitrates of the video v and audio a, the lower the number the lower the quality but also the better it might 'play' on a low end device.

scale=-1:480

That will scale the video down to a smaller size, see more info about that in the post)

-vprofile baseline
baseline

Primarily for low-cost applications that require additional data loss robustness, this profile is used in some videoconferencing and mobile applications. This profile includes all features that are supported in the Constrained Baseline Profile, plus three additional features that can be used for loss robustness (or for other purposes such as low-delay multi-point video stream compositing). The importance of this profile has faded somewhat since the definition of the Constrained Baseline Profile in 2009. All Constrained Baseline Profile bitstreams are also considered to be Baseline Profile bitstreams, as these two profiles share the same profile identifier code value.

this all conversion, my input and output file is of same format.

I'm trying to convert an AVI to MP4 with your 360p command but "-acodec libvo_aacenc -ab 128k" is not working, if I replace it with "-acodec copy", it works, Its error is "Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height". Should i set more parameters for audio? if yes, what are does params?

@user1202498 -acodec copy will not actually encode your audio at all but instead just copy the audio stream from the old file into the new one. If you have support for libvo_aacenc (do you?) you shouldn't have to set anything special. You can also try -codec:a aac -strict experimental to use ffmpeg's native aac encoding.

Thank you very much, all the solutions out there are having outdated parameters

what about -movflags +faststart output option in order to "move some information to the beginning of your file and allow the video to begin playing before it is completely downloaded" trac.ffmpeg.org/wiki/Encode/H.264#faststartforwebvideo ?

Convert mp4 to maximum mobile supported MP4 using FFMPEG - Stack Overf...

mobile ffmpeg h.264
Rectangle 27 6

I think you want something to the effect of :

-g 12 -bf 2 sgop

The -g flag sets the GOP size (as you already mentioned), the -bf 2 says that 2 B-frames should be inserted between each set of P-frames, and the sgop strictly enforces the GOP size.

video - Coding a certain MP4 GOP with FFMPEG - Stack Overflow

video ffmpeg mp4 mpeg
Rectangle 27 15

http://handbrake.fr is a nice high level tool with a lot of useful presets for mp4 for iPod, PS3, ... with both GUI and CLI interfaces for Linux, Windows and Mac OS X.

It comes with its own dependencies as a single statically linked fat binary so you have all the x264 / aac codecs included.

$ HandBrakeCLI -Z Universal -i myinputfile.mov -o myoutputfile.mp4

To list all the available presets:

$ HandBrakeCLI -z

linux - Convert a video to MP4 (H.264/AAC) with ffmpeg - Stack Overflo...

linux video ubuntu ffmpeg
Rectangle 27 7

From the ffmpeg man page "Examples" section:

You can put many streams of the same type in the output:

ffmpeg -i test1.avi -i test2.avi -vcodec copy -acodec copy \ -vcodec copy -acodec copy test12.avi -newvideo -newaudio

In addition to the first video and audio streams, the resulting output file test12.avi will contain the second video and the second audio stream found in the input streams list.

The "-newvideo", "-newaudio" and "-newsubtitle" options have to be specified immediately after the name of the output file to which you want to add them.

I'm not sure if this question/answer belongs on SuperUser.

-newvideo, -newaudio, -newsubtitle have been removed from the current version. You have to use the -map option. (which I haven't wrapped my brain around.) If somebody wants to show how to use -map to string together MP4s that would be awesome.

These docs describe the concat filter and how to use the -map option in that case: ffmpeg.org/trac/ffmpeg/wiki/

Note I'm having videos get corrupted if I concat very long files, so I'm going to try to mp4->mpeg then use simple concat.

The concat option in ffmpeg does not require the use of the -map option if you are really just concatenating the input files (e.g. you have two mp4 files, each 2 minutes in duration, and want to create a single mp4 file of 4 minutes duration as the output). The ffmpeg command line in Windows 7 (using bcmpinc's "inputs.txt" file, see above) is: ffmpeg -f concat -i inputs.txt -c copy output.mp4

ffmpeg: Combine/merge multiple mp4 videos not working, output only con...

ffmpeg
Rectangle 27 2

And in any case you may found ffmpeg build in which webm is not built-in.

./configure
--enable-libvpx

How to extract images from webm video using ffmpeg - Stack Overflow

video ffmpeg video-encoding webm libvpx
Rectangle 27 11

For .mp4 files (which I obtained from DailyMotion.com: a 50 minute tv episode, downloadable only in three parts, as three .mp4 video files) the following was an effective solution for Windows 7, and does NOT involve re-encoding the files.

I renamed the files (as file1.mp4, file2.mp4, file3.mp4) such that the parts were in the correct order for viewing the complete tv episode.

Then I created a simple batch file (concat.bat), with the following contents:

:: Create File List
echo file file1.mp4 >  mylist.txt 
echo file file2.mp4 >> mylist.txt
echo file file3.mp4 >> mylist.txt

:: Concatenate Files
ffmpeg -f concat -i mylist.txt -c copy output.mp4

The batch file, and ffmpeg.exe, must both be put in the same folder as the .mp4 files to be joined. Then run the batch file. It will typically take less than ten seconds to run.

The easiest solution by far.

h.264 - Concatenate two mp4 files using ffmpeg - Stack Overflow

ffmpeg h.264 mp4
Rectangle 27 11

For .mp4 files (which I obtained from DailyMotion.com: a 50 minute tv episode, downloadable only in three parts, as three .mp4 video files) the following was an effective solution for Windows 7, and does NOT involve re-encoding the files.

I renamed the files (as file1.mp4, file2.mp4, file3.mp4) such that the parts were in the correct order for viewing the complete tv episode.

Then I created a simple batch file (concat.bat), with the following contents:

:: Create File List
echo file file1.mp4 >  mylist.txt 
echo file file2.mp4 >> mylist.txt
echo file file3.mp4 >> mylist.txt

:: Concatenate Files
ffmpeg -f concat -i mylist.txt -c copy output.mp4

The batch file, and ffmpeg.exe, must both be put in the same folder as the .mp4 files to be joined. Then run the batch file. It will typically take less than ten seconds to run.

The easiest solution by far.

h.264 - Concatenate two mp4 files using ffmpeg - Stack Overflow

ffmpeg h.264 mp4