EzDevInfo.com

ffmpeg interview questions

Top ffmpeg frequently asked interview questions

Concatenate two mp4 files using ffmpeg

I'm trying to concatenate two mp4 files using ffmpeg. I need this to be an automatic process hence why I chose ffmpeg. I'm converting the two files into .ts files and then concatenating them and then trying to encode that concated .ts file. The files are h264 and aac encoded and I'm hoping to keep the quality the same or as close to original as possible.

ffmpeg -i part1.mp4 -vcodec copy -vbsf h264_mp4toannexb -acodec copy part1.ts
ffmpeg -i part2.mp4 -vcodec copy -vbsf h264_mp4toannexb -acodec copy part2.ts
cat part1.ts part2.ts > parts.ts
ffmpeg -y -i parts.ts -acodec copy -ar 44100 -ab 96k -coder ac -vbsf h264_mp4toannexb parts.mp4

Unfortunately I'm getting the following error message coming back from ffmpeg during encoding:

[h264 @ 0x1012600]sps_id out of range
[h264 @ 0x1012600]non-existing SPS 0 referenced in buffering period
[h264 @ 0x1012600]sps_id out of range
[h264 @ 0x1012600]non-existing SPS 0 referenced in buffering period
[NULL @ 0x101d600]error, non monotone timestamps 13779431 >= 13779431kbits/s    
av_interleaved_write_frame(): Error while opening file

This happens about half way through encoding which makes me think that you can't concat two .ts files together and have it work. Any help would be much appreciated.


Source: (StackOverflow)

Unknown encoder 'libx264'

I installed ffmpeg 0.8.9 on ubuntu11 by

./configure --enable-gpl --enable-nonfree --enable-pthreads --enable-libfaac --enable-libmp3lame --enable-libx264

When I run it

ffmpeg -y -i test.mp4 -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -vcodec libx264 -b 250k -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 250k -maxrate 250k -bufsize 250k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 320:240 -g 30 -async 2 a.ts

It said

Unknown encoder 'libx264'

(Note: the same error could occour with avconv)

How can I fix this? Thanks!


Source: (StackOverflow)

Advertisements

Crop MP3 to first 30 seconds

Original Question

I want to be able to generate a new (fully valid) MP3 file from an existing MP3 file to be used as a preview -- try-before-you-buy style. The new file should only contain the first n seconds of the track.

Now, I know I could just "chop the stream" at n seconds (calculating from the bitrate and header size) when delivering the file, but this is a bit dirty and a real PITA on a VBR track. I'd like to be able to generate a proper MP3 file.

Anyone any ideas?

Answers

Both mp3split and ffmpeg are both good solutions. I chose ffmpeg as it is commonly installed on linux servers and is also easily available for windows. Here's some more good command line parameters for generating previews with ffmpeg

  • -t <seconds> chop after specified number of seconds
  • -y force file overwrite
  • -ab <bitrate> set bitrate e.g. -ab 96k
  • -ar <rate Hz> set sampling rate e.g. -ar 22050 for 22.05kHz
  • -map_meta_data <outfile>:<infile> copy track metadata from infile to outfile

instead of setting -ab and -ar, you can copy the original track settings, as Tim Farley suggests, with:

  • -acodec copy

Source: (StackOverflow)

ffmpeg for a android (using tutorial: "ffmpeg and Android.mk")

I am trying to compile ffmpeg for a android. I have found several posts on this theme but non of these seems to work. If tried to build ffmpeg like it is posted on [1]. Did anybody successfully compile ffmpeg using theses tutorial? I am not sure how to realize step 4 to 5.

STEP4: Configuring ...

STEP5: cd to your NDK root dir, type make TARGET_ARCH=arm APP=ffmpeg-org

It seems to me that building an application like it is explained in the tutorial in step 5 need some previous steps. Unfortunately I have no app in the folder to make. I am using the current android ndk release 3 and checked out the actual ffmpeg releases from [3] and [4]. I am thankful for every advice.

[1] http://slworkthings.wordpress.com/
[2] http://gitorious.org/~olvaffe/ffmpeg/ffmpeg-android
[3] http://ffmpeg.org/download.html


Source: (StackOverflow)

Screenshot of the Nexus One from adb?

My goal is to be able to type a one word command and get a screenshot from a rooted Nexus One attached by USB.

So far, I can get the framebuffer which I believe is a 32bit xRGB888 raw image by pulling it like this:

adb pull /dev/graphics/fb0 fb0

From there though, I'm having a hard time getting it converted to a png. I'm trying with ffmpeg like this:

ffmpeg -vframes 1 -vcodec rawvideo -f rawvideo -pix_fmt rgb8888 -s 480x800 -i fb0 -f image2 -vcodec png image.png

That creates a lovely purple image that has parts that vaguely resemble the screen, but it's by no means a clean screenshot.


Source: (StackOverflow)

FFmpeg: How to split video efficiently?

I wish to split a large avi video into two smaller consecutive videos. I am using ffmpeg.

One way is to run ffmpeg two times:

ffmpeg -i input.avi -vcodec copy -acodec copy -ss 00:00:00 -t 00:30:00 output1.avi
ffmpeg -i input.avi -vcodec copy -acodec copy -ss 00:30:00 -t 00:30:00 output2.avi

But according to manpage of ffmpeg, I can make more than one ouput file from one input file using just one line:

ffmpeg -i input.avi -vcodec copy -acodec copy -ss 00:00:00 -t 00:30:00 output1.avi \
   -vcodec copy -acodec copy -ss 00:30:00 -t 00:30:00 output2.avi

My question is, does the later approach save computation time and memory?


Source: (StackOverflow)

FFMPEG (libx264) "height not divisible by 2"

I am trying to encode a .mp4 video from a set of frames using FFMPEG using the libx264 codec.

This is the command I am running:

/usr/local/bin/ffmpeg -r 24 -i frame_%05d.jpg -vcodec libx264 -y -an video.mp4

I sometimes get the following error:

[libx264 @ 0xa3b85a0] height not divisible by 2 (520x369)

After searching around a bit it seems that the issue has something to do with the scaling algorithm and can be fixed by adding a -vf argument.

However, in my case I don't want to do any scaling. Ideally, I want to keep the dimensions exactly the same as the frames. Any advice? Is there some sort of aspect ratio that h264 enforces?


Source: (StackOverflow)

Generating movie from python without saving individual frames to files

I would like to create an h264 or divx movie from frames that I generate in a python script in matplotlib. There are about 100k frames in this movie.

In examples on the web [eg. 1], I have only seen the method of saving each frame as a png and then running mencoder or ffmpeg on these files. In my case, saving each frame is impractical. Is there a way to take a plot generated from matplotlib and pipe it directly to ffmpeg, generating no intermediate files?

Programming with ffmpeg's C-api is too difficult for me [eg. 2]. Also, I need an encoding that has good compression such as x264 as the movie file will otherwise be too large for a subsequent step. So it would be great to stick with mencoder/ffmpeg/x264.

Is there something that can be done with pipes [3]?

[1] http://matplotlib.sourceforge.net/examples/animation/movie_demo.html

[2] http://stackoverflow.com/questions/2940671

[3] http://www.ffmpeg.org/ffmpeg-doc.html#SEC41


Source: (StackOverflow)

Live stream RTMP/RTSP player without using webview (WOWZA server) on Android

I am developing an Android application in which I want to publish as well as stream a video...

What I want is:

  1. My app records a video and that video is sent to the server

  2. The recorded video will be streamed live to another Android device at the same time..

I have completed the first task using javac and ffmpeg. I am stuck in the second task. I have searched a lot to stream the video from the server, but I didn't succeed. I don't want to use WebView and play the video in it. I want an RTMP player. This task has been completed in iOS... I want the same for Android. What is some link to fulfill my task?

P.S.:

I am using wowza server and RTMP stream. I would like to stream RTMP video (.flv)... If no solution is available, I would like to switch to RTSP and for that also, need a working link to follow..

Now I have switched to RTSP player [with wowza server] as I have not found an RTMP player without webview. How do I fix this issue?


Source: (StackOverflow)

Using FFmpeg in .net?

So I know its a fairly big challenge but I want to write a basic movie player/converter in c# using the FFmpeg library. However, the first obstacle I need to overcome is wrapping the FFmpeg library in c#. I've downloaded ffmpeg but couldn't compile it on Windows, so I downloaded a precompiled version for me. Ok awesome. Then I started looking for C# wrappers.

I have looked around and have found a few wrappers such as SharpFFmpeg (http://sourceforge.net/projects/sharpffmpeg/) and ffmpeg-sharp (http://code.google.com/p/ffmpeg-sharp/). First of all, I wanted to use ffmpeg-sharp as its LGPL and SharpFFmpeg is GPL. However, it had quite a few compile errors. Turns out it was written for the mono compiler, I tried compiling it with mono but couldn't figure out how. I then started to manually fix the compiler errors myself, but came across a few scary ones and thought I'd better leave those alone. So I gave up on ffmpeg-sharp.

Then I looked at SharpFFmpeg and it looks like what I want, all the functions P/Invoked for me. However its GPL? Both the AVCodec.cs and AVFormat.cs files look like ports of avcodec.c and avformat.c which I reckon I could port myself? Then not have to worry about licencing.

But I want to get this right before I go ahead and start coding. Should I:

  1. Write my own C++ library for interacting with ffmpeg, then have my C# program talk to the C++ library in order to play/convert videos etc.

OR

  1. Port avcodec.h and avformat.h (is that all i need?) to c# by using a whole lot of DllImports and write it entirely in C#?

First of all consider that I'm not great at C++ as I rarely use it but I know enough to get around. The reason I'm thinking #1 might be the better option is that most FFmpeg tutorials are in C++ and I'd also have more control over memory management than if I was to do it in c#.

What do you think? Also would you happen to have any useful links (perhaps a tutorial) for using FFmpeg?


Source: (StackOverflow)

How to generate gif from avi using ffmpeg? [closed]

I'm trying to extract a part of a video into an animated gif using the following command:

ffmpeg -i video.avi -t 5 out.gif

It generates an animated gif but the quality is insane. However when I generate gif image using:

ffmpeg -i video.avi -t 10 out%d.gif

It generates acceptable quality of gif images. How can i generate animated gif using the first command but the same quality as the second command?


Source: (StackOverflow)

How can I extract a good quality JPEG image from an H264 video file with ffmpeg?

Currently I am using this command to extract the images:

ffmpeg.exe -i 10fps.h264 -r 10 -f image2 10fps.h264_%03d.jpeg

But how can I improve the JPEG image quality?


Source: (StackOverflow)

ffmpeg converting mov files to mp4 [closed]

Hi i have just installed ffmpeg and i am trying to encode all my uploaded videos to .mp4 file most of the users currently upload .mov and i want to convert every video to .mp4.

i am running the command as follows.

ffmpeg -i movie.mov -vcodec copy -acodec cop out.mp4

But all i am getting is the following errors

ffmpeg version 0.8.5, Copyright (c) 2000-2011 the FFmpeg developers
  built on Aug 19 2012 11:38:20 with clang 3.1 (tags/Apple/clang-318.0.61)
  configuration: --enable-nonfree --enable-gpl --enable-version3 --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libfaac --enable-libxvid --enable-libx264 --enable-libvpx --enable-hardcoded-tables --enable-shared --enable-pthreads --disable-indevs --cc=clang
  libavutil    51.  9. 1 / 51.  9. 1
  libavcodec   53.  7. 0 / 53.  7. 0
  libavformat  53.  4. 0 / 53.  4. 0
  libavdevice  53.  1. 1 / 53.  1. 1
  libavfilter   2. 23. 0 /  2. 23. 0
  libswscale    2.  0. 0 /  2.  0. 0
  libpostproc  51.  2. 0 / 51.  2. 0
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'movie.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    creation_time   : 2012-03-28 07:13:20
  Duration: 00:00:26.23, start: 0.000000, bitrate: 12974 kb/s
    Stream #0.0(eng): Video: mjpeg, yuvj420p, 1280x720 [PAR 72:72 DAR 16:9], 12972 kb/s, 11.67 fps, 600 tbr, 600 tbn, 600 tbc
    Metadata:
      creation_time   : 2012-03-28 07:13:20
File 'out.mp4' already exists. Overwrite ? [y/N] y
Output #0, mp4, to 'out.mp4':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    creation_time   : 2012-03-28 07:13:20
    encoder         : Lavf53.4.0
    Stream #0.0(eng): Video: mjpeg, yuvj420p, 1280x720 [PAR 72:72 DAR 16:9], q=2-31, 12972 kb/s, 600 tbn, 600 tbc
    Metadata:
      creation_time   : 2012-03-28 07:13:20
Stream mapping:
  Stream #0.0 -> #0.0
Press [q] to stop, [?] for help
frame=  121 fps=  0 q=-1.0 size=   16408kB time=00:00:10.08 bitrate=13332.2kbitsframe=  306 fps=  0 q=-1.0 Lsize=   41543kB time=00:00:26.12 bitrate=13025.0kbits/s    
video:41538kB audio:0kB global headers:0kB muxing overhead 0.012531%

Can anyone point me in the right direction thanks


Source: (StackOverflow)

Convert image sequence to lossless movie [closed]

I have a sequence of images in TIF format, and I would like to create a movie at a fixed FPS (say 10 images per second) and that is lossless. Is there an easy way to do that? I've been trying with convert from Imagemagick, and ffmpeg, but I just can't figure out what settings to use to avoid any compression.


Source: (StackOverflow)

What are the differences and similarities between ffmpeg, libav, and avconv?

When I run ffmpeg on Ubuntu, it shows:

$ ffmpeg 
ffmpeg version v0.8, Copyright (c) 2000-2011 the Libav developers
  built on Feb 28 2012 13:27:36 with gcc 4.6.1
This program is not developed anymore and is only provided for compatibility. Use avconv instead (see Changelog for the list of incompatible changes).

Or it shows (depending on the Ubuntu version):

$ ffmpeg
ffmpeg version 0.8.5-6:0.8.5-0ubuntu0.12.10.1, Copyright (c) 2000-2012 the Libav developers
  built on Jan 24 2013 14:49:20 with gcc 4.7.2
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.

I found avconv on http://libav.org. I am just perplexed by them.


Source: (StackOverflow)