Skip to content

Commit

Permalink
[muxerMp4] Add config options to specify pixel aspect ratio, disguise…
Browse files Browse the repository at this point in the history
…d as usual DAR values
  • Loading branch information
eumagga0x2a committed Nov 26, 2017
1 parent 5fb6c2c commit 9056ceb
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 9 deletions.
2 changes: 2 additions & 0 deletions avidemux_plugins/ADM_muxers/muxerMp4/mp4_muxer.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mp4_muxer{
uint32_t:muxerType
bool:useAlternateMp3Tag
bool:forceAspectRatio
uint32_t:aspectRatio
}
8 changes: 4 additions & 4 deletions avidemux_plugins/ADM_muxers/muxerMp4/mp4_muxer.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// automatically generated by admSerialization.py, do not edit!
// automatically generated by admSerialization.py do not edit
#ifndef ADM_mp4_muxer_CONF_H
#define ADM_mp4_muxer_CONF_H
#include "string"
#pragma once
typedef struct {
uint32_t muxerType;
bool useAlternateMp3Tag;
bool forceAspectRatio;
uint32_t aspectRatio;
}mp4_muxer;
#endif
5 changes: 4 additions & 1 deletion avidemux_plugins/ADM_muxers/muxerMp4/mp4_muxer_desc.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const ADM_paramList mp4_muxer_param[]={
// automatically generated by admSerialization.py, do not edit!
extern const ADM_paramList mp4_muxer_param[]={
{"muxerType",offsetof(mp4_muxer,muxerType),"uint32_t",ADM_param_uint32_t},
{"useAlternateMp3Tag",offsetof(mp4_muxer,useAlternateMp3Tag),"bool",ADM_param_bool},
{"forceAspectRatio",offsetof(mp4_muxer,forceAspectRatio),"bool",ADM_param_bool},
{"aspectRatio",offsetof(mp4_muxer,aspectRatio),"uint32_t",ADM_param_uint32_t},
{NULL,0,NULL}
};
35 changes: 34 additions & 1 deletion avidemux_plugins/ADM_muxers/muxerMp4/muxerMP4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
mp4_muxer muxerConfig=
{
MP4_MUXER_MP4,
true
true,
false,
WIDE
};


Expand Down Expand Up @@ -100,6 +102,37 @@ bool muxerMP4::open(const char *file, ADM_videoStream *s,uint32_t nbAudioTrack,A
ADM_info("Video stream time base :%d,%d\n",video_st->time_base.num,video_st->time_base.den);
c->gop_size=15;

if(true==muxerConfig.forceAspectRatio)
{
float h=(float)(s->getHeight());
float w=h;
switch (muxerConfig.aspectRatio)
{
case 0:
w*=4.;
w/=3.;
break;
case 1:
w*=16.;
w/=9.;
break;
case 2:
w*=2.;
break;
case 3:
w*=64.;
w/=27.;
break;
}
int num=1,den=1;
av_reduce(&num, &den, (uint32_t)w, s->getWidth(),65535);
par->sample_aspect_ratio.num=num;
par->sample_aspect_ratio.den=den;
video_st->sample_aspect_ratio.num=num;
video_st->sample_aspect_ratio.den=den;
ADM_info("Forcing pixel aspect ratio of %d:%d\n",den,num);
}

if(initAudio(nbAudioTrack,a)==false)
{
printf("[MP4] Failed to init audio\n");
Expand Down
9 changes: 8 additions & 1 deletion avidemux_plugins/ADM_muxers/muxerMp4/muxerMP4.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ typedef enum
MP4_MUXER_PSP
}MP4_MUXER_TYPE;

typedef enum
{
STANDARD,
WIDE,
UNI,
CINEMA
}MP4_MUXER_DAR;
#include "mp4_muxer.h"
extern mp4_muxer muxerConfig;

Expand All @@ -42,4 +49,4 @@ class muxerMP4 : public muxerFFmpeg

};

#endif
#endif
11 changes: 9 additions & 2 deletions avidemux_plugins/ADM_muxers/muxerMp4/muxerMP4Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@
bool mp4Configure(void)
{
uint32_t fmt=(uint32_t)muxerConfig.muxerType;
uint32_t dar=(uint32_t)muxerConfig.aspectRatio;
bool alt=muxerConfig.useAlternateMp3Tag;
bool force=muxerConfig.forceAspectRatio;
diaMenuEntry format[]={{MP4_MUXER_MP4,"MP4"},{MP4_MUXER_PSP,"PSP"}};
diaElemMenu menuFormat(&fmt,QT_TRANSLATE_NOOP("mp4muxer","Muxing Format"),2,format,"");
diaElemToggle alternate(&alt,QT_TRANSLATE_NOOP("mp4muxer","Use alternate MP3 tag"));
diaElemToggle forceAR(&force,QT_TRANSLATE_NOOP("mp4muxer","Force aspect ratio"));
diaMenuEntry aspect[]={{STANDARD,"4:3"},{WIDE,"16:9"},{UNI,"18:9"},{CINEMA,"64:27"}};
diaElemMenu menuAspect(&dar,QT_TRANSLATE_NOOP("mp4muxer","Aspect Ratio (DAR)"),4,aspect,"");

diaElem *tabs[]={&menuFormat,&alternate};
if( diaFactoryRun(QT_TRANSLATE_NOOP("mp4muxer","MP4 Muxer"),2,tabs))
diaElem *tabs[]={&menuFormat,&alternate,&forceAR,&menuAspect};
if( diaFactoryRun(QT_TRANSLATE_NOOP("mp4muxer","MP4 Muxer"),4,tabs))
{
muxerConfig.muxerType=(MP4_MUXER_TYPE)fmt;
muxerConfig.useAlternateMp3Tag=alt;
muxerConfig.forceAspectRatio=force;
muxerConfig.aspectRatio=(MP4_MUXER_DAR)dar;
return true;
}
return false;
Expand Down

0 comments on commit 9056ceb

Please sign in to comment.