Copied FLV file with FFMPEG won't open in any program except VLC

1

I am trying to add an overlay to a FLV file fetched from YouTube. The input file is 4.4MB and playable by QuickTime so it doesn't appear to have any issues.

ffmpeg -i input.flv -vf drawtext="fontfile='arial.ttf':text='hello':fontsize=9" output.flv

I receive the following output after a surprisingly short few seconds:

  ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
  built on May 15 2013 13:13:12 with Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
  configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libtheora --enable-libschroedinger --enable-libopenjpeg --enable-libmodplug --enable-libvpx --enable-libspeex --enable-libfreetype --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/clang --arch=x86_64 --enable-yasm --enable-gpl --enable-postproc --enable-libx264 --enable-libxvid
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.flv':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2010-01-31 13:44:29
  Duration: 00:02:20.85, start: 0.000000, bitrate: 249 kb/s
    Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 22050 Hz, mono, fltp, 56 kb/s
    Metadata:
      creation_time   : 2010-01-31 13:44:29
      handler_name    : (C) 2007 Google Inc. v08.13.2007.
    Stream #0:1(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 191 kb/s, 29.84 fps, 29.97 tbr, 30k tbn, 29.97 tbc
    Metadata:
      creation_time   : 2010-01-31 13:44:29
      handler_name    : (C) 2007 Google Inc. v08.13.2007.
File 'output.flv' already exists. Overwrite ? [y/N] y
Output #0, flv, to 'output.flv':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Lavf54.63.104
    Stream #0:0(und): Video: flv1 ([2][0][0][0] / 0x0002), yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 1k tbn, 29.97 tbc
    Metadata:
      creation_time   : 2010-01-31 13:44:29
      handler_name    : (C) 2007 Google Inc. v08.13.2007.
    Stream #0:1(und): Audio: mp3 ([2][0][0][0] / 0x0002), 22050 Hz, mono, fltp
    Metadata:
      creation_time   : 2010-01-31 13:44:29
      handler_name    : (C) 2007 Google Inc. v08.13.2007.
Stream mapping:
  Stream #0:1 -> #0:0 (mpeg4 -> flv)
  Stream #0:0 -> #0:1 (aac -> libmp3lame)
Press [q] to stop, [?] for help
frame= 4201 fps=1386 q=10.0 Lsize=    4304kB time=00:02:20.85 bitrate= 250.3kbits/s    
video:3603kB audio:550kB subtitle:0 global headers:0kB muxing overhead 3.618454%

Now output.flv is left unplayable by QuickTime, and Flash complains that the audio codec is not supported. The only program capable of playing it successfully is VLC. Its filesize is the same as input.flv. What could be the cause of this, and what options could produce a playable copy?

UPDATE

Truncated output received from using various encoders:

ffmpeg -i input.flv -c:v libxvid -c:a copy -q:v 5 output2.flv
...
Stream mapping:
  Stream #0:1 -> #0:0 (mpeg4 -> libxvid)
  Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 4201 fps=303 q=5.0 Lsize=    6597kB time=00:02:20.85 bitrate= 383.7kbits/s    
video:5491kB audio:968kB subtitle:0 global headers:0kB muxing overhead 2.120003%


ffmpeg -i input.flv -c:v mpeg4 -c:a copy -q:v 5 output3.flv
...
Stream mapping:
  Stream #0:1 -> #0:0 (mpeg4 -> mpeg4)
  Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 4201 fps=2523 q=5.0 Lsize=    6852kB time=00:02:20.85 bitrate= 398.5kbits/s    
video:5746kB audio:968kB subtitle:0 global headers:0kB muxing overhead 2.044082%


ffmpeg -i input.flv -c copy outputcopy.flv
...
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 4201 fps=0.0 q=-1.0 Lsize=    4394kB time=00:02:20.85 bitrate= 255.6kbits/s    
video:3289kB audio:968kB subtitle:0 global headers:0kB muxing overhead 3.216934%

Getting the info on any of these files gives me a lot of the following types of errors (where n is an increasing integer):

- Stream discovered after head already parsed
- header damaged
- max_analyze_duration 5000000 reached at 5014000 microseconds
- Could not find codec parameters for stream n (Video: mpeg4, yuv420p): unspecified size
  Consider increasing the value for the 'analyzeduration' and 'probesize' options
- decoding for stream n failed

This is followed by messages of type:

Stream #0:n: Video: mpeg4, yuv420p, 1k tbr, 1k tbn

I just upgraded ffmpeg and its dependencies through MacPorts and am still out of luck. This is happening for every FLV file I've tried from YouTube and elsewhere.

danronmoon

Posted 2013-07-08T14:59:35.167

Reputation: 123

Answers

5

Flash Video

According to the specification, Flash Video only supports VP-6 and H.264 video natively, amongst a few others. This means you're going to have to stick to using FFmpeg's flv encoder, or you switch to H.264 with the libx264 encoder – see the x264 encoding guide for the options you can use:

ffmpeg -i input.flv … -c:v libx264 output.flv

You therefore cannot use the MPEG-4 Part 2 encoders mpeg4 or libxvid, as they're only supported in the libavformat-based players, which includes anything from Android phones to VLC, but – of course – not QuickTime.

QuickTime

As for QuickTime, it does not officially support FLV. Unfortunately it is entirely reasonable to assume that QuickTime cannot play all files. Installing Perian (now EOL) should make it play some FLV files, but not all.

Like the specification predicts, I've only got it to play FLV files with the flv encoder as it's called in ffmpeg, which is the Sorenson Spark H.263 codec, and the libx264 encoder.

Audio

FLV supports both MP3 and AAC, so I don't know what's up with Flash complaining about an invalid codec there. You might want to try an AAC encoder:

ffmpeg -i input.flv … -c:a aac -strict experimental output.flv

… or use any other AAC encoder that your build supports.

slhck

Posted 2013-07-08T14:59:35.167

Reputation: 182 472

-c:v mpeg4 gives me similar results. -c:v libxvid takes a more realistic amount of time to process but still does not produce a playable output. Even a straight copy command ffmpeg -i input.flv -c:v copy -c:a copy output.flv without filters does not work unfortunately. – danronmoon – 2013-07-08T15:30:12.097

Please don't truncate your output of the other commands. If it's too long for the question body, paste it to a pasteboard – this will make it easier to identify problems. Do you have a sample maybe? Does the file play, say in VLC?

– slhck – 2013-07-08T16:59:05.177

The truncated output for the last 3 was the same as the first complete output at the top (bunch of metadata for the original file). OK I must admit my original command (as well as output3.flv, thanks for this) does work with VLC but not with anything else (Flash says audio codec is not supported). This is good news but I think it is reasonable to expect playback in other video players, so I'm rewording the question. – danronmoon – 2013-07-08T17:45:14.787

Seems a bit tricky. With QuickTime you'll have to use the officially supported FLV video codecs, at least according to my tests. Haven't been able to find an MPEG-4 Part 2 video stream in an FLV container from YouTube yet, though – seems I only either get H.264 or Sorenson H.263-encoded ones. – slhck – 2013-07-08T18:45:38.990

-c:a aac causes ffmpeg to hang, forcing me to close and open a new terminal. -c:a mp3 still produces a file unplayable with QT. The youtube id this question is based on is rNp-cj5dEA8. If you could give me a YT id and the associated command that works for you (original and copy both playable by QT), I could try it out and see if it works on my machine. BTW what type of ffmpeg build do you have? Starting to think I might have to downgrade or reinstall. – danronmoon – 2013-07-08T21:01:08.530

For the video ID you gave me I only get two possible FLV options (based on what youtube-dl shows), one with H.264 video inside, and one with Sorenson H.263. Both are playable in QuickTime. I don't get an MPEG-4 version – are you maybe using some other YouTube downloading service that does a transcode? I just tried the "regular" ffmpeg -i input.flv output.flv and it's playable in QuickTime. Both on latest ffmpeg compiled from Git as well as 1.2.1.

– slhck – 2013-07-09T18:31:38.170

I've been using MacTubes to test #5. I just installed youtube-dl and downloaded #5 and I noticed that the filesize and resolution were different from the one I downloaded from MacTubes, and that the video encoder is flv1, the same as what you had. Even more mind-boggling is the fact that I can't get the file downloaded from youtube-dl to play in QT. So I think the issue is getting too localized, and with all the discrepancies I've been encountering I think the sane route is to sing VLC's praises and focus on other tasks. Thanks for your help. – danronmoon – 2013-07-09T19:14:25.530

Sure. Ping me in chat or here if you need to cross-check something though. I'm sorry I couldn't help you any more, but there seem to be many factors in play here. – slhck – 2013-07-09T19:20:46.373