0

I download videos from YouTube using youtube-dl https://www.youtube.com/.... , but their format is .mp4. My TV doesn't support this format, therefore i need to have (dowload) them in .avi. Please help me :)

ArcaGraphy
  • 11
  • 1
  • 4

2 Answers2

2

you can run the following command to convert all of your mp4 videos to avi:

for i in `find . -type f -name '*.mp4'`; do avconv -i "$i" -qscale 1 "${i/.mp4/.avi}"; done

For more info on avconv, see the manpages:

man avconv

Alternatively, you can download as a specific format by using the --recode-video FORMAT flag like so (but the only formats supported are : mp4|flv|ogg|webm|mkv):

youtube-dl --recode-video flv 

for format .flv, followed by the URL.

Newer versions of youtube-dl may allow recoding to avi:

youtube-dl --recode-video avi

and newer versions of Ubuntu (15.04+) will allow you to prefer ffmpeg over avconv if ffmpeg is installed:

youtube-dl --recode-video avi --prefer-ffmpeg    
andrew.46
  • 38,003
  • 27
  • 156
  • 232
mchid
  • 43,546
  • 8
  • 97
  • 150
1

While mchid's answer may result in a working file on your device, re-encoding an entire video is not what you should do just because your device is picky with standard formats and therefore default to legacy non-standard formats.

Assuming that the optimal format for your device is AVI is awful and stupid. The AVI container can be used with a lot of different formats (like MKV, just older and worse) and despite it's popularity in warezing before podcasting, streaming and video on demand were widely available, it's anything but a standard meant for content distribution.


Here is an excerpt of what avconv did in my test case:

  Stream #0:0 -> #0:0 (h264 -> mpeg4)
  Stream #0:1 -> #0:1 (aac -> libmp3lame)

What's MPEG4? Mediainfo output:

Video
ID                                       : 0
Format                                   : MPEG-4 Visual
Format profile                           : Simple@L1
Format settings, BVOP                    : No
Format settings, QPel                    : No
Format settings, GMC                     : No warppoints
Format settings, Matrix                  : Default (H.263)
Codec ID                                 : FMP4
Duration                                 : 1mn 29s
Bit rate                                 : 3 479 Kbps
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate                               : 29.970 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.056
Stream size                              : 36.9 MiB (100%)
Writing library                          : Lavc54.92.100

Notice the switch to the very old H.263 (Simple@L1 – you may want to study what profiles and levels mean in video encoding… or better not). A sane default when no further information is provided, but you shouldn't use H.263 on a modern device unless you're really desperate.

Comparison with original and result both mangled through JPEG, though I uploaded 1080p PNG screenshots (view full size!). And that's just a low detail scene from a video game with almost no motion.

enter image description here enter image description here

TL;DR:

  1. Get a device that isn't picky with formats and makes you waste time and energy by re-encoding.
  2. Use a converter that offers templates for achieving quality with sane encoding settings, like Handbrake.
  3. Try -vcodec copy to change the container, but avoid re-encoding video with avconv/ffmpeg.
LiveWireBT
  • 28,763
  • I changed the command to include the flag -qscale 1 which sets the video quality to the highest available instead of the default which is pretty low. – mchid Jan 17 '15 at 06:54
  • @mchid That's also possible, but will result in huge files (my went from 32 MB h264 to ~32 MB H.263 default to 240 MB with qscale 1) and be beyond what dumb "smartdevices" can handle. The profile is still Simple@L1, some advanced features that are typically enabled in Xvid may help. Apparently you can label the result as Xvid without using any advanced settings, which adds confusion http://askubuntu.com/q/262163/40581 https://libav.org/faq.html#How-do-I-encode-Xvid-or-DivX-video-with-avconv_003f. Note that I already upvoted you answer before writing mine. – LiveWireBT Jan 17 '15 at 10:30
  • @mchid As far as I know, certain levels for MPEG2 and H.264 are standards for HDTV broadcasting and should work on any modern TV/device (don't these even have YouTube apps?), H.263 compatibility may be a byproduct but I don't think it's part of the standard. Sane H.264 settings in whatever container the device expects should be suggested, therefore my 3 suggestions. (All this fiddling just because one device cannot parse MP4 but accepts the same format in a transport stream without moaning.) :) – LiveWireBT Jan 17 '15 at 10:42