[FFmpeg-user] Problem with reencoded videos.
Adam Kłobukowski
adamklobukowski at gmail.com
Mon Feb 4 17:46:12 CET 2013
Hello
Executive summary first: I'm encoding videos with ffmpeg, to play them
on my Sony Bravia TV via DLNA. They always stop at about 27m40s point
and I'm unable to play them further (or rewind over that point. As I do
not think I'm able to make Sony fix their firmware, I'm asking for help
here.
Long story: as Sony TV are a bit picky what they play, I created a bash
script to reencode everything into a format that will play: mp4 with
h264 video stream. Because I do not like wasting CPU cycles (and reduced
quality), I made my script to use 'copy' is source video stream is
already h264. Here is the most important part of this script:
function encode()
{
NAME="$1"
NEWNAME=${NAME%.*}".mp4"
VCODEC="copy"
ACODEC="copy"
VTEST=`mplayer -msglevel identify=6 -frames 0 "$NAME" 2>&1 | grep -e
"ID_VIDEO_FORMAT=H264"`
ATEST=`mplayer -msglevel identify=6 -frames 0 "$NAME" 2>&1 | grep -e
"ID_AUDIO_FORMAT=MP4A"`
# if [ ! -n "$VTEST" ]; then
TEST=`mplayer -msglevel identify=6 -frames 0 "$NAME" 2>&1 | grep
-e "ID_VIDEO_BITRATE="`
BITRATE=$(trim `echo "$TEST" | cut -d= -f2`)
if [[ ${BITRATE%.*} -lt "1500000" ]]; then
BITRATE=1500000
fi
VCODEC='libx264 -b:v '${BITRATE}
# fi
if [ ! -n "$ATEST" ]; then
TEST=`mplayer -msglevel identify=6 -frames 0 "$NAME" 2>&1 | grep
-e "ID_AUDIO_BITRATE="`
BITRATE=$(trim `echo "$TEST" | cut -d= -f2`)
unset ATEST
ATEST=`mplayer -msglevel identify=6 -frames 0 "$NAME" 2>&1 |
grep -e "ID_AUDIO_FORMAT=8193"`
if [ -n "$ATEST" ]; then
BITRATE=$((BITRATE/4))
fi
ACODEC='aac -ab '${BITRATE}
fi
ffmpeg -threads 4 -i "$NAME" -vcodec $VCODEC -acodec $ACODEC
-strict experimental -f mp4 "$NEWNAME"
}
(I'm using mplayer because I found it's output easier to parse in shell
script, then ffprobe).
Aditional info: I tried few DLNA servers (all with transcoding off) and
the effect is ok. Files play ok in totem or vlc.
What I found out is, that when I force reencoding (always use -vcodec
libx264), video will play just fine on my TV!
Is it possible to make some 'fix' to have videos that my tv will be able
to play and still use 'copy'?
Now, an example:
original video ffprobe output:
ffprobe version git-2012-12-26-a2349dc Copyright (c) 2007-2012 the
FFmpeg developers
built on Dec 26 2012 19:55:46 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)
configuration: --enable-gpl --enable-libass --enable-libfaac
--enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-librtmp --enable-libtheora
--enable-libvorbis --enable-libvpx --enable-x11grab --enable-libx264
--enable-nonfree --enable-version3
libavutil 52. 12.100 / 52. 12.100
libavcodec 54. 81.100 / 54. 81.100
libavformat 54. 50.102 / 54. 50.102
libavdevice 54. 3.102 / 54. 3.102
libavfilter 3. 30.101 / 3. 30.101
libswscale 2. 1.103 / 2. 1.103
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Input #0, matroska,webm, from 'file.mkv':
Duration: 02:00:22.17, start: 0.000000, bitrate: 6492 kb/s
Chapter #0.0: start 0.000000, end 759.759000
Metadata:
title : 00:00:00.000
Chapter #0.1: start 759.759000, end 1176.092000
Metadata:
title : 00:12:39.759
Chapter #0.2: start 1176.092000, end 1739.571000
Metadata:
title : 00:19:36.092
Chapter #0.3: start 1739.571000, end 2568.608000
Metadata:
title : 00:28:59.571
Chapter #0.4: start 2568.608000, end 3001.540000
Metadata:
title : 00:42:48.608
Chapter #0.5: start 3001.540000, end 3600.055000
Metadata:
title : 00:50:01.540
Chapter #0.6: start 3600.055000, end 4149.520000
Metadata:
title : 01:00:00.055
Chapter #0.7: start 4149.520000, end 4786.824000
Metadata:
title : 01:09:09.520
Chapter #0.8: start 4786.824000, end 5414.117000
Metadata:
title : 01:19:46.824
Chapter #0.9: start 5414.117000, end 5940.852000
Metadata:
title : 01:30:14.117
Chapter #0.10: start 5940.852000, end 6694.771000
Metadata:
title : 01:39:00.852
Chapter #0.11: start 6694.771000, end 7222.173000
Metadata:
title : 01:51:34.771
Stream #0:0(eng): Video: h264 (High), yuv420p, 1280x536 [SAR 1:1 DAR
160:67], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536
kb/s (default)
Metadata:
title : DTS
Stream #0:2(eng): Subtitle: subrip (default)
Metadata:
title : English
Stream #0:3(eng): Subtitle: subrip
Metadata:
title : English SDH
Stream #0:4(eng): Subtitle: subrip
Metadata:
title : English Commentary
ffmpeg with vcodec copy output (I took a liberty of removing most of
frame= lines, there were no errors):
$ ffmpeg -threads 4 -i file.mkv -vcodec copy -acodec aac -ab 384000
-strict experimental -f mp4 file.mp4
ffmpeg version git-2012-12-26-a2349dc Copyright (c) 2000-2012 the FFmpeg
developers
built on Dec 26 2012 19:55:46 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)
configuration: --enable-gpl --enable-libass --enable-libfaac
--enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-librtmp --enable-libtheora
--enable-libvorbis --enable-libvpx --enable-x11grab --enable-libx264
--enable-nonfree --enable-version3
libavutil 52. 12.100 / 52. 12.100
libavcodec 54. 81.100 / 54. 81.100
libavformat 54. 50.102 / 54. 50.102
libavdevice 54. 3.102 / 54. 3.102
libavfilter 3. 30.101 / 3. 30.101
libswscale 2. 1.103 / 2. 1.103
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Input #0, matroska,webm, from 'file.mkv':
Duration: 02:00:22.17, start: 0.000000, bitrate: 6492 kb/s
Chapter #0.0: start 0.000000, end 759.759000
Metadata:
title : 00:00:00.000
Chapter #0.1: start 759.759000, end 1176.092000
Metadata:
title : 00:12:39.759
Chapter #0.2: start 1176.092000, end 1739.571000
Metadata:
title : 00:19:36.092
Chapter #0.3: start 1739.571000, end 2568.608000
Metadata:
title : 00:28:59.571
Chapter #0.4: start 2568.608000, end 3001.540000
Metadata:
title : 00:42:48.608
Chapter #0.5: start 3001.540000, end 3600.055000
Metadata:
title : 00:50:01.540
Chapter #0.6: start 3600.055000, end 4149.520000
Metadata:
title : 01:00:00.055
Chapter #0.7: start 4149.520000, end 4786.824000
Metadata:
title : 01:09:09.520
Chapter #0.8: start 4786.824000, end 5414.117000
Metadata:
title : 01:19:46.824
Chapter #0.9: start 5414.117000, end 5940.852000
Metadata:
title : 01:30:14.117
Chapter #0.10: start 5940.852000, end 6694.771000
Metadata:
title : 01:39:00.852
Chapter #0.11: start 6694.771000, end 7222.173000
Metadata:
title : 01:51:34.771
Stream #0:0(eng): Video: h264 (High), yuv420p, 1280x536 [SAR 1:1 DAR
160:67], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536
kb/s (default)
Metadata:
title : DTS
Stream #0:2(eng): Subtitle: subrip (default)
Metadata:
title : English
Stream #0:3(eng): Subtitle: subrip
Metadata:
title : English SDH
Stream #0:4(eng): Subtitle: subrip
Metadata:
title : English Commentary
Output #0, mp4, to 'file.mp4':
Metadata:
encoder : Lavf54.50.102
Chapter #0.0: start 0.000000, end 759.759000
Metadata:
title : 00:00:00.000
Chapter #0.1: start 759.759000, end 1176.092000
Metadata:
title : 00:12:39.759
Chapter #0.2: start 1176.092000, end 1739.571000
Metadata:
title : 00:19:36.092
Chapter #0.3: start 1739.571000, end 2568.608000
Metadata:
title : 00:28:59.571
Chapter #0.4: start 2568.608000, end 3001.540000
Metadata:
title : 00:42:48.608
Chapter #0.5: start 3001.540000, end 3600.055000
Metadata:
title : 00:50:01.540
Chapter #0.6: start 3600.055000, end 4149.520000
Metadata:
title : 01:00:00.055
Chapter #0.7: start 4149.520000, end 4786.824000
Metadata:
title : 01:09:09.520
Chapter #0.8: start 4786.824000, end 5414.117000
Metadata:
title : 01:19:46.824
Chapter #0.9: start 5414.117000, end 5940.852000
Metadata:
title : 01:30:14.117
Chapter #0.10: start 5940.852000, end 6694.771000
Metadata:
title : 01:39:00.852
Chapter #0.11: start 6694.771000, end 7222.173000
Metadata:
title : 01:51:34.771
Stream #0:0(eng): Video: h264 ([33][0][0][0] / 0x0021), yuv420p,
1280x536 [SAR 1:1 DAR 160:67], q=2-31, 23.98 fps, 16k tbn, 1k tbc (default)
Stream #0:1(eng): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz,
5.1(side), fltp, 384 kb/s (default)
Metadata:
title : DTS
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (dca -> aac)
Press [q] to stop, [?] for help
frame= 152 fps=0.0 q=-1.0 size= 1310kB time=00:00:06.27
bitrate=1710.9kbits/s
(...)
frame=173160 fps=192 q=-1.0 Lsize= 4572079kB time=02:00:22.18
bitrate=5186.0kbits/s
video:4391288kB audio:172523kB subtitle:0 global headers:0kB muxing
overhead 0.181172%
ffprobe output of file encoded with vcodec copy:
ffprobe version git-2012-12-26-a2349dc Copyright (c) 2007-2012 the
FFmpeg developers
built on Dec 26 2012 19:55:46 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)
configuration: --enable-gpl --enable-libass --enable-libfaac
--enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-librtmp --enable-libtheora
--enable-libvorbis --enable-libvpx --enable-x11grab --enable-libx264
--enable-nonfree --enable-version3
libavutil 52. 12.100 / 52. 12.100
libavcodec 54. 81.100 / 54. 81.100
libavformat 54. 50.102 / 54. 50.102
libavdevice 54. 3.102 / 54. 3.102
libavfilter 3. 30.101 / 3. 30.101
libswscale 2. 1.103 / 2. 1.103
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf54.50.102
Duration: 02:00:22.22, start: 0.021333, bitrate: 5186 kb/s
Chapter #0.0: start 0.000000, end 759.759000
Metadata:
title : 00:00:00.000
Chapter #0.1: start 759.759000, end 1176.092000
Metadata:
title : 00:12:39.759
Chapter #0.2: start 1176.092000, end 1739.571000
Metadata:
title : 00:19:36.092
Chapter #0.3: start 1739.571000, end 2568.608000
Metadata:
title : 00:28:59.571
Chapter #0.4: start 2568.608000, end 3001.540000
Metadata:
title : 00:42:48.608
Chapter #0.5: start 3001.540000, end 3600.055000
Metadata:
title : 00:50:01.540
Chapter #0.6: start 3600.055000, end 4149.520000
Metadata:
title : 01:00:00.055
Chapter #0.7: start 4149.520000, end 4786.824000
Metadata:
title : 01:09:09.520
Chapter #0.8: start 4786.824000, end 5414.117000
Metadata:
title : 01:19:46.824
Chapter #0.9: start 5414.117000, end 5940.852000
Metadata:
title : 01:30:14.117
Chapter #0.10: start 5940.852000, end 6694.771000
Metadata:
title : 01:39:00.852
Chapter #0.11: start 6694.771000, end 7222.193667
Metadata:
title : 01:51:34.771
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
1280x536 [SAR 1:1 DAR 160:67], 4980 kb/s, 23.98 fps, 23.98 tbr, 16k tbn,
47.95 tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, 5.1,
fltp, 195 kb/s
Metadata:
handler_name : SoundHandler
ffmpeg with vcodec libx264 output (I took a liberty of removing most of
frame= lines, there were no errors):
$ ffmpeg -threads 4 -i file.mkv -vcodec libx264 -b:v 1500000 -acodec aac
-ab 384000 -strict experimental -f mp4 file.mp4
ffmpeg version git-2012-12-26-a2349dc Copyright (c) 2000-2012 the FFmpeg
developers
built on Dec 26 2012 19:55:46 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)
configuration: --enable-gpl --enable-libass --enable-libfaac
--enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-librtmp --enable-libtheora
--enable-libvorbis --enable-libvpx --enable-x11grab --enable-libx264
--enable-nonfree --enable-version3
libavutil 52. 12.100 / 52. 12.100
libavcodec 54. 81.100 / 54. 81.100
libavformat 54. 50.102 / 54. 50.102
libavdevice 54. 3.102 / 54. 3.102
libavfilter 3. 30.101 / 3. 30.101
libswscale 2. 1.103 / 2. 1.103
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Input #0, matroska,webm, from 'file.mkv':
Duration: 02:00:22.17, start: 0.000000, bitrate: 6492 kb/s
Chapter #0.0: start 0.000000, end 759.759000
Metadata:
title : 00:00:00.000
Chapter #0.1: start 759.759000, end 1176.092000
Metadata:
title : 00:12:39.759
Chapter #0.2: start 1176.092000, end 1739.571000
Metadata:
title : 00:19:36.092
Chapter #0.3: start 1739.571000, end 2568.608000
Metadata:
title : 00:28:59.571
Chapter #0.4: start 2568.608000, end 3001.540000
Metadata:
title : 00:42:48.608
Chapter #0.5: start 3001.540000, end 3600.055000
Metadata:
title : 00:50:01.540
Chapter #0.6: start 3600.055000, end 4149.520000
Metadata:
title : 01:00:00.055
Chapter #0.7: start 4149.520000, end 4786.824000
Metadata:
title : 01:09:09.520
Chapter #0.8: start 4786.824000, end 5414.117000
Metadata:
title : 01:19:46.824
Chapter #0.9: start 5414.117000, end 5940.852000
Metadata:
title : 01:30:14.117
Chapter #0.10: start 5940.852000, end 6694.771000
Metadata:
title : 01:39:00.852
Chapter #0.11: start 6694.771000, end 7222.173000
Metadata:
title : 01:51:34.771
Stream #0:0(eng): Video: h264 (High), yuv420p, 1280x536 [SAR 1:1 DAR
160:67], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536
kb/s (default)
Metadata:
title : DTS
Stream #0:2(eng): Subtitle: subrip (default)
Metadata:
title : English
Stream #0:3(eng): Subtitle: subrip
Metadata:
title : English SDH
Stream #0:4(eng): Subtitle: subrip
Metadata:
title : English Commentary
[libx264 @ 0x325ad60] using SAR=1/1
[libx264 @ 0x325ad60] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[libx264 @ 0x325ad60] profile High, level 3.1
[libx264 @ 0x325ad60] 264 - core 129 r2 1cffe9f - H.264/MPEG-4 AVC codec
- Copyleft 2003-2012 - http://www.videolan.org/x264.html - options:
cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1
psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1
cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6
lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0
bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1
b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250
keyint_min=23 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr
mbtree=1 bitrate=1500 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4
ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'file.mp4':
Metadata:
encoder : Lavf54.50.102
Chapter #0.0: start 0.000000, end 759.759000
Metadata:
title : 00:00:00.000
Chapter #0.1: start 759.759000, end 1176.092000
Metadata:
title : 00:12:39.759
Chapter #0.2: start 1176.092000, end 1739.571000
Metadata:
title : 00:19:36.092
Chapter #0.3: start 1739.571000, end 2568.608000
Metadata:
title : 00:28:59.571
Chapter #0.4: start 2568.608000, end 3001.540000
Metadata:
title : 00:42:48.608
Chapter #0.5: start 3001.540000, end 3600.055000
Metadata:
title : 00:50:01.540
Chapter #0.6: start 3600.055000, end 4149.520000
Metadata:
title : 01:00:00.055
Chapter #0.7: start 4149.520000, end 4786.824000
Metadata:
title : 01:09:09.520
Chapter #0.8: start 4786.824000, end 5414.117000
Metadata:
title : 01:19:46.824
Chapter #0.9: start 5414.117000, end 5940.852000
Metadata:
title : 01:30:14.117
Chapter #0.10: start 5940.852000, end 6694.771000
Metadata:
title : 01:39:00.852
Chapter #0.11: start 6694.771000, end 7222.173000
Metadata:
title : 01:51:34.771
Stream #0:0(eng): Video: h264 ([33][0][0][0] / 0x0021), yuv420p,
1280x536 [SAR 1:1 DAR 160:67], q=-1--1, 1500 kb/s, 24k tbn, 23.98 tbc
(default)
Stream #0:1(eng): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz,
5.1(side), fltp, 384 kb/s (default)
Metadata:
title : DTS
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libx264)
Stream #0:1 -> #0:1 (dca -> aac)
Press [q] to stop, [?] for help
frame= 59 fps=0.0 q=17.0 size= 1kB time=00:00:02.62 bitrate=
4.4kbits/s
(...)
frame=173160 fps= 15 q=32766.0 Lsize= 1485457kB time=02:00:22.18
bitrate=1684.9kbits/s
video:1307036kB audio:172523kB subtitle:0 global headers:0kB muxing
overhead 0.398641%
[libx264 @ 0x325ad60] frame I:2648 Avg QP:20.55 size: 45677
[libx264 @ 0x325ad60] frame P:92447 Avg QP:22.99 size: 10427
[libx264 @ 0x325ad60] frame B:78065 Avg QP:24.23 size: 3247
[libx264 @ 0x325ad60] consecutive B-frames: 26.5% 36.8% 9.8% 26.9%
[libx264 @ 0x325ad60] mb I I16..4: 13.6% 72.4% 14.0%
[libx264 @ 0x325ad60] mb P I16..4: 2.6% 7.2% 0.7% P16..4: 43.0%
9.8% 6.0% 0.0% 0.0% skip:30.7%
[libx264 @ 0x325ad60] mb B I16..4: 0.1% 0.4% 0.0% B16..8: 43.3%
2.4% 0.4% direct: 1.0% skip:52.4% L0:41.4% L1:55.4% BI: 3.2%
[libx264 @ 0x325ad60] final ratefactor: 22.32
[libx264 @ 0x325ad60] 8x8 transform intra:70.2% inter:82.2%
[libx264 @ 0x325ad60] coded y,uvDC,uvAC intra: 55.5% 63.9% 23.1% inter:
15.1% 19.5% 0.7%
[libx264 @ 0x325ad60] i16 v,h,dc,p: 39% 20% 9% 32%
[libx264 @ 0x325ad60] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 14% 24% 6% 7%
8% 7% 7% 6%
[libx264 @ 0x325ad60] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 17% 15% 6% 9%
9% 8% 6% 5%
[libx264 @ 0x325ad60] i8c dc,h,v,p: 57% 18% 20% 5%
[libx264 @ 0x325ad60] Weighted P-Frames: Y:2.4% UV:1.2%
[libx264 @ 0x325ad60] ref P L0: 66.1% 13.6% 14.0% 6.2% 0.1%
[libx264 @ 0x325ad60] ref B L0: 85.8% 12.6% 1.6%
[libx264 @ 0x325ad60] ref B L1: 96.3% 3.7%
[libx264 @ 0x325ad60] kb/s:1482.54
Please help.
AdamK
More information about the ffmpeg-user
mailing list