Transcoding to MPEG-2 MP2V

Microsoft Windows specific usage questions
Forum rules
Please post only Windows specific questions in this forum category. If you don't know where to post, please read the different forums' rules. Thanks.
jhb50
Blank Cone
Blank Cone
Posts: 45
Joined: 24 May 2010 21:56

Transcoding to MPEG-2 MP2V

Postby jhb50 » 27 May 2010 14:42

Note: This post has been rewritten a number of times, based on hours of testing. It is now correct.
Further updated to add transcoding of .flv files.

Sometimes it is necessary, when a video player does not have the power to decode some video streams, as is the case with the WII, to use a more powerful server to transcode the files into a lesser format and stream the result to the player.

In order to transcode and stream any video(including Hi-def AVC/AAC .mp4 files where the video resolution can be up to 1280 and the audio up to 6 channels)
to a .mpg file with lower resolution 640 Mpeg-2 video and 5.1 AC-3 audio with embedded subtitles, you can use the following command: (Remove the (x86) if you are not on a 64 bit system)

"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" -vvv %1 --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=8000,scale=.5,width=640,fps=30,acodec=a52,ab=384,channels=6
,samplerate=48000,soverlay}:std{access=http,mux=ts,dst=:8081} --sub-autodetect-fuzzy=4

Without these specific parameters VLC may dump, or refuse to encode either the video or audio.
vb=8000 gives maximum picture quality at 8mbps but may be changed. (normal DVD quality is 4000)
Note: If you are streaming over your LAN, 8000 may be too high, and you may get buffering delays..if so drop the rate to 6000 and try again.
scale=.5 is required to display the full picture
width=640 is required to maintain the original aspect ratio
fps=30 is required to use the mp2v encoder
acodec=a52 (ac-3) is required to support up to 6 channels
ab=384 gives maximum audio quality but may be changed to 128 or 256
channels=6 is the ac-3default and is optional
samplerate=48000 is the ac-3 default and is optional
soverlay is optional and will overlay any subtitles on the streamed video
http is the streaming protocol and it can be changed to whatever protocol your player will accept. (I have tested udp and mmsh)
mux=ts works with http and mmsh and apparently is required by udp
dst=:8081 is required with http to prevent a bind error and makes the stream available to any client on your lan. Udp and mmsh require dst=client-url:port
--sub-autodetect-fuzzy=4 is optional and says to detect those subtitles which match the filename exactly.
use --no-sub-autodetect-file instead if you do not want subtitles detected and overlayed.

This command works with .mpg, .mp4, divx .avi, and .mkv files but because of a VLC bug it does not work with .ts files if there is a corresponding subtitle file present. By renaming the .srt to .srtx or using --no-sub-autodetect-file , .ts files will also transcode and stream but without the embedded subtitles. If you need subs with .ts (which I do to display the subs that I have extracted from the closed captions in my HDTV ASTC .ts stream captures), your only choice interim to a VLC fix is to use WinFF and "convert to DVD" with the DVD HQ-Fullscreen or Widescreen Profile depending on the source aspect. This will give you an .mpg file which will transcode and stream with subtitles.

This command will also work with .flv files containing H.263 or VP6 video streams, but due to a bug in VLC, .flv files containing AVC video and AAC audio streams wil not transcode. The work around is to pre-transcode these files to AVC/AC-3.mp4 files using ffmpeg and then transcode and stream them with the above command. The process to do this is now built into the STREAMVIDEO.BAT file posted below. See my post below regarding why you might want to permanently pretranscode all these avc/aac.flv files to avc/ac3.mkv.

You may now test that this VLC (Server) streaming command is working by starting a VLC (client) on your PC with the command ' VLC http://localhost:8081 '. I use this "PlayStream.bat (Remove the (x86) if you are not on a 64 bit system)

=========================================
@echo off
: URL must contain @ sign
"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" http://@192.168.1.10:8081
=========================================

Note that you cannot use the "Play Network Stream" in the GUI to start playing this stream. You must issue the command. I have also noticed that the VLC client may get confused at times after playing a few streams and either not display the embedded subs or overlay successive subs. Restarting the VLC client fixes that.

Hopefully others may benefit from this info.
Last edited by jhb50 on 07 Jun 2010 23:05, edited 12 times in total.

VLC_help
Mega Cone Master
Mega Cone Master
Posts: 25661
Joined: 13 Sep 2006 14:16

Re: Transcoding to MPEG-2 MP2V

Postby VLC_help » 27 May 2010 15:39

Yep. MPEG-2 encoder is very picky child.

jhb50
Blank Cone
Blank Cone
Posts: 45
Joined: 24 May 2010 21:56

Re: Transcoding to MPEG-2 MP2V

Postby jhb50 » 28 May 2010 02:46

Here is a Bat file that may be used to transcode and stream using the above command(s). (Remove the (x86) if you are not on a 64 bit system)

Just put a shortcut to the BAT in your Sendto directory, and you can send any video file to the bat and it will stream!
Once VLC starts, you can then use "Media/Open File" to select the next file to stream.

UPDATED TO HANDLE AVC/AAC.flv files. Note you must have the following installed on your system for this feature to work, and you must modify the two statements in the bat to point at them.

MediaInfo.exe (Command line version) from
http://downloads.sourceforge.net/mediai ... s_i386.zip on 32 bit systems or
http://downloads.sourceforge.net/mediai ... ws_x64.zip on 64 bit systems
and FFMPEG.exe from http://www.videohelp.com/download/FFmpe ... n-22140.7z

StreamVideo.bat
==============================================
@echo off

: This bat is used to stream video with VLC using http
: A corresponding player using http must be started on each client. ie: VLC http:\\@server-url:8081

if "%~x1"==".ts" goto :playit
if "%~x1"==".avi" goto :playit
if "%~x1"==".mpg" goto :playit
if "%~x1"==".mp4" goto :playit
if "%~x1"==".mkv" goto :playit
if "%~x1"==".flv" goto :playit

echo invalid filetype - cannot stream

goto :exit

:playit

: Check if another instance is running.
if not exist C:\temp\VLCFlag.txt goto :doit
echo previous stream is active - close it first
goto :exit

:doit
: Set running flag
echo VLC is Running > C:\temp\VLCflag.txt

: there is a bug in VLC which prevents .ts from playing if subs are present.
: use VLC option to ignore subs for .ts
if "%~x1"==".ts" goto :nosubs

: there is a bug in VLC that prevents .flv with AVC from converting

if NOT "%~x1" == ".flv" goto :normal

: Check .flv files for AVC video streams.
C:\Programs\MediaInfo_CLI\MediaInfo.exe --Inform=Video;%%Format%% %1 > C:\TEMP\media.txt
: Read MI Value string back in
set /p format= < C:\TEMP\media.txt
if .%format% == .AVC goto :avcflv

:normal

: This transcodes all files to MPEG-2 video with AC3 audio on-the-fly as they are streamed.
: must use fps=30, channels=6, scale=.5, width=640, acodec=a52, samplerate=48000
"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" -vvv %1 --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=6000,scale=.5,width=640,fps=30,acodec=a52,ab=384,channels=6,samplerate=48000,soverlay}:std{access=http,mux=ts,dst=:8081} --sub-autodetect-fuzzy=4

goto :exit

:nosubs

"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" -vvv %1 --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=8000,scale=.5,width=640,fps=30,acodec=a52,ab=384,channels=6,samplerate=48000}:std{access=http,mux=ts,dst=:8081} --no-sub-autodetect-file

goto :exit

:avcflv

if exist C:\TEMP\Video.mp4 erase C:\TEMP\Video.mp4 > nul

echo.
echo THE AUDIO WILL FIRST TRANSCODE TO AC3... PLEASE WAIT A MINUTE or TWO...

: There is a bug that prevents VLC from streaming AAC and audio is lost
: so must use ffmpeg to preconvert avc/aac.flv to avc/ac3.mp4
: This only takes about 1 minute for each 30 minutes of video
: Need to use a 2 in front of redirect to stop ffmpeg output from displaying.

"C:\Programs\FFMPEG\ffmpeg.exe" -i %1 -vcodec copy -acodec ac3 -ar 48000 -ab 128kb -ac 2 -f mp4 "C:\TEMP\video.mp4" 2> C:\TEMP\ffmpeg.txt

: Transcode the .mp4 file to MPEG-2 and just copy the ac3 audio
"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" -vvv "C:\TEMP\video.mp4" --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=6000,scale=.5,width=640,fps=30,soverlay}:std{access=http,mux=ts,dst=:8080} --sub-autodetect-fuzzy=4

:exit

: Clean-up
if exist C:\TEMP\media.txt erase C:\TEMP\media.txt > nul
if exist C:\TEMP\Video.mp4 erase C:\TEMP\Video.mp4 > nul

: Remove Running Flag after first warning.
if exist C:\temp\VLCFlag.txt erase C:\temp\VLCFlag.txt

:==================================================
Last edited by jhb50 on 07 Jun 2010 22:13, edited 2 times in total.

jhb50
Blank Cone
Blank Cone
Posts: 45
Joined: 24 May 2010 21:56

Re: Transcoding to MPEG-2 MP2V

Postby jhb50 » 07 Jun 2010 07:14

I have updated the above posts to reflect the addition of support for .flv files containing avc video and aac audio streams.

This format is now in common use by sites such as YouTube, Hulu and PBS for streaming video to Flash Player, which tools such as Real Player and StreamTransport can download. While VLC can play these captured files, due to a VLC bug it cannot trancode or stream them. I have developed a workaround however consisting of a relatively fast (about 2 mins per hour of video on my I7) pretranscode of the AAC to AC3 into .mp4, followed by the transcode and streaming of the resulting .mp4 file which does work in VLC. This process is embedded in the revised streamvideo.bat

I am now able to stream all my videos regardless of source and play them on my TV using my WII and the soft moded Homebrew Channel program WIIMC. See http://www.wiimc.org/forum/viewtopic.php?f=4&t=405

jhb50
Blank Cone
Blank Cone
Posts: 45
Joined: 24 May 2010 21:56

Re: Transcoding to MPEG-2 MP2V

Postby jhb50 » 07 Jun 2010 23:22

To workaround a bug, the previous post includes the process to pre-transcode avc/aac.flv files prior issuing the streaming command.

Note however that many players have problems with these avc/aac.flv files. While VLC is OK, MPC-HC has problems jumping back and forth and WMP terminates! You may therefore want to permanently convert these .flv files to AVC/AC3.mkv format using the following BAT which only takes 2-3 minutes per hour of video. These files will then play and stream correctly. Again you need the mediainfo.exe and ffmpeg.exe referenced in the above post. It is also possible that ffmpeg might repeatedly issue the message: "[aac@ xxxxxx]SBR not implemented for some files..." This was fixed on May 5, 2010, so be sure to use ffmpeg release 23107 or later.

Convert avc-aac flv to avc-ac3 mkv.bat
==========================================
@echo on

: This bat will convert AVC/AAC.flv files to AVC/AC3.mkv files.
: These files from Hulu and YouTube etc do not play well with MPC,
: abort WMP and play but will not transcode or stream in VLC.
: The original filename.flv will be used to create filename.flv.mkv in the same directory.

if "%~x1"==".flv" goto :checkavc

echo Source is not an .flv file. Exiting...
pause
goto :exit

:checkavc
pause
: Check for AVC
C:\Programs\MediaInfo_CLI\MediaInfo.exe --Inform=Video;%%Format%% %1 > C:\TEMP\media.txt
: Read MI Value string back in
set /p format= < C:\TEMP\media.txt
if .%format% == .AVC goto :doit

echo .flv file does not contain an avc video stream. Exiting ....
pause
goto :exit

pause
:doit

"C:\Programs\FFMPEG\ffmpeg.exe" -i %1 -vcodec copy -acodec ac3 -ar 48000 -ab 160kb %1.mkv

:exit
if exist C:\TEMP\media.txt erase C:\TEMP\media.txt > nul

========================================


Return to “VLC media player for Windows Troubleshooting”

Who is online

Users browsing this forum: blueice_haller and 59 guests